Skip to content

Commit 82f8daf

Browse files
committed
fix(ci): hand the cross-repo token to github-script instead of requiring @actions/github
`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.
1 parent 85a966f commit 82f8daf

2 files changed

Lines changed: 38 additions & 9 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: 15 additions & 9 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;
@@ -60,6 +66,12 @@ jobs:
6066
'gi',
6167
);
6268
69+
// Report credential state on EVERY run, before any early return.
70+
const token = process.env.CROSS_REPO_TOKEN;
71+
core.info(
72+
`CROSS_REPO_ISSUE_TOKEN: ${token ? 'configured' : 'ABSENT — cross-repo closes will be reported, not performed'}`,
73+
);
74+
6375
const targets = new Map();
6476
for (const [, owner, repo, number] of body.matchAll(pattern)) {
6577
const key = `${owner}/${repo}#${number}`;
@@ -75,8 +87,6 @@ jobs:
7587
}
7688
core.info(`Cross-repo targets: ${[...targets.keys()].join(', ')}`);
7789
78-
const token = process.env.CROSS_REPO_TOKEN;
79-
8090
if (!token) {
8191
// Degrade VISIBLY. Someone has to close these by hand, and this
8292
// comment is the only thing that will tell them so.
@@ -101,27 +111,23 @@ jobs:
101111
return;
102112
}
103113
104-
// A second client: `github` is bound to GITHUB_TOKEN, which has no
105-
// write access outside this repository.
106-
const octokit = require('@actions/github').getOctokit(token);
107-
108114
for (const [key, t] of targets) {
109115
try {
110-
const { data: issue } = await octokit.rest.issues.get({
116+
const { data: issue } = await github.rest.issues.get({
111117
owner: t.owner, repo: t.repo, issue_number: t.number,
112118
});
113119
if (issue.state === 'closed') {
114120
core.info(`${key} is already closed — skipping.`);
115121
continue;
116122
}
117-
await octokit.rest.issues.createComment({
123+
await github.rest.issues.createComment({
118124
owner: t.owner, repo: t.repo, issue_number: t.number,
119125
body:
120126
`已由 ${thisRepo} 的 ${prUrl} 修复并合并。\n\n` +
121127
`(跨仓库的关闭关键字不会自动生效,本条由 \`cross-repo-issue-closer\` 工作流代为收口。)\n\n` +
122128
`---\n_Generated by [Claude Code](https://claude.ai/code)_`,
123129
});
124-
await octokit.rest.issues.update({
130+
await github.rest.issues.update({
125131
owner: t.owner, repo: t.repo, issue_number: t.number,
126132
state: 'closed', state_reason: 'completed',
127133
});

0 commit comments

Comments
 (0)