From a0c0963c483fc8f1aeed4547787d1673adcb583c Mon Sep 17 00:00:00 2001 From: rustdesk Date: Tue, 24 Nov 2026 23:46:30 +0800 Subject: [PATCH] Add PR evidence check and AI cross-review section The PR template gets an "AI cross-review" section: contributors list the models that reviewed the diff besides the one that wrote it, paste the review output or a share link, and give their decision on each finding. Findings can be wrong, so they are judged, not applied blindly. A pull_request_target workflow reads the PR description and file list (it never checks out PR code) and, for authors without write access, labels the PR needs-evidence and leaves one polite comment listing what is missing: test environment and results, reproduction for bug fixes, AI cross-review, screenshots or video for UI changes, and the approval link for features. Translation, docs and CI-only PRs skip the test and review checks. PRs opened before this template are left alone. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01JAxkkkfvhEPKVg85ZHovfs --- .github/pull_request_template.md | 19 ++- .github/workflows/pr-evidence-check.yml | 156 ++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/pr-evidence-check.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index ebc932aed..9a827bcd3 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,7 +5,7 @@ Read these before opening a PR. They apply whether the code is AI-generated or w PRs that skip these requirements, leave the sections below empty, or have an unjustifiably large regression surface may be closed without review. -Translation-only and docs-only PRs may skip the test and regression sections. +Translation-only, docs-only, and CI-only PRs may skip the test, AI cross-review, and regression sections. --> ## Type @@ -60,6 +60,21 @@ the change; for changes to existing UI, show before and after. Write "No UI impact" if there is none. --> +## AI cross-review + + + +**Models used:** + +**Review output, and your decision on each finding:** + ## Regression surface '; + const LABEL = 'needs-evidence'; + const APPROVAL_POLICY = 'https://github.com/rustdesk/rustdesk/discussions/17223'; + const TESTING_POLICY = 'https://github.com/rustdesk/rustdesk/discussions/17225'; + const TEMPLATE = 'https://github.com/rustdesk/rustdesk/blob/master/.github/pull_request_template.md'; + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const issue_number = pr.number; + // PRs opened before the template existed are left alone. + if (new Date(pr.created_at) < new Date('2026-11-24T15:46:22Z')) return; + // author_association can say CONTRIBUTOR for org members with private membership. + try { + const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ + owner, repo, username: pr.user.login, + }); + if (['admin', 'write'].includes(data.permission)) return; + } catch (e) { + core.info(`permission lookup failed: ${e.status}`); + } + + const files = (await github.paginate(github.rest.pulls.listFiles, { + owner, repo, pull_number: issue_number, per_page: 100, + })).map(f => f.filename); + const body = (pr.body || '').replace(//g, ''); + + const LABELS = { + env: /\*\*Environment\*\*(\s*\([^)]*\))?\s*:?/i, + repro: /\*\*Reproduced on master\*\*(\s*\([^)]*\))?\s*:?/i, + steps: /\*\*Steps and actual results with this PR:?\*\*:?/i, + untested: /\*\*Not tested \/ could not reproduce:?\*\*:?/i, + models: /\*\*Models used:?\*\*:?/i, + review: /\*\*Review output[^*\n]*:?\*\*:?/i, + }; + // Only the template's own headings end a section, so pasted review output may contain "##". + const HEADINGS = /\n##\s*(Type|Linked issue|What and why|End-to-end test|Screenshots|AI cross-review|Regression surface|Known limits|Checklist)\b/i; + const until = (text, res) => { + const ends = res.map(re => text.search(re)).filter(i => i >= 0); + return text.slice(0, ends.length ? Math.min(...ends) : text.length); + }; + function section(key) { + const m = LABELS[key].exec(body); + if (!m) return ''; + return until(body.slice(m.index + m[0].length), [...Object.values(LABELS), HEADINGS]); + } + function heading(re) { + const m = re.exec(body); + return m ? until(body.slice(m.index + m[0].length), [HEADINGS]) : ''; + } + const filled = text => text.replace(/^\s*(-|\d+\.)\s*$/gm, '').trim().length > 0; + const ticked = re => new RegExp(String.raw`^\s*-\s*\[[xX]\]\s*` + re.source, 'm').test(body); + + const missing = []; + const docsOnly = files.length > 0 && + files.every(f => /^(src\/lang\/|docs\/|\.github\/(?!patches\/))|\.md$/.test(f)); + if (!docsOnly) { + if (!/^## End-to-end test on real devices/m.test(body)) { + missing.push(`The test sections of the [PR template](${TEMPLATE}) seem to be missing. Please add them back and fill them in.`); + } else { + if (!filled(section('env'))) { + missing.push('**Environment**: the real devices you tested on (OS and version, controlling or controlled side, and so on).'); + } + if (ticked(/Bug fix\s*$/) && !filled(section('repro')) && !/reproduc/i.test(section('untested'))) { + missing.push('**Reproduced on master**: how you triggered the original issue on master, or under **Not tested / could not reproduce** why you could not.'); + } + if (!filled(section('steps'))) { + missing.push('**Steps and actual results with this PR**: what you did on those devices and what happened.'); + } + const review = section('review'); + const proof = /https?:\/\/|
= 100; + if (!filled(section('models')) || !proof) { + missing.push('**AI cross-review**: the AI models, other than the one that wrote the code, that reviewed this diff, with their review output (pasted or a share link) and your decision on each finding. Findings can be wrong, so you do not have to fix all of them, but say why you left one.'); + } + } + } + + const touchesUi = files.some(f => /^(flutter\/lib\/|src\/ui\/)/.test(f)); + const hasMedia = /github\.com\/user-attachments\/(assets|files)\/|user-images\.githubusercontent\.com\/| m[1]).filter(n => !POLICIES.includes(n)); + if (refs.length === 0) { + missing.push(`**Feature approval**: a link to the discussion where a maintainer approved this feature ([why](${APPROVAL_POLICY})).`); + } + } + + const comments = await github.paginate(github.rest.issues.listComments, { + owner, repo, issue_number, per_page: 100, + }); + const previous = comments.find(c => c.user.type === 'Bot' && c.body.includes(MARKER)); + const ignore = (...codes) => e => { if (!codes.includes(e.status)) throw e; }; + + if (missing.length === 0) { + await github.rest.issues.removeLabel({ owner, repo, issue_number, name: LABEL }).catch(ignore(404)); + const done = `${MARKER}\nThanks for updating the description. The automated check has nothing more to ask for.`; + if (previous && previous.body !== done) { + await github.rest.issues.updateComment({ owner, repo, comment_id: previous.id, body: done }); + } + return; + } + + const text = [ + MARKER, + 'Thanks for the contribution! This is an automated reminder. Before a maintainer reviews this PR, please add the following to the PR description:', + '', + ...missing.map(m => `- ${m}`), + '', + `We ask for these because of [feature approval](${APPROVAL_POLICY}) and [end-to-end testing on real devices](${TESTING_POLICY}). This check runs again when you edit the description.`, + ].join('\n'); + + await github.rest.issues.createLabel({ + owner, repo, name: LABEL, color: 'fbca04', + description: 'PR description is missing test evidence or approval', + }).catch(ignore(422)); + await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [LABEL] }); + if (!previous) { + await github.rest.issues.createComment({ owner, repo, issue_number, body: text }); + } else if (previous.body !== text) { + await github.rest.issues.updateComment({ owner, repo, comment_id: previous.id, body: text }); + }