cmd/api: Respect GH_REPO when substituting {owner}/{repo}#5063
Merged
cmd/api: Respect GH_REPO when substituting {owner}/{repo}#5063
GH_REPO when substituting {owner}/{repo}#5063Conversation
mislav
suggested changes
Jan 19, 2022
- This fixes issue 5061.
- Previously, a user could set `GH_REPO=TestOrg/repo` and run `gh api
repos/{owner}/{repo}/releases` expecting to see the releases from
`TestOrg/repo` but instead see releases from the current git repo
they're in.
- Or, worse, if the user ran the command from outside of a git repo,
they'd see a "not a git repo" error from git itself.
- This was different to `GH_REPO=TestOrg/repo gh release list` which
successfully lists `TestOrg/repo`'s releases.
----
Before:
```shell
$ cd repos/issyl0/not-a-git-repo
$ GH_REPO=issyl0/terraform-provider-improvmx gh api repos/{owner}/{repo}/releases
unable to expand placeholder in path: fatal: not a git repository (or any of the parent directories): .git
/opt/homebrew/bin/git: exit status 128
```
```shell
$ cd repos/issyl0/a-git-repo-with-no-releases
$ GH_REPO=issyl0/terraform-provider-improvmx gh api repos/{owner}/{repo}/releases
[]
```
After:
```shell
$ cd repos/issyl0/not-a-git-repo
$ GH_REPO=issyl0/terraform-provider-improvmx ../../cli/cli/bin/gh api repos/{owner}/{repo}/releases
[lots of JSON about GH_REPO's releases - success]
```
```shell
$ cd repos/issyl0/a-git-repo-with-no-releases
$ GH_REPO=issyl0/terraform-provider-improvmx ../../cli/cli/bin/gh api repos/{owner}/{repo}/releases
[lots of JSON about GH_REPO's releases - success]
```
af49eeb to
8c2695b
Compare
Contributor
Author
|
Thank you, @mislav, for the feedback - I pushed an improved version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GH_REPOcompatibility withgh api#5061.GH_REPO=TestOrg/repoand rungh api repos/{owner}/{repo}/releasesexpecting to see the releases fromTestOrg/repobut instead see releases from the current git repo they're in.GH_REPO=TestOrg/repo gh release listwhich successfully listsTestOrg/repo's releases.TODO and NOTES:
Test cases. Not sure how to do that tonight. For manual reproduction of the issue and testing my fix, I used a repo of mine that had releases, and one that did not (as you'll see from the before/after output below).Not necessary now we useOverrideBaseRepoFuncin the Cobra command definition.EnableRepoOverridefunction, but I couldn't work out how to use it with onlyGH_REPO. It seemed to relate heavily to the--repoflag, and telling users to specify--repoingh apiseemed weird.(Also worth noting I'm doing this right now entirely in a personal capacity for fun - it's an open source repo after all!)
Before:
$ cd repos/issyl0/a-git-repo-with-no-releases $ GH_REPO=issyl0/terraform-provider-improvmx gh api repos/{owner}/{repo}/releases []After: