Skip to content

Commit 6b17e81

Browse files
committed
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.
1 parent dab35e0 commit 6b17e81

2 files changed

Lines changed: 27 additions & 4 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,25 @@ jobs:
103103
104104
// A second client: `github` is bound to GITHUB_TOKEN, which has no
105105
// write access outside this repository.
106-
const octokit = require('@actions/github').getOctokit(token);
106+
const crossRepo = require('@actions/github').getOctokit(token);
107107
108108
for (const [key, t] of targets) {
109109
try {
110-
const { data: issue } = await octokit.rest.issues.get({
110+
const { data: issue } = await crossRepo.rest.issues.get({
111111
owner: t.owner, repo: t.repo, issue_number: t.number,
112112
});
113113
if (issue.state === 'closed') {
114114
core.info(`${key} is already closed — skipping.`);
115115
continue;
116116
}
117-
await octokit.rest.issues.createComment({
117+
await crossRepo.rest.issues.createComment({
118118
owner: t.owner, repo: t.repo, issue_number: t.number,
119119
body:
120120
`已由 ${thisRepo} 的 ${prUrl} 修复并合并。\n\n` +
121121
`(跨仓库的关闭关键字不会自动生效,本条由 \`cross-repo-issue-closer\` 工作流代为收口。)\n\n` +
122122
`---\n_Generated by [Claude Code](https://claude.ai/code)_`,
123123
});
124-
await octokit.rest.issues.update({
124+
await crossRepo.rest.issues.update({
125125
owner: t.owner, repo: t.repo, issue_number: t.number,
126126
state: 'closed', state_reason: 'completed',
127127
});

0 commit comments

Comments
 (0)