Files
John SmithandClaude Opus 5.5 e2da1ec685 fix(triage): never clear needs-human or mark such a PR ready
needs-human is a maintainer gate (e.g. a project held for using the V1 SDK); re-running triage on a push used to replace it with ready.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:43:31 -04:00

52 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
/**
* Label and comment on a pull request based on the catalog checks.
* Usage: node scripts/triage.js --pr <number> [--dry-run]
*
* Runs from the pull_request_target workflow with the BASE branch checked out: PR files are read
* through the API as data and never executed, so this is safe for fork PRs and gives feedback
* even before a maintainer approves the PR's own workflow runs.
*/
const { loadCatalog } = require('./utils/catalog');
const { analyzePullRequest, formatReport } = require('./utils/pr-checks');
const { REPO, pullChanges, setTriageLabels, addLabels, upsertComment } = require('./utils/repo');
const { rest } = require('./utils/github');
const MARKER = '<!-- awesome-opencode:triage -->';
async function main() {
const argv = process.argv.slice(2);
const number = Number(argv[argv.indexOf('--pr') + 1]);
const dryRun = argv.includes('--dry-run');
if (!number) throw new Error('usage: triage.js --pr <number>');
const { data: pull } = await rest(`/repos/${REPO}/pulls/${number}`);
if (!pull || !pull.head) throw new Error(`PR #${number} not found`);
const changes = await pullChanges(pull);
const { entries } = loadCatalog();
const result = await analyzePullRequest({ changes, baseEntries: entries });
const report = formatReport(result);
const current = pull.labels.map(l => l.name);
console.log(report);
console.log('labels:', result.labels.join(', ') || '(none)');
if (dryRun) return;
// needs-human is a maintainer gate: the bot may add it but never clears it or marks the PR ready
const labels = current.includes('needs-human')
? [...new Set([...result.labels.filter(l => l !== 'ready'), 'needs-human'])]
: result.labels;
await setTriageLabels(number, labels, current);
await addLabels(number, result.categories.map(c => `category: ${c}`).filter(l => !current.includes(l)));
if (result.dataChanged || result.errors.length) {
await upsertComment(number, MARKER, report);
}
}
main().catch(err => {
console.error(err);
process.exit(1);
});