-
Couldn't load subscription status.
- Fork 7.3k
Check GH_REPO too in addition to --repo for disambiguation
#10539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Confirming changes with updated testsFollowing up on this PR, I'm on the verge of pushing up changes to tests to cover this and want to demonstrate that these tests fail on Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNewCmdListBaseRepoFuncs$ github.com/cli/cli/v2/pkg/cmd/secret/list
--- FAIL: TestNewCmdListBaseRepoFuncs (0.00s)
--- FAIL: TestNewCmdListBaseRepoFuncs/when_GH_REPO_env_var_is_provided,_the_factory_base_repo_func_is_used (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x1032fdec0]
goroutine 6 [running]:
testing.tRunner.func1.2({0x10358c3a0, 0x1039e9a50})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1734 +0x1ac
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1737 +0x334
panic({0x10358c3a0?, 0x1039e9a50?})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/runtime/panic.go:787 +0x124
github.com/cli/cli/v2/internal/ghrepo.IsSame({0x10362d828, 0x140001da7b0}, {0x0, 0x0})
/Users/andyfeller/Documents/workspace/cli/cli-10539/internal/ghrepo/repo.go:80 +0x40
github.com/cli/cli/v2/pkg/cmd/secret/list.TestNewCmdListBaseRepoFuncs.func2(0x140001ea380)
/Users/andyfeller/Documents/workspace/cli/cli-10539/pkg/cmd/secret/list/list_test.go:217 +0x3f8
testing.tRunner(0x140001ea380, 0x140001d37a0)
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1792 +0xe4
created by testing.(*T).Run in goroutine 4
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1851 +0x374
FAIL github.com/cli/cli/v2/pkg/cmd/secret/list 0.208s
FAIL
Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNewCmdDeleteBaseRepoFuncs$ github.com/cli/cli/v2/pkg/cmd/secret/delete
--- FAIL: TestNewCmdDeleteBaseRepoFuncs (0.00s)
--- FAIL: TestNewCmdDeleteBaseRepoFuncs/when_GH_REPO_env_var_is_provided,_the_factory_base_repo_func_is_used (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x104758000]
goroutine 37 [running]:
testing.tRunner.func1.2({0x104993fa0, 0x104dac9d0})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1734 +0x1ac
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1737 +0x334
panic({0x104993fa0?, 0x104dac9d0?})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/runtime/panic.go:787 +0x124
github.com/cli/cli/v2/internal/ghrepo.IsSame({0x104a30788, 0x140001fe6f0}, {0x0, 0x0})
/Users/andyfeller/Documents/workspace/cli/cli-10539/internal/ghrepo/repo.go:80 +0x40
github.com/cli/cli/v2/pkg/cmd/secret/delete.TestNewCmdDeleteBaseRepoFuncs.func2(0x14000129180)
/Users/andyfeller/Documents/workspace/cli/cli-10539/pkg/cmd/secret/delete/delete_test.go:238 +0x3f8
testing.tRunner(0x14000129180, 0x140001f3810)
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1792 +0xe4
created by testing.(*T).Run in goroutine 35
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1851 +0x374
FAIL github.com/cli/cli/v2/pkg/cmd/secret/delete 0.253s
FAIL
Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNewCmdSetBaseRepoFuncs$ github.com/cli/cli/v2/pkg/cmd/secret/set
--- FAIL: TestNewCmdSetBaseRepoFuncs (0.00s)
--- FAIL: TestNewCmdSetBaseRepoFuncs/when_GH_REPO_env_var_is_provided,_the_factory_base_repo_func_is_used (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x28 pc=0x100ac8a10]
goroutine 6 [running]:
testing.tRunner.func1.2({0x100d14aa0, 0x101138b40})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1734 +0x1ac
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1737 +0x334
panic({0x100d14aa0?, 0x101138b40?})
/opt/homebrew/Cellar/go/1.24.0/libexec/src/runtime/panic.go:787 +0x124
github.com/cli/cli/v2/internal/ghrepo.IsSame({0x100db2cb8, 0x140001d8810}, {0x0, 0x0})
/Users/andyfeller/Documents/workspace/cli/cli-10539/internal/ghrepo/repo.go:80 +0x40
github.com/cli/cli/v2/pkg/cmd/secret/set.TestNewCmdSetBaseRepoFuncs.func2(0x140001ea380)
/Users/andyfeller/Documents/workspace/cli/cli-10539/pkg/cmd/secret/set/set_test.go:337 +0x3f8
testing.tRunner(0x140001ea380, 0x140001e22a0)
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1792 +0xe4
created by testing.(*T).Run in goroutine 4
/opt/homebrew/Cellar/go/1.24.0/libexec/src/testing/testing.go:1851 +0x374
FAIL github.com/cli/cli/v2/pkg/cmd/secret/set 0.248s
FAIL |
Building on top of the work done in commands to account for GH_REPO environment variable, this commit expands existing tests around handling base repo functions to include new test scenarios. These tests fail in the same way as reported on the issue when run against `trunk` without the other branch's changes, demonstrating they will help avoid regression.
This commit builds on top of work previously done within acceptance tests around gh secret and remote disambiguation. The choice of expanding this existing test rather than creating a new test was in order to keep context together within a single acceptance test rather than splitting it over multiple.
Updated acceptance test resultsAlong with the updated tests, I've gone ahead and enhanced our acceptance tests to also cover this. Here is the result from running the updated acceptance tests against βΉtrunk*βΊ$ set -o pipefail && GH_ACCEPTANCE_SCRIPT=secret-require-remote-disambiguation.txtar GH_ACCEPTANCE_TOKEN=$(gh auth token --hostname github.com) GH_ACCEPTANCE_HOST=github.com GH_ACCEPTANCE_ORG=gh-acceptance-testing go test -tags acceptance -json -run ^TestSecrets$ github.com/cli/cli/v2/acceptance | tparse --all go test
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FAIL package: github.com/cli/cli/v2/acceptance β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
--- FAIL: TestSecrets (0.00s)
--- FAIL: TestSecrets/secret-require-remote-disambiguation (7.84s)
testscript.go:584: WORK=$WORK
PATH=/var/folders/y5/q89b76cj7ws55x3trcyllf_80000gn/T/testscript-main3772044479/bin:/opt/homebrew/Cellar/go/1.24.0/libexec/bin:/Users/andyfeller/.nvm/versions/node/v18.17.1/bin:/usr/local/opt/go/libexec/bin:/opt/homebrew/bin:/Users/andyfeller/go/bin:/Users/andyfeller/.dotnet:/Users/andyfeller/bin:/Users/andyfeller/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/share/dotnet:~/.dotnet/tools
GOTRACEBACK=system
HOME=$WORK
TMPDIR=$WORK/.tmp
devnull=/dev/null
/=/
:=:
$=$
exe=
SCRIPT_NAME=secret_require_remote_disambiguation
GH_CONFIG_DIR=$WORK
GH_HOST=github.com
ORG=gh-acceptance-testing
GH_TOKEN=gho_************************************
RANDOM_STRING=pTzaHEGHvk
# Set up env vars (0.000s)
> env REPO=${SCRIPT_NAME}-${RANDOM_STRING}
# Use gh as a credential helper (0.560s)
> exec gh auth setup-git
# Create a repository with a file so it has a default branch (0.928s)
> exec gh repo create ${ORG}/${REPO} --add-readme --private
[stdout]
https://github.com/gh-acceptance-testing/secret_require_remote_disambiguation-pTzaHEGHvk
# Defer repo cleanup (0.000s)
> defer gh repo delete --yes ${ORG}/${REPO}
# Create a fork (0.849s)
> exec gh repo fork ${ORG}/${REPO} --org ${ORG} --fork-name ${REPO}-fork
[stdout]
https://github.com/gh-acceptance-testing/secret_require_remote_disambiguation-pTzaHEGHvk-fork
# Defer fork cleanup (0.000s)
> defer gh repo delete --yes ${ORG}/${REPO}-fork
# Sleep to allow the fork to be created before cloning (2.001s)
> sleep 2
# Clone and move into the fork repo (1.514s)
> exec gh repo clone ${ORG}/${REPO}-fork
[stderr]
Cloning into 'secret_require_remote_disambiguation-pTzaHEGHvk-fork'...
From https://github.com/gh-acceptance-testing/secret_require_remote_disambiguation-pTzaHEGHvk
* [new branch] main -> upstream/main
> cd ${REPO}-fork
$WORK/secret_require_remote_disambiguation-pTzaHEGHvk-fork
# Secret list requires disambiguation (0.071s)
> ! exec gh secret list
[stderr]
multiple remotes detected. please specify which repo to use by providing the -R, --repo argument
[exit status 1]
> stderr 'multiple remotes detected. please specify which repo to use by providing the -R, --repo argument'
# Secret set requires disambiguation (0.051s)
> ! exec gh secret set 'TEST_SECRET_NAME' --body 'TEST_SECRET_VALUE'
[stderr]
multiple remotes detected. please specify which repo to use by providing the -R, --repo argument
[exit status 1]
> stderr 'multiple remotes detected. please specify which repo to use by providing the -R, --repo argument'
# Secret delete requires disambiguation (0.049s)
> ! exec gh secret delete 'TEST_SECRET_NAME'
[stderr]
multiple remotes detected. please specify which repo to use by providing the -R, --repo argument
[exit status 1]
> stderr 'multiple remotes detected. please specify which repo to use by providing the -R, --repo argument'
# Move out of the fork repo to test whether secret commands work without local repository context (0.000s)
> cd ..
$WORK
# Secret set using --repo flag does not require disambiguation (0.370s)
> exec gh secret set 'TEST_SECRET_NAME' --body 'TEST_SECRET_VALUE' --repo ${ORG}/${REPO}-fork
# Secret list using --repo flag does not require disambiguation (0.264s)
> exec gh secret list --repo ${ORG}/${REPO}-fork
[stdout]
TEST_SECRET_NAME 2025-03-04T19:27:33Z
> stdout 'TEST_SECRET_NAME'
# Secret delete using --repo flag does not require disambiguation (0.274s)
> exec gh secret delete 'TEST_SECRET_NAME' --repo ${ORG}/${REPO}-fork
# Setup GH_REPO for testing environment variable behavior (0.000s)
> env GH_REPO=${ORG}/${REPO}-fork
# Secret set using GH_REPO env var does not require disambiguation (0.866s)
> exec gh secret set 'TEST_SECRET_NAME2' --body 'TEST_SECRET_VALUE2'
[stderr]
failed to run git: fatal: not a git repository (or any of the parent directories): .git
[exit status 1]
FAIL: testdata/secret/secret-require-remote-disambiguation.txtar:55: unexpected command failure
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STATUS β ELAPSED β PACKAGE β COVER β PASS β FAIL β SKIP β
βββββββββββΌββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββΌβββββββΌβββββββΌββββββββ
β FAIL β 8.36s β github.com/cli/cli/v2/acceptance β -- β 0 β 2 β 0 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββAnd here we see the updated test passes against the branch changes: βΉwm/secret-env-var*βΊ$ set -o pipefail && GH_ACCEPTANCE_SCRIPT=secret-require-remote-disambiguation.txtar GH_ACCEPTANCE_TOKEN=$(gh auth token --hostname github.com) GH_ACCEPTANCE_HOST=github.com GH_ACCEPTANCE_ORG=gh-acceptance-testing go test -tags acceptance -json -run ^TestSecrets$ github.com/cli/cli/v2/acceptance | tparse --all go test
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STATUS β ELAPSED β TEST β PACKAGE β
βββββββββββΌββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββ
β PASS β 9.18 β TestSecrets/secret-require-remote-disambiguation β github.com/cli/cli/v2/acceptance β
β PASS β 0.00 β TestSecrets β github.com/cli/cli/v2/acceptance β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β STATUS β ELAPSED β PACKAGE β COVER β PASS β FAIL β SKIP β
βββββββββββΌββββββββββΌβββββββββββββββββββββββββββββββββββΌββββββββΌβββββββΌβββββββΌββββββββ
β PASS β 9.74s β github.com/cli/cli/v2/acceptance β -- β 2 β 0 β 0 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
The previous commit failed to update the 2nd set of tests to rely upon GH_REPO instead of --repo flag. These have been tested against `trunk` and fail because not being in a git directory when they should pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I've got a couple questions, but they're non-blocking so I'm giving this my β
acceptance/testdata/secret/secret-require-remote-disambiguation.txtar
Outdated
Show resolved
Hide resolved
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [cli/cli](https://github.com/cli/cli) | minor | `v2.67.0` -> `v2.68.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>cli/cli (cli/cli)</summary> ### [`v2.68.0`](https://github.com/cli/cli/releases/tag/v2.68.0): GitHub CLI 2.68.0 [Compare Source](cli/cli@v2.67.0...v2.68.0) #### What's Changed ##### β¨ Features - \[gh repo view] Improve error message for forked repo by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10334 - Add signer-digest, source-ref, and source-digest options for `gh attestation verify` by [@​malancas](https://github.com/malancas) in cli/cli#10308 - \[gh pr checkout] Add --no-tags option to git fetch commands in checkout by [@​latzskim](https://github.com/latzskim) in cli/cli#10479 - \[`gh issue/pr comment`] Add `--create-if-none` and prompts to create a comment if no comment already exists by [@​latzskim](https://github.com/latzskim) in cli/cli#10427 - \[gh cache delete --all] Add `--succeed-on-no-caches` flag to return exit code 0 by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10327 - \[gh release create] Fail when there are no new commits since the last release by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10398 - update default upstream when forking repo during MR creation by [@​daviddl9](https://github.com/daviddl9) in cli/cli#10458 ##### π Fixes - Refactor `GetLocalAttestations` and clean up custom registry transport by [@​malancas](https://github.com/malancas) in cli/cli#10382 - Check `GH_REPO` too in addition to `--repo` for disambiguation by [@​williammartin](https://github.com/williammartin) in cli/cli#10539 - (Fixes `gh secret` subcommands not working outside of a repository) - Fix unhandled panic in FindWorkflow and add tests by [@​jtmcg](https://github.com/jtmcg) in cli/cli#10521 - Fix checkout when URL arg is from fork and cwd is upstream by [@​williammartin](https://github.com/williammartin) in cli/cli#10512 - \[gh api] Escape package name (URL encoding) for packages endpoint by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10384 - Fix `remoteResolver` caching issue by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10456 - Fix gh project item-edit to allow --number 0 as a valid value by [@​aryanbhosale](https://github.com/aryanbhosale) in cli/cli#10417 - Add mutex to fix race in attestation test client by [@​codysoyland](https://github.com/codysoyland) in cli/cli#10439 - Base64 decode GPG passphrase in deployment workflow by [@​BagToad](https://github.com/BagToad) in cli/cli#10546 ##### π Docs & Chores - Deep Dive Document Release Process by [@​williammartin](https://github.com/williammartin) in cli/cli#10503 - Inconsistent format of examples in help text by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10508 - Inconsistent format of description of flags (starting with lowercase letter) by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10507 - Update Go version to 1.23 in CONTRIBUTING.md by [@​williammartin](https://github.com/williammartin) in cli/cli#10504 - Fix minor auth login help typo by [@​williammartin](https://github.com/williammartin) in cli/cli#10501 - docs: document how to revoke `gh` OAuth tokens in `auth logout`'s help by [@​BagToad](https://github.com/BagToad) in cli/cli#10490 - chore: update codespaces Go version by [@​BagToad](https://github.com/BagToad) in cli/cli#10491 - Allow injection of TUFMetadataDir in tests by [@​williammartin](https://github.com/williammartin) in cli/cli#10478 - refactor: use a more straightforward return value by [@​beforetech](https://github.com/beforetech) in cli/cli#10489 - Use subtests in attestation verification integration tests by [@​williammartin](https://github.com/williammartin) in cli/cli#10463 - Fix typo in README by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10445 - Update usage to lower-kebab-case by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10447 - Standardize URLs by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10429 - Remove trailing whitespace by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10430 #####Dependencies - Bump actions/attest-build-provenance from 2.2.0 to 2.2.2 by [@​dependabot](https://github.com/dependabot) in cli/cli#10518 - Bump github.com/go-jose/go-jose/v4 from 4.0.2 to 4.0.5 by [@​dependabot](https://github.com/dependabot) in cli/cli#10499 - Bump github.com/spf13/pflag from 1.0.5 to 1.0.6 by [@​dependabot](https://github.com/dependabot) in cli/cli#10338 </details> --- ### Configuration π **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). π¦ **Automerge**: Disabled by config. Please merge this manually once you are satisfied. β» **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. π **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xODYuMCIsInVwZGF0ZWRJblZlciI6IjM5LjE4Ni4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Description
Fixes #10525
Commit pulled from @iamazeem's fork, with attribution maintained.
This is an alternative to #10535 because that one requires a bit more thought and I'd like this to go out in a release.
Acceptance
Given my cwd is not a git repo
And I have
GH_REPOset to a repo I have permissions onWhen I run any of the
gh secretcommandsThen I am able to interact with secrets on that repo
Before:
After: