Skip to content

GH_REPO compatibility with gh api #5061

@allanlei

Description

@allanlei

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

  1. Go to a directory that is not a git repo
  2. GH_REPO=my-org/my-repo gh api repos/{owner}/{repo}/releases
  3. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issuehelp 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