diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 983e294b0..ce49cdddb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,3 +1,5 @@ +> **Before you open this PR:** read the full diff yourself and test the change. Do not submit AI output that you have not reviewed. See [Review your work before opening a PR](https://github.com/navidrome/navidrome/blob/master/CONTRIBUTING.md#review-your-work-before-opening-a-pr). + ### Description @@ -18,12 +20,12 @@ ### Checklist Please review and check all that apply. Leave unverified items unchecked and explain them under How to Test. - - [ ] My code follows the project’s coding style - [ ] I have tested the changes locally - [ ] I have added or updated documentation as needed - [ ] I have added tests that prove my fix/feature works (or explain why not) - [ ] All existing and new tests pass + - [ ] I personally read and reviewed the entire diff and relevant code before opening this PR, and have done the same for every subsequent update, if any. - [ ] For code changes, I have the development knowledge to understand, test, and maintain the implementation, assess its security and performance implications, and answer review questions. diff --git a/.github/workflows/review-attestation-label.yml b/.github/workflows/review-attestation-label.yml new file mode 100644 index 000000000..dc316bc06 --- /dev/null +++ b/.github/workflows/review-attestation-label.yml @@ -0,0 +1,79 @@ +name: Review attestation label +on: + pull_request_target: + types: [opened, edited, reopened] + +permissions: + contents: read + +concurrency: + group: review-attestation-${{ github.event.pull_request.number }} + +jobs: + sync-label: + name: Sync review-attestation-missing label + if: ${{ !contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) }} + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + # Reads only PR metadata; never check out PR code under pull_request_target. + - uses: actions/github-script@v9 + with: + script: | + const label = 'review-attestation-missing'; + const commentMarker = ''; + const nonAgentBots = ['dependabot[bot]', 'github-actions[bot]']; + const rulesUrl = 'https://github.com/navidrome/navidrome/blob/master/CONTRIBUTING.md#review-your-work-before-opening-a-pr'; + const templateUrl = 'https://github.com/navidrome/navidrome/blob/master/.github/pull_request_template.md?plain=1'; + const issue = { ...context.repo, issue_number: context.payload.pull_request.number }; + // Re-read the PR so a queued run never acts on a stale event payload. + const { data: pr } = await github.rest.pulls.get({ ...context.repo, pull_number: issue.issue_number }); + if (nonAgentBots.includes(pr.user.login)) return; + + const body = (pr.body ?? '') + .replace(//g, '') + .replace(/^[ \t]*(```|~~~)[\s\S]*?^[ \t]*\1/gm, ''); + let reason = ''; + if (pr.user.type === 'Bot') { + reason = 'A coding agent account opened this PR, so no person has confirmed a review yet.'; + } else if (!/^###\s+Checklist\s*$/m.test(body)) { + reason = `The PR description does not use the [PR template](${templateUrl}), so the review confirmation is missing.`; + } else if (!/^[ \t]*-\s*\[[xX]\]\s*I personally read and reviewed the entire diff/m.test(body)) { + reason = 'The "I personally read and reviewed the entire diff..." box is not checked.'; + } + + const labeled = pr.labels.some((l) => l.name === label); + core.info(reason ? `Missing attestation: ${reason}` : 'Attestation present'); + if (!reason) { + if (labeled) { + try { + await github.rest.issues.removeLabel({ ...issue, name: label }); + } catch (e) { + if (e.status !== 404) throw e; + } + } + return; + } + + if (!labeled) { + await github.rest.issues.addLabels({ ...issue, labels: [label] }); + } + const comments = await github.paginate(github.rest.issues.listComments, { ...issue, per_page: 100 }); + if (comments.some((c) => c.user?.login === 'github-actions[bot]' && c.body?.includes(commentMarker))) return; + await github.rest.issues.createComment({ + ...issue, + body: [ + commentMarker, + 'Thanks for the PR. Before it can be reviewed, please follow the [review rule](' + rulesUrl + '):', + '', + '- Read and review the entire diff and the relevant code yourself.', + '- Test the affected behavior yourself.', + '', + "An AI agent's summary or review does not count. If an agent wrote this code, review it as if someone else wrote it.", + '', + `**Why you see this:** ${reason}`, + '', + 'When you are done, edit the PR description and check the "I personally read and reviewed the entire diff..." box. The `' + label + '` label then goes away. A PR that looks like unreviewed AI output may be closed without review.', + ].join('\n'), + }); diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f8381ce5..bd00d40d7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ For large or cross-cutting changes, agree on the design and a sequence of small, ## Review your work before opening a PR -Before opening any pull request, including a draft, you must personally read and review the entire diff and the relevant surrounding code, understand the implementation, and verify the affected behavior. This applies when an AI agent writes the code or creates the PR for you. An agent's summary or review does not satisfy this requirement. Personally review each subsequent update and verify its effects before pushing it or asking an agent to push it. +Before opening any pull request, including a draft, you must personally read and review the entire diff and the relevant surrounding code, understand the implementation, and verify the affected behavior. This applies when an AI agent writes the code or creates the PR for you. An agent's summary or review does not satisfy this requirement. Personally review each subsequent update and verify its effects before pushing it or asking an agent to push it. A PR that looks like unreviewed AI output may be closed without review. Check the assumptions behind the change. Explain the implementation and important tradeoffs in your own words. For code changes, personally test the affected functionality, add regression tests where practical, and report the commands run and results actually observed. Identify failures, untested cases, and limitations. If an automated test is impractical, explain why and provide manual verification steps. @@ -38,6 +38,8 @@ AI-assisted work must meet the personal full-diff review and functional testing Declare whether AI was used to generate or modify submitted code or tests, draft substantive PR text, or create the PR. A simple Yes or No in the PR description is enough. Tool names, prompts, and transcripts are not required. +An AI agent must never check the personal review or development knowledge boxes in the PR template for you. A PR from an outside contributor gets the `review-attestation-missing` label and a reminder comment when the personal review box is unchecked, the PR template is missing, or a coding agent account opened the PR. + AI tools may help you draft, edit, or translate PR explanations and review replies. Review the final text before you send it, make sure you agree with it, and take responsibility for it. Do not send AI-generated text that you have not reviewed to maintainers or other contributors. Please be mindful of the maintainer's time. ## Keep the result maintainable