Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/sxzz/rolldown-plugin-dts. A Rolldown plugin to generate and bundle dts files.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798name: PR Template
on: pull_request_target: types: [opened, edited, reopened]
concurrency: group: pr-template-${{ github.event.pull_request.number }} cancel-in-progress: false
jobs: check: runs-on: ubuntu-slim permissions: pull-requests: write steps: # Never check out or execute PR code with this write-enabled token. - name: Check PR template uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | const params = { ...context.repo, pull_number: context.issue.number }; // Read the latest body so queued events do not check stale descriptions. const { data: pr } = await github.rest.pulls.get(params); if (pr.state !== 'open' || pr.user.type === 'Bot') return;
const { data: access } = await github.rest.repos.getCollaboratorPermissionLevel({ ...context.repo, username: pr.user.login, }); // GitHub maps maintain to write, including the base role of custom roles. if (['admin', 'write'].includes(access.permission)) return; if (!['read', 'none'].includes(access.permission)) { throw new Error(`Unexpected permission: ${access.permission}`); }
const label = 'incomplete template'; const marker = '<!-- pr-template-check -->'; const templateUrl = 'https://github.com/sxzz/.github/blob/main/.github/PULL_REQUEST_TEMPLATE.md';
// Only the AI usage disclosure is required; other sections and comments may be removed. const visibleBody = (pr.body ?? '').replace(/<!--[\s\S]*?-->/g, ''); const noAi = /^\s*[-*]\s*\[[xX]\]\s*No AI was used/m.test(visibleBody); const aiUsed = visibleBody.match(/^\s*[-*]\s*\[[xX]\]\s*AI was used\b:?(.*)$/m); const problems = []; if (noAi && aiUsed) { problems.push('Check only one of "No AI was used" and "AI was used".'); } else if (!noAi && !aiUsed) { problems.push('Check either "No AI was used" or "AI was used" in the AI usage section.'); } else if (aiUsed && !aiUsed[1].trim()) { problems.push('Describe your AI setup after "AI was used:", e.g. "Claude Code + Opus 4.8 High".'); }
const comments = await github.paginate(github.rest.issues.listComments, { ...context.repo, issue_number: pr.number, per_page: 100, }); const existing = comments.find( (c) => c.user?.type === 'Bot' && c.body?.includes(marker), ); const hasLabel = pr.labels.some((l) => l.name === label);
if (problems.length === 0) { if (hasLabel) { await github.rest.issues.removeLabel({ ...context.repo, issue_number: pr.number, name: label, }); } if (existing) { await github.rest.issues.deleteComment({ ...context.repo, comment_id: existing.id }); } return; }
const body = [ marker, `Thank you for contributing! Please complete the AI usage disclosure from the [PR template](${templateUrl}) in the PR description:`, '', ...problems.map((p) => `- ${p}`), '', `This PR stays open. The \`${label}\` label is removed automatically once the description is updated.`, ].join('\n'); if (existing) { await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body }); } else { await github.rest.issues.createComment({ ...context.repo, issue_number: pr.number, body }); } if (!hasLabel) { await github.rest.issues.addLabels({ ...context.repo, issue_number: pr.number, labels: [label], }); }