X Tutup
Skip to content

Commit fac020e

Browse files
authored
Merge pull request cli#5063 from issyl0/repo-envvar-compatible-with-gh-api
cmd/api: Respect `GH_REPO` when substituting `{owner}/{repo}`
2 parents f02a73b + 8c2695b commit fac020e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkg/cmd/api/api.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
7272
The endpoint argument should either be a path of a GitHub API v3 endpoint, or
7373
"graphql" to access the GitHub API v4.
7474
75-
Placeholder values "{owner}", "{repo}", and "{branch}" in the endpoint argument will
76-
get replaced with values from the repository of the current directory. Note that in
77-
some shells, for example PowerShell, you may need to enclose any value that contains
78-
"{...}" in quotes to prevent the shell from applying special meaning to curly braces.
75+
Placeholder values "{owner}", "{repo}", and "{branch}" in the endpoint
76+
argument will get replaced with values from the repository of the current
77+
directory or the repository specified in the GH_REPO environment variable.
78+
Note that in some shells, for example PowerShell, you may need to enclose
79+
any value that contains "{...}" in quotes to prevent the shell from
80+
applying special meaning to curly braces.
7981
8082
The default HTTP request method is "GET" normally and "POST" if any parameters
8183
were added. Override the method with %[1]s--method%[1]s.
@@ -168,6 +170,9 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command
168170
`),
169171
},
170172
Args: cobra.ExactArgs(1),
173+
PreRun: func(c *cobra.Command, args []string) {
174+
opts.BaseRepo = cmdutil.OverrideBaseRepoFunc(f, "")
175+
},
171176
RunE: func(c *cobra.Command, args []string) error {
172177
opts.RequestPath = args[0]
173178
opts.RequestMethodPassed = c.Flags().Changed("method")

0 commit comments

Comments
 (0)
X Tutup