mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-03 02:25:55 +00:00
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user