Repository navigation
gh variable get, gh variable delete, gh secret delete do not resolve Enterprise host based on repository #9274
Description
Activity
- changed the title
[-]gh variable delete does not working on enterprise[/-][+]gh variable get does not working on enterprise[/+]on Jul 1, 2024 - addedgh-variablerelating to the gh variable commandrelating to the gh variable command
on Aug 1, 2024 Thank you for your patience, @yukha-dw! This is definitely a bug in
gh variable getas it doesn't leverage the host associated with the repo.Reproducing
$ gh auth status github.com ✓ Logged in to github.com account andyfeller (keyring) - Active account: true - Git operations protocol: https - Token: gho_************************************ - Token scopes: 'codespace', 'gist', 'project', 'read:org', 'repo', 'workflow' ghe.io ✓ Logged in to ghe.io account andyfeller (keyring) - Active account: true - Git operations protocol: https - Token: gho_************************************ - Token scopes: 'gist', 'read:org', 'repo', 'workflow' $ GH_HOST=ghe.io gh repo clone services/gh-repo-export-test Cloning into 'gh-repo-export-test'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. $ cd gh-repo-export-test $ gh variable list no variables found $ gh variable set FOO_BAR --body FOO ✓ Created variable FOO_BAR for services/gh-repo-export-test $ gh variable list NAME VALUE UPDATED FOO_BAR FOO less than a minute ago $ gh repo view services/gh-repo-export-test No description provided gh-repo-export-test View this repository on GitHub: https://ghe.io/services/gh-repo-export-test $ gh variable get FOO_BAR variable FOO_BAR was not found $ GH_DEBUG=api gh variable get FOO_BAR [git remote -v] [git config --get-regexp ^remote\..*\.gh-resolved$] * Request at 2024-08-01 14:21:44.30068 -0400 EDT m=+0.080073793 * Request to https://api.github.com/repos/services/gh-repo-export-test/actions/variables/FOO_BAR > GET /repos/services/gh-repo-export-test/actions/variables/FOO_BAR HTTP/1.1 > Host: api.github.com > Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview > Authorization: token ████████████████████ > Content-Type: application/json; charset=utf-8 > Time-Zone: America/New_York > User-Agent: GitHub CLI 2.52.0 < HTTP/2.0 404 Not Found < Access-Control-Allow-Origin: * < Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset < Content-Security-Policy: default-src 'none' < Content-Type: application/json; charset=utf-8 < Date: Thu, 01 Aug 2024 18:21:44 GMT < Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin < Server: github.com < Strict-Transport-Security: max-age=31536000; includeSubdomains; preload < Vary: Accept-Encoding, Accept, X-Requested-With < X-Accepted-Oauth-Scopes: repo < X-Content-Type-Options: nosniff < X-Frame-Options: deny < X-Github-Api-Version-Selected: 2022-11-28 < X-Github-Media-Type: github.v3; param=merge-info-preview.nebula-preview; format=json < X-Github-Request-Id: EB3B:3D304A:783B42:E0BCDD:66ABD238 < X-Oauth-Client-Id: 178c6fc778ccc68e1d6a < X-Oauth-Scopes: codespace, gist, project, read:org, repo, workflow < X-Ratelimit-Limit: 15000 < X-Ratelimit-Remaining: 14990 < X-Ratelimit-Reset: 1722538980 < X-Ratelimit-Resource: core < X-Ratelimit-Used: 10 < X-Xss-Protection: 0 { "message": "Not Found", "documentation_url": "https://docs.github.com/rest/actions/variables#get-a-repository-variable", "status": "404" } * Request took 301.246958ms variable FOO_BAR was not found
Related source code
This is the
gh variable getcode:cli/pkg/cmd/variable/get/get.go
Lines 110 to 120 in 89cbcfe
host, _ := cfg.Authentication().DefaultHost() var variable shared.Variable if err = client.REST(host, "GET", path, nil, &variable); err != nil { var httpErr api.HTTPError if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound { return fmt.Errorf("variable %s was not found", opts.VariableName) } return fmt.Errorf("failed to get variable %s: %w", opts.VariableName, err) } Comparing it to
gh variable listthat shows the value, we see how repository and repository environment based variables use the host associated with the repo:cli/pkg/cmd/variable/list/list.go
Lines 195 to 202 in 89cbcfe
func getRepoVariables(client *http.Client, repo ghrepo.Interface) ([]shared.Variable, error) { return getVariables(client, repo.RepoHost(), fmt.Sprintf("repos/%s/actions/variables", ghrepo.FullName(repo))) } func getEnvVariables(client *http.Client, repo ghrepo.Interface, envName string) ([]shared.Variable, error) { path := fmt.Sprintf("repos/%s/environments/%s/variables", ghrepo.FullName(repo), envName) return getVariables(client, repo.RepoHost(), path) } Reacted by Yukha Dharmeswara- addedpriority-1Affects a large population and inhibits workAffects a large population and inhibits workand removedneeds-triageneeds to be reviewedneeds to be reviewed
on Aug 1, 2024 - added a commit that references this issue
on Aug 2, 2024 @yukha-dw : one thing that was a little unclear between the title of this issue and the issue body was the totally affected scope of commands. I've modified the original issue body to remove the redundant aliases and the non-existent
gh secret getcommand mentioned.That said, I was able to confirm this impacting
gh variable deleteandgh secret delete, so I'm expanding the PR to account for these, too.- changed the title
[-]gh variable get does not working on enterprise[/-][+]`gh variable get`, `gh variable delete`, `gh secret delete` do not resolve Enterprise host based on repository[/+]on Aug 2, 2024 @andyfeller great, thank you. I'm not good at communicating issue 😅
Describe the bug
Most of gh variable/secret command does not working on enterprise due to invalid hostname such as:
gh variable getgh variable deletegh secret deleteUPDATED: @andyfeller removed
removealiases from the above list being redundant todeleteas well asgh secret getbecause this command does not existContext:
Steps to reproduce the behavior
chdir to repository
Check FOO_BAR is exist
--repoarg--repoarg (https://, http://, without protocol)