|
47 | 47 | const REF = /(?:https?:\/\/github\.com\/)?([\w.-]+)\/([\w.-]+)(?:\/pull\/|#)(\d+)/g; |
48 | 48 | const { owner, repo } = context.repo; |
49 | 49 | 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 | + } |
51 | 66 |
|
52 | 67 | function parseCompanions(body) { |
53 | 68 | body = body || ''; |
@@ -147,13 +162,13 @@ jobs: |
147 | 162 | const lines = []; |
148 | 163 | let warn = false; |
149 | 164 | for (const c of companions) { |
150 | | - if (!cross) { |
| 165 | + if (!crossToken) { |
151 | 166 | lines.push(`- ❓ \`${c.ref}\` — set the **CROSS_REPO_TOKEN** secret to verify merge status`); |
152 | 167 | warn = true; |
153 | 168 | continue; |
154 | 169 | } |
155 | 170 | 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); |
157 | 172 | const title = (cp.title || '').slice(0, 80); |
158 | 173 | if (cp.merged) { |
159 | 174 | const tierOk = cp.base.ref === base; |
|
0 commit comments