|
| 1 | +const MAX_LISTED_FILES = 12; |
| 2 | + |
| 3 | +function classifyTouchedSurfaces(files) { |
| 4 | + const checks = [ |
| 5 | + [ |
| 6 | + 'Source behavior or orchestration changed; verify regressions, contracts, and dependency boundaries.', |
| 7 | + (file) => file.startsWith('src/'), |
| 8 | + ], |
| 9 | + [ |
| 10 | + 'Tests changed; confirm assertions still cover the touched behavior and edge cases.', |
| 11 | + (file) => file.startsWith('tests/'), |
| 12 | + ], |
| 13 | + [ |
| 14 | + 'Docs or README changed; verify commands, examples, and generated outputs stayed aligned.', |
| 15 | + (file) => file === 'README.md' || file.startsWith('docs/'), |
| 16 | + ], |
| 17 | + [ |
| 18 | + 'Workflow or local GitHub Action logic changed; scrutinize permissions, triggers, release flow, and CI side effects.', |
| 19 | + (file) => file.startsWith('.github/workflows/') || file.startsWith('.github/actions/'), |
| 20 | + ], |
| 21 | + [ |
| 22 | + 'Consumer workflow wrappers changed; verify they still mirror the reusable workflow contract safely.', |
| 23 | + (file) => file.startsWith('resources/github-actions/'), |
| 24 | + ], |
| 25 | + [ |
| 26 | + 'Packaged agent surfaces changed; verify prompts, sync behavior, and inherited guidance.', |
| 27 | + (file) => file.startsWith('.agents/skills/') || file.startsWith('.agents/agents/') || file === 'AGENTS.md', |
| 28 | + ], |
| 29 | + [ |
| 30 | + 'Changelog changed; verify notable behavior and automation changes are documented accurately.', |
| 31 | + (file) => file === 'CHANGELOG.md', |
| 32 | + ], |
| 33 | + [ |
| 34 | + 'Wiki output changed; confirm generated content updates are intentional and consistent with the source.', |
| 35 | + (file) => file.startsWith('.github/wiki'), |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'Packaged resources changed; verify consumer repositories inherit the right defaults and generated artifacts.', |
| 39 | + (file) => file.startsWith('resources/'), |
| 40 | + ], |
| 41 | + ]; |
| 42 | + |
| 43 | + return checks |
| 44 | + .filter(([, matcher]) => files.some(matcher)) |
| 45 | + .map(([message]) => message); |
| 46 | +} |
| 47 | + |
| 48 | +function renderComment({pull, files, focusAreas}) { |
| 49 | + const listedFiles = files.slice(0, MAX_LISTED_FILES); |
| 50 | + const remainingCount = Math.max(0, files.length - listedFiles.length); |
| 51 | + const touchedSurfaces = focusAreas.length > 0 |
| 52 | + ? focusAreas |
| 53 | + : ['No special review surface was inferred beyond the normal findings-first review contract.']; |
| 54 | + |
| 55 | + const lines = [ |
| 56 | + '## Rigorous review requested', |
| 57 | + '', |
| 58 | + 'This pull request is ready for the dedicated `review-guardian` pass powered by `$pull-request-review`.', |
| 59 | + '', |
| 60 | + `- PR: #${pull.number} — ${pull.title}`, |
| 61 | + `- Author: @${pull.user.login}`, |
| 62 | + `- Base: \`${pull.base.ref}\``, |
| 63 | + `- Head: \`${pull.head.ref}\` @ \`${pull.head.sha.slice(0, 7)}\``, |
| 64 | + '', |
| 65 | + '### Review focus', |
| 66 | + ...touchedSurfaces.map((item) => `- ${item}`), |
| 67 | + '', |
| 68 | + '### Sample changed files', |
| 69 | + ...listedFiles.map((file) => `- \`${file}\``), |
| 70 | + ]; |
| 71 | + |
| 72 | + if (remainingCount > 0) { |
| 73 | + lines.push(`- ...and ${remainingCount} more files.`); |
| 74 | + } |
| 75 | + |
| 76 | + lines.push( |
| 77 | + '', |
| 78 | + '### Suggested prompt', |
| 79 | + '```text', |
| 80 | + `Use $pull-request-review with the review-guardian agent to review PR #${pull.number} (${pull.html_url}).`, |
| 81 | + 'Lead with findings ordered by severity. Include repository file references whenever possible.', |
| 82 | + 'Prioritize bugs, regressions, missing tests, missing docs, generated-output drift, and workflow or CI impacts.', |
| 83 | + `Base: ${pull.base.ref}`, |
| 84 | + `Head: ${pull.head.ref} @ ${pull.head.sha.slice(0, 7)}`, |
| 85 | + '```', |
| 86 | + ); |
| 87 | + |
| 88 | + return lines.join('\n'); |
| 89 | +} |
| 90 | + |
| 91 | +function renderSummary({pull, focusAreas}) { |
| 92 | + const lines = [ |
| 93 | + '## Rigorous review requested', |
| 94 | + '', |
| 95 | + `- Pull request: [#${pull.number}](${pull.html_url})`, |
| 96 | + '- Agent: `review-guardian`', |
| 97 | + '- Skill: `$pull-request-review`', |
| 98 | + '', |
| 99 | + '### Findings-first expectations', |
| 100 | + '- Lead with bugs, regressions, missing tests, missing docs, generated-output drift, and workflow or CI risk.', |
| 101 | + '- Include repository file references whenever possible.', |
| 102 | + ]; |
| 103 | + |
| 104 | + if (focusAreas.length > 0) { |
| 105 | + lines.push('', '### Inferred high-signal surfaces', ...focusAreas.map((item) => `- ${item}`)); |
| 106 | + } |
| 107 | + |
| 108 | + return lines.join('\n'); |
| 109 | +} |
| 110 | + |
| 111 | +module.exports = async function run({github, context, core}) { |
| 112 | + const owner = context.repo.owner; |
| 113 | + const repo = context.repo.repo; |
| 114 | + const input = core.getInput('pull-request-number').trim(); |
| 115 | + const inferredNumber = String(context.payload.pull_request?.number || '').trim(); |
| 116 | + const pullRequestNumber = input || inferredNumber; |
| 117 | + |
| 118 | + if (pullRequestNumber === '') { |
| 119 | + core.setFailed('Unable to resolve a pull request number for the rigorous review workflow.'); |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + const pull_number = Number.parseInt(pullRequestNumber, 10); |
| 124 | + |
| 125 | + if (Number.isNaN(pull_number)) { |
| 126 | + core.setFailed(`Invalid pull request number: ${pullRequestNumber}`); |
| 127 | + return; |
| 128 | + } |
| 129 | + |
| 130 | + const {data: pull} = await github.rest.pulls.get({ |
| 131 | + owner, |
| 132 | + repo, |
| 133 | + pull_number, |
| 134 | + }); |
| 135 | + |
| 136 | + const files = await github.paginate(github.rest.pulls.listFiles, { |
| 137 | + owner, |
| 138 | + repo, |
| 139 | + pull_number, |
| 140 | + per_page: 100, |
| 141 | + }); |
| 142 | + |
| 143 | + const changedFiles = files.map((file) => file.filename); |
| 144 | + const focusAreas = classifyTouchedSurfaces(changedFiles); |
| 145 | + |
| 146 | + core.setOutput('pull-request-number', String(pull.number)); |
| 147 | + core.setOutput('comment', renderComment({pull, files: changedFiles, focusAreas})); |
| 148 | + core.setOutput('summary', renderSummary({pull, focusAreas})); |
| 149 | +}; |
0 commit comments