-
Notifications
You must be signed in to change notification settings - Fork 5
ci: add auto-approval for copilot reviews #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
caabb3b
ci: add auto-approval for copilot reviews
troinine 94cebb6
Merge branch 'main' into chore/pr-approval
troinine 18f4179
Update .github/workflows/copilot-review-approval.yml
troinine 9dabc7b
Update .github/workflows/copilot-review-approval.yml
troinine c164a3d
Update .github/workflows/copilot-review-approval.yml
troinine 00e2af9
Update .github/workflows/copilot-review-approval.yml
troinine e75e36d
fix: escape regex metacharacters in workflow file pattern matching (#5)
Copilot 966cda2
Update .github/workflows/copilot-review-approval.yml
troinine e609a47
ci: make sure .github matches correctly
troinine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: Approve Copilot reviews | ||
|
|
||
| on: | ||
| pull_request_review: | ||
| types: [submitted] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
| concurrency: | ||
| group: pr-approval-${{ github.head_ref }} | ||
troinine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| auto-approve: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.pull_request.draft == false | ||
troinine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| steps: | ||
| - name: Check Copilot Review and Approval | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
troinine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
troinine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| PR_DATA=$(gh pr view "$PR_URL" --repo "$REPO" --json reviews) | ||
|
|
||
| LATEST_COPILOT_REVIEW=$(echo "$PR_DATA" | jq -r ' | ||
| [(.reviews // [])[] | select(.author.login == "copilot-pull-request-reviewer")] | ||
| | sort_by(.submittedAt) | ||
| | last | ||
| ') | ||
|
|
||
| if [ "$LATEST_COPILOT_REVIEW" == "null" ]; then | ||
| echo "No reviews found from copilot-pull-request-reviewer. Skipping." | ||
| exit 0 | ||
| fi | ||
|
|
||
| IS_CLEAN=$(echo "$LATEST_COPILOT_REVIEW" | jq -r ' | ||
| .body | test("Copilot reviewed \\d+ out of \\d+ changed files in this pull request and generated no new comments\\.") | ||
troinine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ') | ||
|
|
||
| if [ "$IS_CLEAN" != "true" ]; then | ||
| echo "Latest Copilot review does not indicate a clean state (generated no new comments)." | ||
| echo "Review Body: $(echo "$LATEST_COPILOT_REVIEW" | jq -r .body)" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Copilot review is clean. Checking for existing approvals..." | ||
|
|
||
| EXISTING_APPROVAL=$(echo "$PR_DATA" | jq -r ' | ||
| [(.reviews // [])[] | select( | ||
| (.state == "APPROVED") and | ||
| (.author.login == "github-actions[bot]" or .author.login == "copilot-pull-request-reviewer") | ||
| )] | ||
| | length | ||
| ') | ||
| if [ "$EXISTING_APPROVAL" -gt 0 ]; then | ||
| echo "An approval review already exists from github-actions[bot] or copilot-pull-request-reviewer. Skipping approval." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Checking if sensitive files have been modified..." | ||
|
|
||
| SENSITIVE_PATTERNS=' | ||
| .github/workflows/ | ||
| ' | ||
| CHANGED_FILES=$(gh pr view "$PR_URL" --repo "$REPO" --json files | jq -r '.files[].path') | ||
| for pattern in $SENSITIVE_PATTERNS; do | ||
troinine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if echo "$CHANGED_FILES" | grep -q "^$pattern"; then | ||
| echo "PR modifies sensitive file(s) matching pattern: $pattern" | ||
| echo "Auto-approval is not allowed for PRs that modify workflow, dependency, or security-sensitive files." | ||
troinine marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exit 0 | ||
| fi | ||
| done | ||
troinine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "Copilot review is clean. Approving PR..." | ||
|
|
||
| gh pr review "$PR_URL" --repo "$REPO" --approve --body "Auto-approved based on clean Copilot review." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.