Skip to content

Commit d91d39e

Browse files
os-zhuangclaude
andauthored
fix(ci): hand the cross-repo token to github-script instead of requiring @actions/github (#4578)
`require('@actions/github')` is not resolvable from a github-script `script:` block — the action bundles its dependencies, so it dies with MODULE_NOT_FOUND. Passing the token via `github-token:` makes the injected `github` client the cross-repo one, so no second client is needed at all. Observed in objectui, whose copy reached that line first. Supersedes the rename in #4573: that fixed the parse-time collision, which is what let the run get far enough to hit this. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4820f55 commit d91d39e

2 files changed

Lines changed: 32 additions & 7 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): hand the cross-repo token to github-script instead of requiring @actions/github
5+
6+
Release-nothing: touches `.github/workflows/cross-repo-issue-closer.yml` only.
7+
8+
`require('@actions/github')` is not resolvable from a github-script `script:`
9+
block — the action bundles its dependencies, so the call fails at runtime with
10+
`MODULE_NOT_FOUND`. The token is now handed to the action itself
11+
(`github-token:`), which makes the injected `github` client the cross-repo one,
12+
with `secrets.GITHUB_TOKEN` as the fallback so the report path can still
13+
comment on the pull request when no cross-repo credential is configured.
14+
15+
Observed in objectui, whose copy of this workflow reached that line first. Its
16+
run also confirmed the credential logging added alongside works, printing
17+
`CROSS_REPO_ISSUE_TOKEN: configured` before failing at the require.
18+
19+
This supersedes #4573, which renamed the second client without removing it —
20+
the rename fixed the identifier collision that aborted parsing, and only then
21+
did the run get far enough to hit the unresolvable module. Three failures in
22+
three consecutive runs, each one further down the same script: parse, resolve,
23+
then (expected next) the API calls themselves.

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ jobs:
4646
# to the repository running the workflow, which is the whole problem.
4747
CROSS_REPO_TOKEN: ${{ secrets.CROSS_REPO_ISSUE_TOKEN }}
4848
with:
49+
# Hand the cross-repo token to the action itself, so `github` IS the
50+
# cross-repo client. `require('@actions/github')` does NOT work here:
51+
# github-script bundles its dependencies and the module is not
52+
# resolvable from the script scope (`MODULE_NOT_FOUND`). Falling back
53+
# to GITHUB_TOKEN keeps the report path able to comment on this PR.
54+
github-token: ${{ secrets.CROSS_REPO_ISSUE_TOKEN || secrets.GITHUB_TOKEN }}
4955
script: |
5056
const body = context.payload.pull_request.body || '';
5157
const prUrl = context.payload.pull_request.html_url;
@@ -109,27 +115,23 @@ jobs:
109115
return;
110116
}
111117
112-
// A second client: `github` is bound to GITHUB_TOKEN, which has no
113-
// write access outside this repository.
114-
const crossRepo = require('@actions/github').getOctokit(token);
115-
116118
for (const [key, t] of targets) {
117119
try {
118-
const { data: issue } = await crossRepo.rest.issues.get({
120+
const { data: issue } = await github.rest.issues.get({
119121
owner: t.owner, repo: t.repo, issue_number: t.number,
120122
});
121123
if (issue.state === 'closed') {
122124
core.info(`${key} is already closed — skipping.`);
123125
continue;
124126
}
125-
await crossRepo.rest.issues.createComment({
127+
await github.rest.issues.createComment({
126128
owner: t.owner, repo: t.repo, issue_number: t.number,
127129
body:
128130
`已由 ${thisRepo} 的 ${prUrl} 修复并合并。\n\n` +
129131
`(跨仓库的关闭关键字不会自动生效,本条由 \`cross-repo-issue-closer\` 工作流代为收口。)\n\n` +
130132
`---\n_Generated by [Claude Code](https://claude.ai/code)_`,
131133
});
132-
await crossRepo.rest.issues.update({
134+
await github.rest.issues.update({
133135
owner: t.owner, repo: t.repo, issue_number: t.number,
134136
state: 'closed', state_reason: 'completed',
135137
});

0 commit comments

Comments
 (0)