Skip to content

Commit bf91810

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 the call dies at runtime with MODULE_NOT_FOUND. Passing the token via `github-token:` makes the injected `github` client the cross-repo one, and no second client is needed. Found on the first run that got past parsing; the same run confirmed the credential logging works (`CROSS_REPO_ISSUE_TOKEN: configured`).
1 parent b200720 commit bf91810

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Found on this workflow's first run that got past parsing. The run also
16+
confirmed the credential logging works — `CROSS_REPO_ISSUE_TOKEN: configured`
17+
followed by `Cross-repo targets: objectstack-ai/objectstack#4475` — so the
18+
job now fails at the last step rather than the first.

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ jobs:
4848
# to the repository running the workflow, which is the whole problem.
4949
CROSS_REPO_TOKEN: ${{ secrets.CROSS_REPO_ISSUE_TOKEN }}
5050
with:
51+
# Hand the cross-repo token to the action itself, so `github` IS the
52+
# cross-repo client. `require('@actions/github')` does NOT work here:
53+
# github-script bundles its dependencies and the module is not
54+
# resolvable from the script scope (`MODULE_NOT_FOUND`, seen on this
55+
# workflow's first successful-parse run). Falling back to
56+
# GITHUB_TOKEN keeps the report path able to comment on this PR.
57+
github-token: ${{ secrets.CROSS_REPO_ISSUE_TOKEN || secrets.GITHUB_TOKEN }}
5158
script: |
5259
const body = context.payload.pull_request.body || '';
5360
const prUrl = context.payload.pull_request.html_url;
@@ -111,27 +118,23 @@ jobs:
111118
return;
112119
}
113120
114-
// A second client: `github` is bound to GITHUB_TOKEN, which has no
115-
// write access outside this repository.
116-
const crossRepo = require('@actions/github').getOctokit(token);
117-
118121
for (const [key, t] of targets) {
119122
try {
120-
const { data: issue } = await crossRepo.rest.issues.get({
123+
const { data: issue } = await github.rest.issues.get({
121124
owner: t.owner, repo: t.repo, issue_number: t.number,
122125
});
123126
if (issue.state === 'closed') {
124127
core.info(`${key} is already closed — skipping.`);
125128
continue;
126129
}
127-
await crossRepo.rest.issues.createComment({
130+
await github.rest.issues.createComment({
128131
owner: t.owner, repo: t.repo, issue_number: t.number,
129132
body:
130133
`已由 ${thisRepo} 的 ${prUrl} 修复并合并。\n\n` +
131134
`(跨仓库的关闭关键字不会自动生效,本条由 \`cross-repo-issue-closer\` 工作流代为收口。)\n\n` +
132135
`---\n_Generated by [Claude Code](https://claude.ai/code)_`,
133136
});
134-
await crossRepo.rest.issues.update({
137+
await github.rest.issues.update({
135138
owner: t.owner, repo: t.repo, issue_number: t.number,
136139
state: 'closed', state_reason: 'completed',
137140
});

0 commit comments

Comments
 (0)