Second draft #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Review Checks | ||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| pull_request_review: | ||
| types: [submitted] | ||
| pull_request_review_comment: | ||
| types: [created, deleted] | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| jobs: | ||
| pr-review-checks: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check Copilot has reviewed and all comments resolved | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const prNumber = context.issue.number || context.payload.pull_request.number; | ||
| // Check if Copilot has reviewed the PR | ||
| const reviews = await github.paginate(github.rest.pulls.listReviews, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| per_page: 100, | ||
| }); | ||
| const copilotReviewed = reviews.some( | ||
| r => r.user.login === 'Copilot' || r.user.login === 'github-copilot[bot]' | ||
| ); | ||
| if (!copilotReviewed) { | ||
| core.setFailed('Copilot has not reviewed this PR yet.'); | ||
| return; | ||
| } | ||
| core.info('✅ Copilot has reviewed this PR.'); | ||
| // Comments that are part of unresolved threads have no direct "resolved" API field, | ||
| // but threads on PRs can be checked via GraphQL for their isResolved status. | ||
| const query = ` | ||
| query($owner: String!, $repo: String!, $pr: Int!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequest(number: $pr) { | ||
| reviewThreads(first: 100) { | ||
| nodes { | ||
| isResolved | ||
| isOutdated | ||
| comments(first: 1) { | ||
| nodes { | ||
| body | ||
| author { login } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `; | ||
| const result = await github.graphql(query, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pr: prNumber, | ||
| }); | ||
| const threads = result.repository.pullRequest.reviewThreads.nodes; | ||
| const unresolvedThreads = threads.filter(t => !t.isResolved && !t.isOutdated); | ||
| if (unresolvedThreads.length > 0) { | ||
| core.setFailed(`${unresolvedThreads.length} unresolved review comment(s) remaining.`); | ||
| return; | ||
| } | ||
| core.info('✅ All review comments are resolved.'); | ||