Skip to content

gh pr edit https://... --add-label ... does not deduce --repo from the URL automatically #11055

Description

@user202729

Describe the bug

As in the title.

Affected version

gh version 2.73.0 (2025-05-19)

This previously worked in gh version 2.72.0 (2025-04-30)

Steps to reproduce the behavior

As in the title.

This affects SageMath's action: sagemath/sage#40193

Activity

  1. babakks commented on Jun 2, 2025

    @babakks
    Member

    Thanks for reporting this! 🙏 Checking the other issue you linked, I assume this is the command you're trying to run:

    gh pr edit https://github.com/sagemath/sage/pull/40192 --add-label "s: needs review"

    If so, could you please run it with the GH_DEBUG=api env var and share the output with me? I mean:

    GH_DEBUG=api gh pr edit https://github.com/sagemath/sage/pull/40192 --add-label "s: needs review"

    Please don't forget to remove unnecessary/private details.

  2. williammartin commented on Jun 2, 2025

    @williammartin
    Member

    I wonder if this might have the same underlying reason as #10071 (comment)

  3. user202729 commented on Jun 2, 2025

    @user202729
    Author

    I test on my fork

    [b]$ gh pr edit https://github.com/user202729/sage/pull/1 --add-label "test label"
    failed to run git: fatal: not a git repository (or any parent up to mount point /)
    Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
    
    [b]$ GH_DEBUG=api gh pr edit https://github.com/user202729/sage/pull/1 --add-label "test label"
    [git remote -v]
    failed to run git: fatal: not a git repository (or any parent up to mount point /)
    Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
    
    

    Only difference is [git remote -v].

  4. babakks commented on Jun 2, 2025

    @babakks
    Member

    @williammartin, Seems like we have a circular kind of dependency to BaseRepo:

    cli/pkg/cmd/pr/edit/edit.go

    Lines 207 to 222 in b4ab343

    findOptions := shared.FindOptions{
    Selector: opts.SelectorArg,
    Fields: []string{"id", "url", "title", "body", "baseRefName", "reviewRequests", "labels", "projectCards", "projectItems", "milestone"},
    Detector: opts.Detector,
    }
    httpClient, err := opts.HttpClient()
    if err != nil {
    return err
    }
    if opts.Detector == nil {
    baseRepo, err := opts.BaseRepo()
    if err != nil {
    return err
    }

    Here, we need a Detector (to make sure we're using the available API features), but to create that we need to know the host. Since, the current directory is not a git repo, call to BaseRepo fails, and so we return with that error.

    As a quick solution, we can check if the SelectorArg is a valid PR URL and grab the host name from that. However, I have to check and see in how many places we're doing this and would need to apply this fix.

    What do you think?

    UPDATE: Basically, this means we have to export the Finder's parseURL method and use it in editRun:

    func (f *finder) parseURL(prURL string) (ghrepo.Interface, int, error) {

  5. williammartin commented on Jun 10, 2025

    @williammartin
    Member

    Just released https://github.com/cli/cli/releases/tag/v2.74.1 which should resolve this. Unfortunately, it might take a little time to get into the runner images so in the meantime you might want to use the Installation Instructions to manually pull the release in (and I'd certainly appreciate if anyone did this to verify our fix as well).

    Extremely sorry for the inconvenience 🙏

  6. danakj commented on Jun 13, 2025

    @danakj

    so in the meantime you might want to use the Installation Instructions to manually pull the release in (and I'd certainly appreciate if anyone did this to verify our fix as well).

    So we tried this by doing apt-get update; apt-get install gh and the apt repo does not appear to have the fix either: gh is already the newest version (2.74.0)

  7. added a commit that references this issue on Jun 13, 2025
  8. williammartin commented on Jun 13, 2025

    @williammartin
    Member

    @danakj not sure about that, it is definitely in the repo.

    curl https://cli.github.com/packages/dists/stable/main/binary-amd64/Packages.gz --output - | gunzip
    Package: gh
    Version: 2.74.1
    Architecture: amd64
    Maintainer: GitHub
    Installed-Size: 36977
    Depends: git
    Homepage: https://github.com/cli/cli
    Priority: optional
    Section: 
    Filename: pool/main/g/gh/gh_2.74.1_amd64.deb <---------
    Size: 14194750
    SHA256: c3d909c338589589b32ee2357a76cea3b2c7bdfe1754ab8a62316fa846692935
    SHA1: 4dd7505ada041a5d2af49d5a9ac922e195c7ada1
    MD5sum: 375068bfa991fcd39bae560961d2c3d9
    Description: GitHub’s official command line tool.
    
  9. danakj commented on Jun 13, 2025

    @danakj

    Interesting, dunno. We solved this another way by adding --repo to the command line for now.

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

    bugSomething isn't workingneeds-triageneeds to be reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions