Skip to content

api: {branch} placeholder in gh api calls should not inherit from the local repo if $GH_REPO is set #7603

Description

@whi-tw

Describe the bug

The api command forces the use of cmdutil.OverrideBaseRepoFunc(), which manually sets the owner and repo to the specified github repository.

cli/pkg/cmd/api/api.go

Lines 181 to 183 in 31ffa6b

PreRun: func(c *cobra.Command, args []string) {
opts.BaseRepo = cmdutil.OverrideBaseRepoFunc(f, "")
},

If the user is 'in' an existing repository on the cli and calls the command with {branch} as a placeholder, it fills that placeholder with the name of the checked-out-branch from the cwd.

This feels like it should not be the behaviour, as the usage text suggests that all three valid placeholders ['owner', 'repo', 'branch'] will be obtained from $GH_REPO if it is set.

Steps to reproduce the behavior

  1. cd /path/to/some/git/repo/on/github
  2. git checkout -b wip/tw/poc
  3. GH_REPO=cli/cli gh api '/some/call/{owner}/{repo}/{branch}'

Expected vs actual behavior

Expected

Either:

  1. A request is made to the api at /some/call/cli/cli/null
  2. Some error is thrown as we have no good value for {branch} under these conditions

Observed

A request is made to the api at /some/call/cli/cli/wip/tw/poc

Activity

  1. samcoe commented on Jun 21, 2023

    @samcoe
    Contributor

    Agreed that behavior is incorrect, I think we should raise an error in this situation alerting the user that we could not determine an appropriate value for {branch}.

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    and removed on Jun 21, 2023
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 workinghelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions