diff --git a/.github/workflows/issue-command.yml b/.github/workflows/issue-command.yml index cd4f7932a..09b5275b8 100644 --- a/.github/workflows/issue-command.yml +++ b/.github/workflows/issue-command.yml @@ -70,7 +70,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, - body: 'This pull request has been automatically closed.', + body: 'This pull request has been automatically closed for denounced users by [vouch](https://github.com/mitchellh/vouch).' }); await github.rest.pulls.update({ owner: context.repo.owner, diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8fde69791..0adea99e9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -80,12 +80,11 @@ jobs: runs-on: ubuntu-slim timeout-minutes: 5 steps: - - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - - name: Check if PR author is denounced - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + uses: mitchellh/vouch/action/check-pr@c6d80ead49839655b61b422700b7a3bc9d0804a9 # v1.4.2 with: - script: | - const { default: checkPr } = await import('${{ github.workspace }}/scripts/workflow/vouch/check-pr.mjs') - await checkPr({ github, context, core }) + pr-number: ${{ github.event.pull_request.number }} + auto-close: true + require-vouch: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/workflow/vouch/check-pr.mjs b/scripts/workflow/vouch/check-pr.mjs deleted file mode 100644 index 0f0b04a47..000000000 --- a/scripts/workflow/vouch/check-pr.mjs +++ /dev/null @@ -1,115 +0,0 @@ -/** - * @param {{ github: ReturnType, context: typeof import('@actions/github').context, core: typeof import('@actions/core') }} githubScript - * @returns {Promise} - */ -export default async function checkPr({ github, context, core }) { - const author = context.payload.pull_request.user.login; - const prNumber = context.payload.pull_request.number; - - // Skip bots - if (author.endsWith('[bot]')) { - core.info(`Skipping bot: ${author}`); - return; - } - - // Read the VOUCHED.td file via API (no checkout needed) - let content; - try { - const response = await github.rest.repos.getContent({ - owner: context.repo.owner, - repo: context.repo.repo, - path: '.github/VOUCHED.td', - }); - content = Buffer.from(response.data.content, 'base64').toString('utf-8'); - } catch (error) { - if (error.status === 404) { - core.info('No .github/VOUCHED.td file found, skipping check.'); - return; - } - throw error; - } - - // Parse the .td file for vouched and denounced users - const vouched = new Set(); - const denounced = new Map(); - for (const line of content.split('\n')) { - const trimmed = line.trim(); - if (!trimmed || trimmed.startsWith('#')) { - continue; - } - - const isDenounced = trimmed.startsWith('-'); - const rest = isDenounced ? trimmed.slice(1).trim() : trimmed; - if (!rest) { - continue; - } - - const spaceIdx = rest.indexOf(' '); - const handle = spaceIdx === -1 ? rest : rest.slice(0, spaceIdx); - const reason = spaceIdx === -1 ? null : rest.slice(spaceIdx + 1).trim(); - - // Handle platform:username or bare username - // Only match bare usernames or github: prefix (skip other platforms) - const colonIdx = handle.indexOf(':'); - if (colonIdx !== -1) { - const platform = handle.slice(0, colonIdx).toLowerCase(); - if (platform !== 'github') { - continue; - } - } - const username = colonIdx === -1 ? handle : handle.slice(colonIdx + 1); - if (!username) { - continue; - } - - if (isDenounced) { - denounced.set(username.toLowerCase(), reason); - continue; - } - - vouched.add(username.toLowerCase()); - } - - // Check if the author is denounced - const reason = denounced.get(author.toLowerCase()); - if (reason !== undefined) { - // Author is denounced — close the PR - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: 'This pull request has been automatically closed.', - }); - - await github.rest.pulls.update({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber, - state: 'closed', - }); - - core.info(`Closed PR #${prNumber} from denounced user ${author}`); - return; - } - - // Author is positively vouched — add label - if (!vouched.has(author.toLowerCase())) { - core.info(`User ${author} is not denounced or vouched. Allowing PR.`); - return; - } - - const association = context.payload.pull_request.author_association; - if (['OWNER', 'MEMBER', 'COLLABORATOR'].includes(association)) { - core.info(`Skipping vouched label for collaborator ${author} (${association}).`); - return; - } - - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - labels: ['vouched'], - }); - - core.info(`Added vouched label to PR #${prNumber} from ${author}`); -}