Skip to content
Merged
63 changes: 63 additions & 0 deletions .github/workflows/pr-approval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Approve Copilot reviews

on:
pull_request_review:
types: [submitted]

permissions:
contents: read
pull-requests: write

jobs:
auto-approve:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Check Copilot Review and Approval
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
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\\.)"; "i")
')

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 and all threads resolved. 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 "Copilot review is clean. Approving PR..."

gh pr review "$PR_URL" --repo "$REPO" --approve --body "Auto-approved based on clean Copilot review."
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"source": [
"src/index.ts"
],
"optimize": true,
"publicUrl": "/hacsfiles/ha-weather-forecast-card/",
"includeNodeModules": true
}
},
"scripts": {
"dev": "parcel serve test/app/index.html test/app/resources/img/*.svg --open",
"build": "parcel build --no-source-maps --target module",
"build:debug": "parcel build --target module --no-optimize",
"clean": "rm -rf ./dist/ ./.parcel-cache",
"preview": "parcel serve test/app/index.html --no-hmr"
},
Expand Down