Files
clash-verge-rev/.github/workflows/shared/pr-review-context.md
T

1.8 KiB

steps
steps
name uses env with
Prepare bounded PR context actions/github-script@3a2844b7e9
PR_NUMBER EXPECTED_HEAD
${{ github.event.pull_request.number || github.event.issue.number || inputs.pr_number }} ${{ inputs.head_sha }}
script
const fs = require('fs'); const number = process.env.PR_NUMBER; if (!/^[1-9][0-9]*$/.test(number)) throw new Error('A PR number is required'); const params = { ...context.repo, pull_number: Number(number) }; const { data: pr } = await github.rest.pulls.get(params); if (process.env.EXPECTED_HEAD && pr.head.sha !== process.env.EXPECTED_HEAD) { throw new Error('PR head changed after trigger; await the newer run'); } const { data: files } = await github.rest.pulls.listFiles({ ...params, per_page: 100 }); const body = pr.body || ''; const snapshot = { repository: `${context.repo.owner}/${context.repo.repo}`, number: pr.number, url: pr.html_url, state: pr.state, draft: pr.draft, title: pr.title, body: body.slice(0, 12000), body_truncated: body.length > 12000, created_at: pr.created_at, author: pr.user.login, base_sha: pr.base.sha, head_sha: pr.head.sha, head_repository: pr.head.repo?.full_name, labels: pr.labels.map(label => label.name), changed_files: pr.changed_files, files_truncated: pr.changed_files > files.length, files: files.map(({ filename, previous_filename, status, additions, deletions }) => ({ filename, previous_filename, status, additions, deletions })), }; fs.mkdirSync('/tmp/gh-aw/agent', { recursive: true }); fs.writeFileSync('/tmp/gh-aw/agent/pr-context.json', JSON.stringify(snapshot));