Skip to content

Commit dafb390

Browse files
os-zhuangclaude
andauthored
fix(ci): 跨仓库客户端改名——github-script 本来就声明了 octokit(修 #4553 引入的红检查) (#4573)
* fix(ci): rename the cross-repo client — github-script already declares `octokit` `actions/github-script` injects an `octokit` binding, so `const octokit = ...` aborts the run with a SyntaxError before any logic executes. Caught on #4553's own merge, the first time the workflow ever ran; until this lands every merged PR carries one red check. The pre-merge `node --check` missed it because the test wrapper declared only {github, context, core, require} — a wrapper that omits an injected identifier cannot see a collision with it. The wrapper now carries the full set. * ci: log CROSS_REPO_ISSUE_TOKEN presence on every run Without this the job returns early whenever a PR body carries no cross-repo reference — which is most PRs — so a repository that has the secret and one that does not produce byte-identical logs. Whether the credential is provisioned stays unanswerable until a cross-repo reference happens to show up, possibly days later. Presence only; the value is never read into the log. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 85a966f commit dafb390

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
---
3+
4+
fix(ci): rename the cross-repo client — `github-script` already declares `octokit`
5+
6+
Release-nothing: touches `.github/workflows/cross-repo-issue-closer.yml` only.
7+
8+
`actions/github-script` injects an `octokit` binding into the script scope, so
9+
the `const octokit = require('@actions/github').getOctokit(token)` added in
10+
#4553 aborted the run before a single line of logic executed:
11+
12+
SyntaxError: Identifier 'octokit' has already been declared
13+
14+
This surfaced on #4553's own merge — the first time the workflow ever ran, and
15+
the first time any of its runtime behaviour was exercised. Until this lands,
16+
every merged pull request in this repository carries one red check.
17+
18+
The pre-merge validation missed it for an instructive reason. The script was
19+
syntax-checked against a hand-written wrapper declaring `{github, context,
20+
core, require}` — and a wrapper that omits an injected identifier cannot
21+
possibly see a collision with it. The check reported clean because it was
22+
asking a narrower question than the runtime asks. The wrapper now carries the
23+
full injected set, and the previous spelling fails it.

.github/workflows/cross-repo-issue-closer.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ jobs:
6060
'gi',
6161
);
6262
63+
// Report credential state on EVERY run, before any early return.
64+
// Otherwise a repository with the secret and one without look
65+
// identical until a cross-repo reference happens to show up —
66+
// which can be days — and "is it configured?" stays unanswerable.
67+
// Presence only; the value is never read into the log.
68+
const token = process.env.CROSS_REPO_TOKEN;
69+
core.info(
70+
`CROSS_REPO_ISSUE_TOKEN: ${token ? 'configured' : 'ABSENT — cross-repo closes will be reported, not performed'}`,
71+
);
72+
6373
const targets = new Map();
6474
for (const [, owner, repo, number] of body.matchAll(pattern)) {
6575
const key = `${owner}/${repo}#${number}`;
@@ -75,8 +85,6 @@ jobs:
7585
}
7686
core.info(`Cross-repo targets: ${[...targets.keys()].join(', ')}`);
7787
78-
const token = process.env.CROSS_REPO_TOKEN;
79-
8088
if (!token) {
8189
// Degrade VISIBLY. Someone has to close these by hand, and this
8290
// comment is the only thing that will tell them so.
@@ -103,25 +111,25 @@ jobs:
103111
104112
// A second client: `github` is bound to GITHUB_TOKEN, which has no
105113
// write access outside this repository.
106-
const octokit = require('@actions/github').getOctokit(token);
114+
const crossRepo = require('@actions/github').getOctokit(token);
107115
108116
for (const [key, t] of targets) {
109117
try {
110-
const { data: issue } = await octokit.rest.issues.get({
118+
const { data: issue } = await crossRepo.rest.issues.get({
111119
owner: t.owner, repo: t.repo, issue_number: t.number,
112120
});
113121
if (issue.state === 'closed') {
114122
core.info(`${key} is already closed — skipping.`);
115123
continue;
116124
}
117-
await octokit.rest.issues.createComment({
125+
await crossRepo.rest.issues.createComment({
118126
owner: t.owner, repo: t.repo, issue_number: t.number,
119127
body:
120128
`已由 ${thisRepo} 的 ${prUrl} 修复并合并。\n\n` +
121129
`(跨仓库的关闭关键字不会自动生效,本条由 \`cross-repo-issue-closer\` 工作流代为收口。)\n\n` +
122130
`---\n_Generated by [Claude Code](https://claude.ai/code)_`,
123131
});
124-
await octokit.rest.issues.update({
132+
await crossRepo.rest.issues.update({
125133
owner: t.owner, repo: t.repo, issue_number: t.number,
126134
state: 'closed', state_reason: 'completed',
127135
});

0 commit comments

Comments
 (0)