PR checks: a read-only token gets a notice from the label job, not a failure (#7850) (#7851)

This commit is contained in:
raykholo
2026-10-29 01:00:15 +00:00
committed by GitHub
parent 0e01dc9bad
commit 4c6382c0a3
2 changed files with 22 additions and 4 deletions
+10 -4
View File
@@ -132,10 +132,16 @@ async function syncDefaultLabel({ github, context, core }) {
const { status } = parseDefaults(pull.body);
const has = hasLabel(pull, DEFAULT_LABEL);
const args = { ...context.repo, issue_number: pull.number };
if (status === 'yes' && !has) {
await github.rest.issues.addLabels({ ...args, labels: [DEFAULT_LABEL] });
} else if (status !== 'yes' && has) {
await github.rest.issues.removeLabel({ ...args, name: DEFAULT_LABEL });
try {
if (status === 'yes' && !has) {
await github.rest.issues.addLabels({ ...args, labels: [DEFAULT_LABEL] });
} else if (status !== 'yes' && has) {
await github.rest.issues.removeLabel({ ...args, name: DEFAULT_LABEL });
}
} catch (e) {
// A fork PR's token is read-only: say so instead of failing the check.
if (e.status !== 403) throw e;
core.notice(`Could not ${status === 'yes' ? 'add' : 'remove'} the ${DEFAULT_LABEL} label (read-only token); a maintainer sets it.`);
}
core.info(`Defaults line: ${status}`);
}
+12
View File
@@ -136,6 +136,18 @@ test('syncDefaultLabel adds and removes', async () => {
assert.deepEqual(f.calls, [['remove', 'changes-default']]);
});
test('syncDefaultLabel notes a read-only token instead of failing', async () => {
const yes = 'Changes a default: yes — a, old behaviour kept behind preference p';
const f = fakes(mk(1, 'a', yes));
const notes = [];
f.core.notice = (m) => notes.push(m);
f.github.rest.issues.addLabels = async () => { throw Object.assign(new Error('Resource not accessible by integration'), { status: 403 }); };
await pc.syncDefaultLabel(f);
assert.equal(notes.length, 1);
f.github.rest.issues.addLabels = async () => { throw Object.assign(new Error('server error'), { status: 500 }); };
await assert.rejects(pc.syncDefaultLabel(f));
});
test('checkDefaults only enforces from 2026-10-25', async () => {
const files = [{ filename: 'crates/a.rs' }];
const old = mk(20, 'alice', 'Fixes #5', { created_at: '2026-10-24T23:59:59Z' });