Repository navigation
feat: scope the token to the clone it runs in when nothing else is named - #92
Merged
Merged
Conversation
githubauth token with no --installation, --owner, --repos or $GITHUB_APP_INSTALLATION_ID exited 2. Inside a clone it now reads the origin remote and, when that remote is on the target host, finds the installation of its owner and scopes the token to that one repository, the way actions/create-github-app-token defaults to the current repository. Outside a clone, or with a remote on another host, it exits 2 as before, so no call that worked changes. An --owner given empty, as from an unset script variable, does not count as nothing, since falling back would mint for a repository the script never named. ssh.github.com, GitHub's SSH over port 443, counts as github.com. GIT_DIR is honoured, as it is by the git push the token is usually for. The CLI tests now run from an empty directory with GIT_DIR, GIT_WORK_TREE and the caller's git config cleared: run from this clone, they reached api.github.com through its origin, and with GIT_DIR set they could have added a remote to it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
+ Coverage 97.86% 97.93% +0.06%
==========================================
Files 8 8
Lines 845 871 +26
==========================================
+ Hits 827 853 +26
Misses 18 18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Four PRs have landed since v1.11.0 with their release notes spread over their descriptions. An Unreleased section gathers them, so cutting v1.12.0 is a date and a tag. Three changes can affect existing code or scripts and are listed under Changed: --exec revoking the token, InstallationPermissions no longer being comparable now that it holds a map, and token values with a scope panicking under ==.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
githubauth tokenneeds to know which installation to mint for:--installation,--owner,--repos owner/repo, or$GITHUB_APP_INSTALLATION_ID. With none of them it exited 2. Run inside a clone, it now uses the repository the clone'soriginremote names, on the same host, and scopes the token to that repository alone, the wayactions/create-github-app-tokendefaults to the current repository.gh githubauth token --exec -- gh pr merge 7then works in any repository the App is installed on.What this does
acme/apion github.comacme's installation, scoped toapi--owner ""(an unset script variable)Changes
tokenreadsgit remote get-url originonly when no--installation,--owner,--reposor$GITHUB_APP_INSTALLATION_IDis given, and only uses it when the remote's host is the target host. It accepts https,ssh://,git@host:owner/repo, andssh.github.comon port 443.--base-url/--enterprise-urlchecks run before the installation checks, since the default needs the target host.GIT_DIR,GIT_WORK_TREEand the caller's git config cleared.Rationale
Only an error turns into a success, so no invocation that worked changes, and the token covers one repository, the narrowest scope.
GIT_DIRis honoured because thegit pushunder--exechonours it too, so both act on the same repository.An adversarial Codex review found three defects, all fixed:
--owner ""fell back to the clone,ssh.github.com:443was not recognised, and the tests could add a remote to the real repository whenGIT_DIRwas set. Writing the tests also caught that, run from this clone, the old suite reached api.github.com through its origin.Migration Notes
None. Tested against a real App: in a clone of
gopherguru/testwith no installation named, the token came back scoped totest; outside a clone the CLI exits 2.Also in this PR
An
Unreleasedsection in CHANGELOG.md collecting #87-#92, so cutting v1.12.0 is a date and a tag. A Codex review of it against the code added a third entry under Changed:InstallationPermissionsis no longer comparable now thatOtheris a map (#88).