Skip to content

Commit d085d74

Browse files
committed
fix(companion): read cross-repo PR via fetch (github-script can't require @actions/github)
Mirror of copilot: companion-pr-check failed with MODULE_NOT_FOUND. Read the other repo's PR with a plain REST fetch + the PAT in the header (PAT stays read-only; commenting/labeling uses GITHUB_TOKEN).
1 parent ef7b4d3 commit d085d74

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

.github/workflows/companion-pr-check.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,22 @@ jobs:
4747
const REF = /(?:https?:\/\/github\.com\/)?([\w.-]+)\/([\w.-]+)(?:\/pull\/|#)(\d+)/g;
4848
const { owner, repo } = context.repo;
4949
const crossToken = process.env.CROSS_REPO_TOKEN;
50-
const cross = crossToken ? require('@actions/github').getOctokit(crossToken) : null;
50+
// Read the OTHER repo's PR via a plain REST fetch with the PAT in the
51+
// header — keeps the PAT strictly READ-ONLY and avoids re-instantiating
52+
// Octokit inside github-script (which can't require('@actions/github')).
53+
// Commenting/labeling uses the default GITHUB_TOKEN via `github`.
54+
async function crossGetPR(c) {
55+
const res = await fetch(`https://api.github.com/repos/${c.owner}/${c.repo}/pulls/${c.number}`, {
56+
headers: {
57+
authorization: `Bearer ${crossToken}`,
58+
accept: 'application/vnd.github+json',
59+
'x-github-api-version': '2022-11-28',
60+
'user-agent': 'companion-pr-check',
61+
},
62+
});
63+
if (!res.ok) { const e = new Error(`HTTP ${res.status}`); e.status = res.status; throw e; }
64+
return res.json();
65+
}
5166
5267
function parseCompanions(body) {
5368
body = body || '';
@@ -147,13 +162,13 @@ jobs:
147162
const lines = [];
148163
let warn = false;
149164
for (const c of companions) {
150-
if (!cross) {
165+
if (!crossToken) {
151166
lines.push(`- ❓ \`${c.ref}\` — set the **CROSS_REPO_TOKEN** secret to verify merge status`);
152167
warn = true;
153168
continue;
154169
}
155170
try {
156-
const { data: cp } = await cross.rest.pulls.get({ owner: c.owner, repo: c.repo, pull_number: c.number });
171+
const cp = await crossGetPR(c);
157172
const title = (cp.title || '').slice(0, 80);
158173
if (cp.merged) {
159174
const tierOk = cp.base.ref === base;

0 commit comments

Comments
 (0)