Skip to content

Support creation of labels #1503

Description

@jayqi

Describe the feature or problem you’d like to solve

I would like the ability to create new labels.

I am using gh to script populating starter issues on new repositories, and currently it appears one can only assign labels that already exist. Since this is for a new repository, I'd like the ability to also script creating the labels in order to tag the new issues with them.

Proposed solution

New subcommand like gh label create [flags] that works similarly to how it works for issues and pull requests.

Activity

  1. mislav commented on Aug 11, 2020

    @mislav
    Contributor

    Thanks for the suggestion! You can do so right now with the api command:

    gh api --silent repos/:owner/:repo/labels -f name="help wanted" -f color="000000"

    Note that the color parameter is required.

  2. alterrebe commented on Oct 12, 2020

    @alterrebe

    The api command didn't work for me - I guess it does not work well with GitHub Enterprise. I worked around using plain curl, but it does not look as nice as it could with the GitHub CLI.

  3. mislav commented on Oct 15, 2020

    @mislav
    Contributor

    @alterrebe If you remove the --silent flag, do you get some response back? Also you may add the -i flag to see response headers. If this doesn't work on Enterprise (it absolutely should), please send us more debugging info so we can fix this 🙇

    Note that for Enterprise you need to set GH_HOST for now:

    GH_HOST=example.com gh api repos/:owner/:repo/labels ...
  4. vl4py commented on Nov 27, 2020

    @vl4py

    If you go for this feature, would it be possible to also do it from the interactive mode?

    Therefore, when creating pr instead of only allowing to search among the existing ones, you could create one straight forward?

  5. alterrebe commented on Nov 27, 2020

    @alterrebe

    Note that for Enterprise you need to set GH_HOST for now:

    GH_HOST=example.com gh api repos/:owner/:repo/labels ...

    This is the point I missed. Other commands work w/o it (I guess they autodetect the GH_HOST from the .git/config of the current repository, but gh api doesn't do it).

    Thank you, it resolved my problem.

  6. billygriffin commented on Mar 2, 2021

    @billygriffin
    Contributor

    I'm closing this as a duplicate of #446 - sorry for missing that the first time around, and please follow along there.

  7. mishabruml commented on Apr 5, 2022

    @mishabruml

    gh api repos/:owner/:repo/labels/my-label-name -X GET --silent || gh api repos/:owner/:repo/labels -f name="my-label-name" -f color="1D76DB" --silent

    This works OK for me for now (for an automated script) 😄

  8. mishabruml commented on Apr 5, 2022

    @mishabruml

    actually as of #5316 you can now do:

    gh api repos/:owner/:repo/labels/my-label-name -X GET --silent || gh label create my-label-name -c "1D76DB" -d "my label description"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIneeds-designAn engineering task needs design to proceed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions