gh-setup-git-identity 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.github/workflows/release.yml +31 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +22 -8
  4. package/docs/case-studies/issue-32/README.md +162 -0
  5. package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.0.0-no-toolchain.txt +47 -0
  6. package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.4.0-no-toolchain.txt +10 -0
  7. package/docs/case-studies/issue-32/raw-logs/ci-run-37733836425-release-failed.txt +252 -0
  8. package/docs/case-studies/issue-32/raw-logs/command-stream-exit-codes.txt +4 -0
  9. package/docs/case-studies/issue-32/raw-logs/dry-run-fixed-publish-fails.txt +91 -0
  10. package/docs/case-studies/issue-32/raw-logs/dry-run-main-publish-fails.txt +81 -0
  11. package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-after-fix.txt +195 -0
  12. package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-before-fix.txt +198 -0
  13. package/docs/case-studies/issue-32/raw-logs/npm-registry-facts.txt +28 -0
  14. package/docs/case-studies/issue-32/raw-logs/setup-npm-fixed-node20.txt +8 -0
  15. package/docs/case-studies/issue-32/raw-logs/setup-npm-main-node20.txt +12 -0
  16. package/docs/case-studies/issue-34/README.md +53 -0
  17. package/docs/case-studies/issue-34/raw-logs/email-endpoint-headers.txt +5 -0
  18. package/docs/case-studies/issue-34/raw-logs/gh-2.102.0-scope-hint.txt +13 -0
  19. package/docs/case-studies/issue-34/raw-logs/gh-2.105.0-scope-hint.txt +13 -0
  20. package/docs/case-studies/issue-34/raw-logs/issue-report.txt +46 -0
  21. package/docs/case-studies/issue-34/raw-logs/prepared-pr-changeset-check.txt +3 -0
  22. package/docs/case-studies/issue-34/raw-logs/regression-after.txt +19 -0
  23. package/docs/case-studies/issue-34/raw-logs/regression-before.txt +22 -0
  24. package/experiments/issue-32-command-stream-exit-codes.mjs +27 -0
  25. package/experiments/issue-32-pinned-helpers.mjs +27 -0
  26. package/experiments/issue-32-release-dry-run.sh +66 -0
  27. package/experiments/issue-34-gh-scope-hint.mjs +68 -0
  28. package/package.json +1 -1
  29. package/scripts/changeset-version.mjs +8 -4
  30. package/scripts/create-github-release.mjs +8 -5
  31. package/scripts/create-manual-changeset.mjs +4 -5
  32. package/scripts/format-github-release.mjs +5 -5
  33. package/scripts/format-release-notes.mjs +5 -5
  34. package/scripts/instant-version-bump.mjs +8 -5
  35. package/scripts/publish-to-npm.mjs +18 -12
  36. package/scripts/release-deps.mjs +21 -0
  37. package/scripts/report-release-failure.mjs +143 -0
  38. package/scripts/setup-npm.mjs +80 -27
  39. package/scripts/version-and-commit.mjs +22 -5
  40. package/src/cli.js +43 -61
  41. package/src/index.js +88 -13
  42. package/test/cli.test.js +257 -0
  43. package/test/index.test.js +0 -17
  44. package/test/release-scripts.test.js +232 -0
@@ -0,0 +1,198 @@
1
+ ### version-and-commit.mjs (HEAD)
2
+ Parsed configuration: {
3
+ mode: "changeset",
4
+ bumpType: "",
5
+ description: "(none)",
6
+ }
7
+ Checking for remote changes...
8
+ From $WORK/origin
9
+ * branch main -> FETCH_HEAD
10
+ 1dc7327cd5c28b38b15efcdcb3bb853ad16ebbac
11
+ 1dc7327cd5c28b38b15efcdcb3bb853ad16ebbac
12
+ Current version: 0.8.0
13
+ Running changeset version...
14
+
15
+ > gh-setup-git-identity@0.8.0 changeset:version
16
+ > bun scripts/changeset-version.mjs
17
+
18
+ Running changeset version...
19
+ 🦋 All files have been updated. Review them and commit at your leisure
20
+
21
+ Synchronizing package-lock.json...
22
+
23
+ up to date, audited 123 packages in 1s
24
+
25
+ 13 packages are looking for funding
26
+ run `npm fund` for details
27
+
28
+ 17 high severity vulnerabilities
29
+
30
+ To address issues that do not require attention, run:
31
+ npm audit fix
32
+
33
+ To address all issues (including breaking changes), run:
34
+ npm audit fix --force
35
+
36
+ Run `npm audit` for details.
37
+
38
+ Version bump complete with synchronized package-lock.json
39
+ New version: 0.8.1
40
+ D .changeset/fix-cli-version.md
41
+ M CHANGELOG.md
42
+ M package-lock.json
43
+ M package.json
44
+ Changes detected, committing...
45
+ [main ea7d639] 0.8.1
46
+ 4 files changed, 9 insertions(+), 8 deletions(-)
47
+ delete mode 100644 .changeset/fix-cli-version.md
48
+ To $WORK/origin.git
49
+ 1dc7327..ea7d639 main -> main
50
+ Version bump committed and pushed to main
51
+ exit=0
52
+ ### publish-to-npm.mjs (HEAD, changeset:publish = 'exit 1')
53
+ From $WORK/origin
54
+ * branch main -> FETCH_HEAD
55
+ Already up to date.
56
+ Current version to publish: 0.8.1
57
+ Checking if version 0.8.1 is already published...
58
+ npm error code E404
59
+ npm error 404 No match found for version 0.8.1
60
+ npm error 404
61
+ npm error 404 The requested resource 'gh-setup-git-identity@0.8.1' could not be found or you do not have permission to access it.
62
+ npm error 404
63
+ npm error 404 Note that you can also install from a
64
+ npm error 404 tarball, folder, http url, or git url.
65
+ npm error A complete log of this run can be found in: ~/.npm/_logs/2026-10-23T07_46_16_664Z-debug-0.log
66
+ Version 0.8.1 not found on npm, proceeding with publish...
67
+ Publish attempt 1 of 3...
68
+
69
+ > gh-setup-git-identity@0.8.1 changeset:publish
70
+ > eval "$PUBLISH_STUB"
71
+
72
+ Publish failed, waiting 0.01s before retry...
73
+ Publish attempt 2 of 3...
74
+
75
+ > gh-setup-git-identity@0.8.1 changeset:publish
76
+ > eval "$PUBLISH_STUB"
77
+
78
+ Publish failed, waiting 0.01s before retry...
79
+ Publish attempt 3 of 3...
80
+
81
+ > gh-setup-git-identity@0.8.1 changeset:publish
82
+ > eval "$PUBLISH_STUB"
83
+
84
+ Failed to publish after 3 attempts
85
+ exit=1
86
+ ### GITHUB_OUTPUT
87
+ new_version=0.8.1
88
+ version_committed=true
89
+ ### origin/main
90
+ ea7d639 0.8.1
91
+ 1dc7327 seed
92
+
93
+ ##### re-run of the same commit, changeset:publish succeeds
94
+ sh: 0: getcwd() failed: No such file or directory
95
+ fatal: this operation must be run in a work tree
96
+ warning: Clone succeeded, but checkout failed.
97
+ You can inspect what was checked out with 'git status'
98
+ and retry with 'git restore --source=HEAD :/'
99
+
100
+ ### version-and-commit.mjs (HEAD)
101
+ Parsed configuration: {
102
+ mode: "changeset",
103
+ bumpType: "",
104
+ description: "(none)",
105
+ }
106
+ Checking for remote changes...
107
+ From $WORK/origin
108
+ * branch main -> FETCH_HEAD
109
+ 1dc7327cd5c28b38b15efcdcb3bb853ad16ebbac
110
+ ea7d63965a6ea008dbff8bfab7b05752d8d6d5fb
111
+ Remote main has advanced (local: 1dc7327cd5c28b38b15efcdcb3bb853ad16ebbac, remote: ea7d63965a6ea008dbff8bfab7b05752d8d6d5fb)
112
+ This may indicate a previous attempt partially succeeded.
113
+ {
114
+ "name": "gh-setup-git-identity",
115
+ "version": "0.8.1",
116
+ "description": "A tool to setup git identity based on current gh user",
117
+ "type": "module",
118
+ "main": "src/index.js",
119
+ "bin": {
120
+ "gh-setup-git-identity": "src/cli.js"
121
+ },
122
+ "scripts": {
123
+ "test": "bun test",
124
+ "test:bun": "bun test",
125
+ "test:deno": "deno test --allow-all",
126
+ "lint": "bun build src/index.js --target=bun --format=esm --outfile=/dev/null && bun build src/cli.js --target=bun --format=esm --outfile=/dev/null",
127
+ "changeset": "changeset",
128
+ "changeset:version": "bun scripts/changeset-version.mjs",
129
+ "changeset:publish": "eval \"$PUBLISH_STUB\"",
130
+ "changeset:status": "changeset status --since=origin/main"
131
+ },
132
+ "keywords": [
133
+ "github",
134
+ "git",
135
+ "identity",
136
+ "config",
137
+ "cli",
138
+ "setup"
139
+ ],
140
+ "author": "Link Foundation",
141
+ "license": "Unlicense",
142
+ "repository": {
143
+ "type": "git",
144
+ "url": "https://github.com/link-foundation/gh-setup-git-identity.git"
145
+ },
146
+ "engines": {
147
+ "bun": ">=1.0.0"
148
+ },
149
+ "dependencies": {
150
+ "lino-arguments": "^0.2.1",
151
+ "log-lazy": "^1.0.4",
152
+ "yargs": "^17.7.2"
153
+ },
154
+ "devDependencies": {
155
+ "@changesets/cli": "^2.29.7",
156
+ "test-anywhere": "^0.7.0"
157
+ }
158
+ }
159
+ Remote version: 0.8.1
160
+ Rebasing on remote main to incorporate changes...
161
+
162
 
163
+ Current version: 0.8.1
164
+ Running changeset version...
165
+
166
+ > gh-setup-git-identity@0.8.1 changeset:version
167
+ > bun scripts/changeset-version.mjs
168
+
169
+ Running changeset version...
170
+ 🦋 warn No unreleased changesets found, exiting.
171
+
172
+ Synchronizing package-lock.json...
173
+
174
+ up to date, audited 123 packages in 1s
175
+
176
+ 13 packages are looking for funding
177
+ run `npm fund` for details
178
+
179
+ 17 high severity vulnerabilities
180
+
181
+ To address issues that do not require attention, run:
182
+ npm audit fix
183
+
184
+ To address all issues (including breaking changes), run:
185
+ npm audit fix --force
186
+
187
+ Run `npm audit` for details.
188
+
189
+ Version bump complete with synchronized package-lock.json
190
+ New version: 0.8.1
191
+ No changes to commit
192
+ exit=0
193
+ ### publish step skipped (no version_committed/already_released)
194
+ ### GITHUB_OUTPUT
195
+ new_version=0.8.1
196
+ version_committed=false
197
+ ### origin/main
198
+ ea7d639 0.8.1
199
+ 1dc7327 seed
@@ -0,0 +1,28 @@
1
+ {
2
+ execa: '10.1.0',
3
+ gifenc: '^1.0.3',
4
+ shelljs: '0.10.0',
5
+ 'node-pty': '^1.1.0',
6
+ 'cross-spawn': '7.0.6',
7
+ '@types/shelljs': '0.10.0',
8
+ '@resvg/resvg-js': '^2.6.2',
9
+ '@xterm/headless': '^6.0.0'
10
+ }
11
+ ---
12
+ { 'node-pty': '^1.1.0' }
13
+ ---
14
+ { node: '^22.22.2 || ^24.15.0 || >=26.0.0' }
15
+ { node: '^20.17.0 || >=22.9.0' }
16
+ ---
17
+ version = '0.8.0'
18
+ time.modified = '2026-01-16T11:31:09.598Z'
19
+ ---
20
+ # npm view command-stream time (2026-10-23)
21
+ "1.6.2": "2026-10-06T14:19:03.161Z",
22
+ "2.0.0": "2026-10-07T08:06:25.277Z",
23
+ "2.0.1": "2026-10-11T00:03:33.933Z",
24
+ "2.4.0": "2026-10-12T09:59:51.525Z"
25
+ # npm view command-stream@2.0.1 optionalDependencies
26
+ {
27
+ "node-pty": "^1.1.0"
28
+ }
@@ -0,0 +1,8 @@
1
+ Current npm version: 10.8.2
2
+ Installing npm@11...
3
+
4
+ removed 65 packages, and changed 112 packages in 8s
5
+
6
+ 15 packages are looking for funding
7
+ run `npm fund` for details
8
+ Updated npm version: 11.21.1
@@ -0,0 +1,12 @@
1
+ 10.8.2
2
+ Current npm version: 10.8.2
3
+ npm error code EBADENGINE
4
+ npm error engine Unsupported engine
5
+ npm error engine Not compatible with your version of node/npm: npm@12.2.1
6
+ npm error notsup Not compatible with your version of node/npm: npm@12.2.1
7
+ npm error notsup Required: {"node":"^22.22.2 || ^24.15.0 || >=26.0.0"}
8
+ npm error notsup Actual: {"npm":"10.8.2","node":"v20.20.2"}
9
+ npm error A complete log of this run can be found in: ~/.npm/_logs/2026-10-23T07_41_06_874Z-debug-0.log
10
+ 10.8.2
11
+ Updated npm version: 10.8.2
12
+ exit=0
@@ -0,0 +1,53 @@
1
+ # Issue #34 case study — a signed-in GitHub CLI account lacked email access
2
+
3
+ The application treated a successful `gh auth status` as proof that it could fetch the authenticated user's primary email. The reported credential passed that check, then GitHub rejected `GET /user/emails` and `gh` identified a missing OAuth scope. Signing in again with `user` restored the lookup. The fix starts the existing login flow once on the permission error and fetches the username and email again before writing Git identity. [Issue #34](https://github.com/link-foundation/gh-setup-git-identity/issues/34) · [Reported terminal transcript](raw-logs/issue-report.txt)
4
+
5
+ ## Timeline
6
+
7
+ | Order | Observed event | Significance |
8
+ | --- | --- | --- |
9
+ | 1 | The tool configured the GitHub CLI credential helper, then printed `Fetching GitHub user information...`. | The installed CLI followed its already-authenticated branch. Git credential helper setup configures Git transport and grants no API permissions. |
10
+ | 2 | Email lookup failed with HTTP 404 and the `"user" scope` hint. | The endpoint needed privileges that the credential did not provide. The program stopped before the two identity writes. |
11
+ | 3 | The reporter piped `y` to `gh auth login -h github.com -s repo,workflow,user,read:org,gist --git-protocol https --web` and approved the device flow. | The command requested the missing scope and activated the account authorized in the browser. The clipboard and keyring messages were incidental because login completed. |
12
+ | 4 | On the next invocation, the tool fetched the username and primary email and set both Git identity fields globally. | The resulting credential could read the identity. |
13
+ | 5 | Issue #34 was filed on 2026-11-22 at 16:05:51 UTC and edited at 16:07:08 UTC. | The issue contains the only incident transcript. The terminal commands have no individual timestamps. |
14
+ | 6 | A mock-subprocess regression reproduced the application failure. A separate replay with `gh` 2.102.0 and 2.105.0 reproduced an unusable refresh hint for environment tokens. | The two experiments established the application control flow and a separate upstream diagnostic problem. |
15
+
16
+ The report does not record the first credential's source, the previous account login, or the version of `gh`. The successful manual login establishes that a new authorization recovered the application. Whether the browser was signed into a different account, and whether `gh auth refresh` would have worked for the original credential, are unknown. The [archived transcript](raw-logs/issue-report.txt) removes the one-time code, email, account and container identifiers. The issue had no comments or linked sub-issues when investigated.
17
+
18
+ ## Root causes and affected entry points
19
+
20
+ 1. **The preflight checks authentication, while the failed operation checks email permission.** The CLI only initiated login on a nonzero `gh auth status`. The library treated any `gh api user/emails` failure as an ordinary setup error, so the CLI exited even when `gh` described a recoverable scope issue. GitHub documents `user:email` for classic token email reads. The parent `user` scope includes it. Fine-grained user tokens need the read permission for email addresses. The live API advertises `user, user:email` in its accepted OAuth scopes header. [REST email endpoint](https://docs.github.com/en/rest/users/emails#list-email-addresses-for-the-authenticated-user) · [OAuth scopes](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps) · [Captured response headers](raw-logs/email-endpoint-headers.txt)
21
+ 2. **A host or account can change across authentication.** The old CLI supplied `--hostname` for login and credential helper setup, while status and identity requests let `gh` choose their host. Restarting only the failed email call could also pair the old username with a newly authorized email. The CLI now passes its selected host through every setup operation and looks up both fields again after login. The recovery path waits for the original lookups to finish before replacing the active credential.
22
+ 3. **The upstream scope hint lacks credential-source context.** `gh api` derives the scope hint from the error status and OAuth response headers. The hint recommends refreshing stored credentials even when an environment variable supplies the active token. `gh auth refresh` explicitly rejects that source. The loopback test reproduces this secondary problem independently of the reporter's unknown credential source. The application now names the applicable variable and explains how to provide a usable token. [Scope suggestion code](https://github.com/cli/cli/blob/v2.105.0/api/client.go#L342-L411) · [Refresh command](https://github.com/cli/cli/blob/v2.105.0/pkg/cmd/auth/refresh/refresh.go#L191-L195) · [Upstream issue](https://github.com/cli/cli/issues/15129)
23
+ 4. **The opt-out flag was declared in the wrong form for the argument parser.** Yargs parses `--no-auto-login` as `auto-login=false`. Strict mode rejected the flag when the positive form was undefined, and the old test only scanned source text. The CLI now declares `auto-login` and tests the user-facing negated flag against both signed-out and insufficient-scope credentials.
24
+
25
+ The CLI recognizes the `user` and `user:email` hints and explicit token-access denials from the email endpoint. A bare HTTP 404, a missing primary email, and failures from the username lookup still surface as setup errors. Low-level lookup functions perform only reads. Library consumers of `setupGitIdentity` can enable the same one-attempt recovery by passing `authOptions`.
26
+
27
+ ## Options considered
28
+
29
+ | Approach | Fit for this incident |
30
+ | --- | --- |
31
+ | Reuse `gh auth login`, then rerun the identity lookup | Matches the successful workaround, delegates device authorization and secure storage to `gh`, and allows the user to choose or reauthorize an account. The implementation preserves login flags and adds a necessary OAuth scope for custom lists that omit email access. |
32
+ | Run `gh auth refresh -s user:email` | A manual option for the active stored account when preserving that account is desired. It cannot select a different account or update an environment-provided token. [GitHub CLI refresh manual](https://cli.github.com/manual/gh_auth_refresh) |
33
+ | Switch an already-authorized account with `gh auth switch` | Useful when the user already knows which stored account has the needed permission. The application cannot infer a preferred account from the permission error. [GitHub CLI switch manual](https://cli.github.com/manual/gh_auth_switch) |
34
+ | Use a user token supplied by the caller | Fits automation and the existing `--with-token` interface. Environment token precedence is controlled by `gh`. Recovery tells the caller how to remove or replace an environment credential that lacks email access. [GitHub CLI environment manual](https://cli.github.com/manual/gh_help_environment) |
35
+ | Replace `gh` API calls with Octokit and implement device authorization in JavaScript | Octokit can perform the REST request and device authorization. The application would also need to manage GitHub CLI's active account and credential store so later `gh` and Git commands use the same identity. [Octokit device authorization](https://github.com/octokit/auth-oauth-device.js) |
36
+ | Use the public profile email or synthesize a noreply address | An identity fallback could be useful for other tooling. This tool promises the account's primary email, which may be private and different from either value. Native Git identity setup has been proposed separately. [cli/cli#6096](https://github.com/cli/cli/issues/6096) |
37
+
38
+ ## Requirements and verification
39
+
40
+ | Requirement | Implementation and evidence |
41
+ | --- | --- |
42
+ | Automatically sign in again when an existing credential lacks the required scope | The CLI uses its existing `gh auth login` flow once, then refetches both identity fields and configures Git. [Regression before](raw-logs/regression-before.txt) · [Regression after](raw-logs/regression-after.txt) |
43
+ | Apply the behavior to affected setup paths | Subprocess tests cover the CLI's default and Enterprise hosts, global and local Git scope, custom settings, a replacement token from stdin, and opt-in library recovery. A first-time login, canceled login, and persistent errors all respect the one-login bound. [CLI tests](../../../test/cli.test.js) |
44
+ | Preserve callers' control of authentication | Tests exercise `--repair`, `--no-auto-login`, and `--dry-run`, an older `gh` without `--active`, healthy credentials, and non-permission errors. Environment token replacement guidance is also covered. [CLI tests](../../../test/cli.test.js) |
45
+ | Collect incident evidence, reconstruct events, establish root causes, and research existing solutions | The [incident transcript](raw-logs/issue-report.txt), [regression logs](raw-logs/) and primary references above preserve the available evidence. The existing `--verbose` mode now shows the scope error, invoked login, and retry host. |
46
+ | Report related upstream findings with reproduction, workaround and code proposal | The environment-token hint mismatch was reproduced against two real `gh` releases with a synthetic API response. The upstream report includes both a classic-token reproduction procedure and the loopback fixture, a credential-source-aware fix proposal, and the token replacement workaround. [cli/cli#15129](https://github.com/cli/cli/issues/15129) |
47
+ | Prepare the fix for release in one PR | The prepared PR's initial changeset check failed because the placeholder commit lacked a release entry. The PR adds a patch changeset and uses the existing check, lint, and Linux/macOS test jobs. [Initial CI failure excerpt](raw-logs/prepared-pr-changeset-check.txt) · [PR #35](https://github.com/link-foundation/gh-setup-git-identity/pull/35) |
48
+
49
+ Run the mocked regression suite with `bun test test/cli.test.js`. To reproduce the original failure locally, use those tests against the original implementation and select the test named `CLI signs in again when an authenticated account lacks the user scope`. The test supplies the same scope diagnostic as the incident and models an account switch so that success requires reading both fields again.
50
+
51
+ The [loopback experiment](../../../experiments/issue-34-gh-scope-hint.mjs) runs with `node experiments/issue-34-gh-scope-hint.mjs [path-to-gh]`. It uses an isolated configuration, a disposable TLS certificate, a synthetic token, and a local listener on port 443. [GitHub CLI 2.102.0 log](raw-logs/gh-2.102.0-scope-hint.txt) · [GitHub CLI 2.105.0 log](raw-logs/gh-2.105.0-scope-hint.txt)
52
+
53
+ Automated checks simulate login completion and cancellation. Browser approval in the original incident is documented in the reporter's transcript.
@@ -0,0 +1,5 @@
1
+ gh version 2.102.0 (2026-09-30)
2
+ https://github.com/cli/cli/releases/tag/v2.102.0
3
+ HTTP/2.0 200 OK
4
+ X-Accepted-Oauth-Scopes: user, user:email
5
+ X-Oauth-Scopes: gist, read:org, repo, user, workflow
@@ -0,0 +1,13 @@
1
+ $ gh --version
2
+ gh version 2.102.0 (2026-09-30)
3
+ https://github.com/cli/cli/releases/tag/v2.102.0
4
+ Exit status 0
5
+ $ gh api --hostname 127.0.0.1 user/emails
6
+ {"message":"Not Found"}
7
+ gh: Not Found (HTTP 404)
8
+ gh: This API operation needs the "user" scope. To request it, run: gh auth refresh -h 127.0.0.1 -s user
9
+ Exit status 1
10
+ $ gh auth refresh -h 127.0.0.1 -s user
11
+ The value of the GH_ENTERPRISE_TOKEN environment variable is being used for authentication.
12
+ To refresh credentials stored in GitHub CLI, first clear the value from the environment.
13
+ Exit status 1
@@ -0,0 +1,13 @@
1
+ $ gh --version
2
+ gh version 2.105.0 (2026-11-17)
3
+ https://github.com/cli/cli/releases/tag/v2.105.0
4
+ Exit status 0
5
+ $ gh api --hostname 127.0.0.1 user/emails
6
+ {"message":"Not Found"}
7
+ gh: Not Found (HTTP 404)
8
+ gh: This API operation needs the "user" scope. To request it, run: gh auth refresh -h 127.0.0.1 -s user
9
+ Exit status 1
10
+ $ gh auth refresh -h 127.0.0.1 -s user
11
+ The value of the GH_ENTERPRISE_TOKEN environment variable is being used for authentication.
12
+ To refresh credentials stored in GitHub CLI, first clear the value from the environment.
13
+ Exit status 1
@@ -0,0 +1,46 @@
1
+ Source: https://github.com/link-foundation/gh-setup-git-identity/issues/34
2
+ Title: `gh: This API operation needs the "user" scope` must trigger relogin sequence instead of failure
3
+ Created: 2026-11-22T16:05:51Z
4
+ Updated: 2026-11-22T16:07:08Z
5
+
6
+ Terminal transcript (device code, user, email and container redacted):
7
+ user@container:~$ gh-setup-git-identity
8
+ Git credential helper configured for GitHub CLI
9
+
10
+ Fetching GitHub user information...
11
+
12
+ Error: Failed to get GitHub email: gh: Not Found (HTTP 404)
13
+ gh: This API operation needs the "user" scope. To request it, run: gh auth refresh -h github.com -s user
14
+ user@container:~$ printf "y" | gh auth login -h github.com -s repo,workflow,user,read:org,gist --git-protocol https --web
15
+
16
+ ! Failed to copy one-time code to clipboard
17
+ No clipboard utilities available. Please install xsel, xclip, wl-clipboard or Termux:API add-on for termux-clipboard-get/set.
18
+ ! First copy your one-time code: [REDACTED]
19
+ Open this URL to continue in your web browser: https://github.com/login/device
20
+ ✓ Authentication complete.
21
+ - gh config set -h github.com git_protocol https
22
+ ✓ Configured git protocol
23
+ ! Authentication credentials saved in plain text
24
+ ✓ Logged in as example-user
25
+ user@container:~$ gh-setup-git-identity
26
+ Git credential helper configured for GitHub CLI
27
+
28
+ Fetching GitHub user information...
29
+ GitHub user: example-user
30
+ GitHub email: user@example.test
31
+
32
+ Configuring git (global)...
33
+ Git identity configured successfully!
34
+
35
+ Git configured:
36
+ user.name: example-user
37
+ user.email: user@example.test
38
+ Scope: global (--global)
39
+
40
+ Git identity setup complete!
41
+
42
+ You can verify your configuration with:
43
+ gh auth status
44
+ git config --global user.name
45
+ git config --global user.email
46
+ user@container:~$
@@ -0,0 +1,3 @@
1
+ Check for Changesets Check for changesets 2026-11-22T16:52:12.0919378Z ##[error]No changeset found. Please add a changeset by running 'npm run changeset' and commit the result.
2
+ Check for Changesets Check for changesets 2026-11-22T16:52:12.0931353Z Found 0 changeset file(s)
3
+ Check for Changesets Check for changesets 2026-11-22T16:52:12.0933550Z ##[error]Process completed with exit code 1.
@@ -0,0 +1,19 @@
1
+ bun test v1.4.4 (38afee6c8)
2
+
3
+ test/cli.test.js:
4
+ (pass) CLI --version matches the package version [87.68ms]
5
+ (pass) CLI --version uses its own package from an unrelated directory [88.49ms]
6
+ (pass) CLI signs in again when an authenticated account lacks the user scope [179.14ms]
7
+ (pass) CLI recovery uses the selected host, flags, scopes and local Git configuration [185.70ms]
8
+ (pass) CLI keeps the original authentication failure when recovery is disabled [438.08ms]
9
+ (pass) CLI attempts recovery once when login is canceled or permissions remain missing [506.62ms]
10
+ (pass) CLI leaves unrelated failures and a usable account on the existing path [462.53ms]
11
+ (pass) CLI keeps dry-run read-only and retains first-time login [575.40ms]
12
+ (pass) CLI still recovers with gh versions without the active-account status flag [157.95ms]
13
+ (pass) CLI explains how to replace an environment token lacking email permission [110.99ms]
14
+ (pass) CLI can read a replacement token from stdin during recovery [160.92ms]
15
+ (pass) Library callers opt in to interactive recovery through setupGitIdentity [202.02ms]
16
+
17
+ 12 pass
18
+ 0 fail
19
+ Ran 12 tests across 1 file. [3.19s]
@@ -0,0 +1,22 @@
1
+ bun test v1.4.4 (38afee6c8)
2
+
3
+ test/cli.test.js:
4
+ 731 | * Assert that two values are equal (using strict equality ===)
5
+ 732 | */
6
+ 733 | equal(actual, expected, message) {
7
+ 734 | if (actual !== expected) {
8
+ 735 | const defaultMessage = `Expected ${JSON.stringify(actual)} to equal ${JSON.stringify(expected)}`;
9
+ 736 | throw new Error(message || defaultMessage);
10
+ ^
11
+ error:
12
+ Error: Failed to get GitHub email: gh: Not Found (HTTP 404)
13
+ gh: This API operation needs the "user" scope. To request it, run: gh auth refresh -h github.com -s user
14
+
15
+ at equal (./node_modules/test-anywhere/src/index.js:736:48)
16
+ at <anonymous> (./test/cli.test.js:116:10)
17
+ (fail) CLI signs in again when an authenticated account lacks the user scope [227.20ms]
18
+
19
+ 0 pass
20
+ 8 filtered out
21
+ 1 fail
22
+ Ran 1 test across 1 file. [258.00ms]
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bun
2
+ // Shows whether `await $\`cmd\`` from the pinned command-stream rejects when
3
+ // the command exits non-zero, with and without shell.errexit(true).
4
+ // Usage: bun experiments/issue-32-command-stream-exit-codes.mjs
5
+ import { USE_M_URL, COMMAND_STREAM } from '../scripts/release-deps.mjs';
6
+
7
+ const { use } = eval(await (await fetch(USE_M_URL)).text());
8
+ const commandStream = await use(COMMAND_STREAM);
9
+ const { $, shell } = commandStream;
10
+
11
+ async function probe(label) {
12
+ try {
13
+ const result = await $`sh -c "exit 3"`;
14
+ console.log(`${label}: resolved, code=${result.code}`);
15
+ } catch (error) {
16
+ console.log(`${label}: rejected, code=${error.code}, ${error.message}`);
17
+ }
18
+ }
19
+
20
+ console.log('shell.errexit available:', typeof shell?.errexit);
21
+ await probe('default');
22
+ shell.errexit(true);
23
+ await probe('errexit(true)');
24
+ const captured = await $`sh -c "exit 4"`
25
+ .run({ capture: true })
26
+ .then((r) => `resolved code=${r.code}`, (e) => `rejected code=${e.code}`);
27
+ console.log('errexit(true) + .run({ capture: true }):', captured);
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bun
2
+ // Loads the release-script helpers at the versions pinned in
3
+ // scripts/release-deps.mjs and exercises the APIs the release scripts use.
4
+ // Usage: bun experiments/issue-32-pinned-helpers.mjs
5
+ import {
6
+ USE_M_URL,
7
+ COMMAND_STREAM,
8
+ LINO_ARGUMENTS,
9
+ } from '../scripts/release-deps.mjs';
10
+
11
+ console.log({ USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS });
12
+ const { use } = eval(await (await fetch(USE_M_URL)).text());
13
+
14
+ const { $ } = await use(COMMAND_STREAM);
15
+ const echo = await $`echo hello`.run({ capture: true });
16
+ console.log('command-stream $ ->', JSON.stringify(echo.stdout.trim()));
17
+
18
+ const { makeConfig } = await use(LINO_ARGUMENTS);
19
+ const config = makeConfig({
20
+ yargs: ({ yargs, getenv }) =>
21
+ yargs.option('release-version', {
22
+ type: 'string',
23
+ default: getenv('VERSION', ''),
24
+ }),
25
+ argv: ['node', 'x', '--release-version', '1.2.3'],
26
+ });
27
+ console.log('lino-arguments makeConfig ->', config.releaseVersion);
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bash
2
+ # Local dry run of the release path (version-and-commit.mjs, then
3
+ # publish-to-npm.mjs) against a throwaway bare git remote.
4
+ # `changeset:publish` is replaced by a stub, so nothing is published to npm.
5
+ #
6
+ # Usage: experiments/issue-32-release-dry-run.sh [ref] [publish-stub] [rerun]
7
+ # ref git ref whose scripts to run (default: HEAD)
8
+ # publish-stub shell command used as changeset:publish (default: "exit 1")
9
+ # rerun if set, then re-run both steps from the original commit
10
+ # with a succeeding stub, like `gh run rerun --failed`
11
+ set -u
12
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
13
+ REF="${1:-HEAD}"
14
+ export PUBLISH_STUB="${2:-exit 1}"
15
+ RERUN="${3:-}"
16
+ WORK="$(mktemp -d)"
17
+ trap 'rm -rf "$WORK"' EXIT
18
+
19
+ mkdir "$WORK/seed"
20
+ git -C "$REPO" archive "$REF" | tar x -C "$WORK/seed"
21
+ cd "$WORK/seed"
22
+ # Bring the pending changeset from main, as it was when the release failed.
23
+ cp "$REPO/.changeset/fix-cli-version.md" .changeset/ 2>/dev/null || true
24
+ node -e '
25
+ const fs = require("fs");
26
+ const p = JSON.parse(fs.readFileSync("package.json", "utf8"));
27
+ p.scripts["changeset:publish"] = "eval \"$PUBLISH_STUB\"";
28
+ fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");'
29
+ # Shorten the 10 s retry delay for the dry run.
30
+ sed -i 's/const RETRY_DELAY = 10000;/const RETRY_DELAY = 10;/' scripts/publish-to-npm.mjs
31
+ git init -q -b main && git add -A && git -c user.name=t -c user.email=t@t commit -q -m seed
32
+ SEED_SHA="$(git rev-parse HEAD)"
33
+ git clone -q --bare . "$WORK/origin.git"
34
+
35
+ release() {
36
+ rm -rf "$WORK/work"
37
+ git clone -q "$WORK/origin.git" "$WORK/work"
38
+ cd "$WORK/work"
39
+ # Like actions/checkout: the commit that triggered the run.
40
+ git checkout -q -B main "$SEED_SHA"
41
+ bun install --silent >/dev/null 2>&1
42
+ export GITHUB_OUTPUT="$WORK/output"
43
+ : > "$GITHUB_OUTPUT"
44
+ echo "### version-and-commit.mjs ($REF)"
45
+ bun scripts/version-and-commit.mjs --mode changeset
46
+ echo "exit=$?"
47
+ if grep -qE "version_committed=true|already_released=true" "$GITHUB_OUTPUT"; then
48
+ echo "### publish-to-npm.mjs ($REF, changeset:publish = '$PUBLISH_STUB')"
49
+ bun scripts/publish-to-npm.mjs --should-pull
50
+ echo "exit=$?"
51
+ else
52
+ echo "### publish step skipped (no version_committed/already_released)"
53
+ fi
54
+ echo "### GITHUB_OUTPUT"
55
+ cat "$GITHUB_OUTPUT"
56
+ echo "### origin/main"
57
+ git -C "$WORK/origin.git" log --oneline -2 main
58
+ }
59
+
60
+ release
61
+ if [ -n "$RERUN" ]; then
62
+ echo
63
+ echo "##### re-run of the same commit, changeset:publish succeeds"
64
+ export PUBLISH_STUB="echo stub-published"
65
+ release
66
+ fi
@@ -0,0 +1,68 @@
1
+ // Replays the upstream scope hint with a real gh binary, an isolated config, and a loopback API.
2
+ // Run with Node.js and OpenSSL. The unprivileged process must be able to bind 127.0.0.1:443.
3
+ import { execFile, execFileSync } from 'node:child_process';
4
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
5
+ import { createServer } from 'node:https';
6
+ import { tmpdir } from 'node:os';
7
+ import { join } from 'node:path';
8
+
9
+ const gh = process.argv[2] || 'gh';
10
+ const host = '127.0.0.1';
11
+ const token = 'fixture-token';
12
+ const configDir = mkdtempSync(join(tmpdir(), 'gh-scope-hint-'));
13
+ const key = join(configDir, 'key.pem');
14
+ const cert = join(configDir, 'cert.pem');
15
+ let server;
16
+
17
+ try {
18
+ execFileSync('openssl', ['req', '-x509', '-newkey', 'rsa:2048', '-nodes', '-days', '1',
19
+ '-subj', `/CN=${host}`, '-addext', `subjectAltName=IP:${host}`, '-keyout', key, '-out', cert], { stdio: 'pipe' });
20
+
21
+ server = createServer({ key: readFileSync(key), cert: readFileSync(cert) }, (request, response) => {
22
+ if (request.url !== '/api/v3/user/emails' || request.headers.authorization !== `token ${token}`) {
23
+ response.writeHead(500).end();
24
+ return;
25
+ }
26
+ response.writeHead(404, {
27
+ 'Content-Type': 'application/json',
28
+ 'X-Accepted-OAuth-Scopes': 'user, user:email',
29
+ 'X-OAuth-Scopes': 'repo',
30
+ }).end(JSON.stringify({ message: 'Not Found' }));
31
+ });
32
+ await new Promise((resolve, reject) => {
33
+ server.once('error', reject);
34
+ server.listen(443, host, resolve);
35
+ });
36
+
37
+ const env = {
38
+ PATH: process.env.PATH,
39
+ GH_CONFIG_DIR: configDir,
40
+ GH_ENTERPRISE_TOKEN: token,
41
+ GH_HOST: host,
42
+ NO_PROXY: host,
43
+ SSL_CERT_FILE: cert,
44
+ };
45
+ const run = (args) => new Promise((resolve, reject) => {
46
+ execFile(gh, args, { env, timeout: 10000 }, (error, stdout, stderr) => {
47
+ if (error && typeof error.code !== 'number') {
48
+ reject(error);
49
+ return;
50
+ }
51
+ const status = error?.code ?? 0;
52
+ const output = [stdout.trim(), stderr.trim()].filter(Boolean).join('\n');
53
+ console.log(`$ gh ${args.join(' ')}\n${output}\nExit status ${status}`);
54
+ resolve({ status, stderr });
55
+ });
56
+ });
57
+
58
+ await run(['--version']);
59
+ const api = await run(['api', '--hostname', host, 'user/emails']);
60
+ const refresh = await run(['auth', 'refresh', '-h', host, '-s', 'user']);
61
+ if (api.status !== 1 || !api.stderr.includes(`gh auth refresh -h ${host} -s user`) ||
62
+ refresh.status !== 1 || !refresh.stderr.includes('GH_ENTERPRISE_TOKEN environment variable')) {
63
+ throw new Error('The scope hint or refresh result differed from the reported behavior.');
64
+ }
65
+ } finally {
66
+ if (server?.listening) await new Promise((resolve) => server.close(resolve));
67
+ rmSync(configDir, { recursive: true, force: true });
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gh-setup-git-identity",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "A tool to setup git identity based on current gh user",
5
5
  "type": "module",
6
6
  "main": "src/index.js",