-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Describe the bug
GH_REPO has no effect when using it with gh api repos/{owner}/{repo}/... but using the corresponding CLI version of the API call, it works (gh api repos/{owner}/{repo}/releases vs gh release list).
GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands that otherwise operate on a local repository.
The that otherwise operate on a local repository is slightly confusing to me so I am not sure if this is by design, but for consistency sake, it would beneficial to have the same behaviour.
The use case I have is for Github Actions where I would like to run a job without actions/checkout and needing to run multiple gh commands
steps:
- env:
GH_REPO: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
run:
tagName=gh release list
# This does not work
gh api repos/{owner}/{repo}/deployments -f tagName
# Workaround
gh api repos/$GH_REPO/deployments -f tagName
$ gh --version
gh version 2.4.0 (2021-12-21)
https://github.com/cli/cli/releases/tag/v2.4.0
Steps to reproduce the behavior
- Go to a directory that is not a git repo
GH_REPO=my-org/my-repo gh api repos/{owner}/{repo}/releases- See error
Expected vs actual behavior
Expected
The API call is successful and lists the results from GH_REPO
v2022.01.18+5d2c44e Latest (v2022.01.18+5d2c44e) about 5 hours ago
v2022.01.18+a7eee2a (v2022.01.18+a7eee2a) about 5 hours ago
v2022.01.18+d5f9927 (v2022.01.18+d5f9927) about 7 hours ago
Actual
unable to expand placeholder in path: fatal: not a git repository (or any of the parent directories): .git
/usr/bin/git: exit status 128
Logs
This works
$ cd directory-that-is-not-a-repo
$ GH_REPO=my-org/my-repo gh release list
v2022.01.18+5d2c44e Latest (v2022.01.18+5d2c44e) about 5 hours ago
v2022.01.18+a7eee2a (v2022.01.18+a7eee2a) about 5 hours ago
v2022.01.18+d5f9927 (v2022.01.18+d5f9927) about 7 hours ago
This does not
$ cd directory-that-is-not-a-repo
$ GH_REPO=my-org/my-repo gh api repos/{owner}/{repo}/releases
unable to expand placeholder in path: fatal: not a git repository (or any of the parent directories): .git
/usr/bin/git: exit status 128
This works where the current directory is a git repo but is not equal to GH_REPO. It will correctly list GH_REPO=my-org/my-repo's releases
$ cd directory-that-is-not-my-org-abc
$ GH_REPO=my-org/my-repo gh release list
v2022.01.18+5d2c44e Latest (v2022.01.18+5d2c44e) about 5 hours ago
v2022.01.18+a7eee2a (v2022.01.18+a7eee2a) about 5 hours ago
v2022.01.18+d5f9927 (v2022.01.18+d5f9927) about 7 hours ago
This does not work correctly as it will list the releases of my-org/abc, not GH_REPO
$ cd directory-that-is-not-my-org-abc
$ GH_REPO=my-org/my-repo gh api repos/{owner}/{repo}/releases
release-a Latest (release-a) about 5 hours ago
release-b (release-b) about 5 hours ago
release-c (release-c) about 7 hours ago