-
Notifications
You must be signed in to change notification settings - Fork 0
feat: make pr-review-mention an org standard #237
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e4b446
feat: make pr-review-mention an org standard with reusable workflow
don-petry c6fc3ec
fix: remove unused counter vars (SC2034), add trailing newline to cod…
don-petry d455e49
fix: address Gemini review comments on deploy-standard-workflows.sh
don-petry 28a9b93
fix: address Copilot review comments
don-petry 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,132 @@ | ||
| # Reusable PR Review — Mention Trigger workflow. | ||
| # Single source of truth for the org: all review-dispatch logic lives here. | ||
| # Repo-level pr-review-mention.yml files are thin caller stubs. | ||
| # Standard: https://github.com/petry-projects/.github/blob/main/standards/ci-standards.md | ||
| # | ||
| # Fires when @petry-review-bot is mentioned in a PR comment / review comment, | ||
| # or when donpetry-bot is assigned as a reviewer on a PR. Dispatches a | ||
| # repository_dispatch event to petry-projects/.github-private to trigger the | ||
| # pr-review agent cascade. | ||
| # | ||
| # Requires: GH_PAT_WORKFLOWS org secret (classic PAT with repo scope). | ||
| name: PR Review — Mention Trigger (Reusable) | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| GH_PAT_WORKFLOWS: | ||
| description: "Classic PAT with repo scope used to post comments and dispatch the review agent" | ||
| required: true | ||
|
|
||
| jobs: | ||
| handle-mention: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| # Fire when: | ||
| # (a) donpetry-bot is added as a reviewer on a same-repo PR (fork PRs | ||
| # don't receive org secrets so we exclude them), OR | ||
| # (b) @petry-review-bot is mentioned in a PR comment / review comment. | ||
| # | ||
| # Guard each branch against missing fields: requested_reviewer is null for | ||
| # team review requests; comment fields don't exist on pull_request events. | ||
| if: | | ||
| (github.event_name == 'pull_request' && | ||
| github.event.requested_reviewer != null && | ||
| github.event.requested_reviewer.login == 'donpetry-bot' && | ||
| github.event.pull_request.head.repo.full_name == github.repository) || | ||
| (github.event_name != 'pull_request' && | ||
| contains(github.event.comment.body, '@petry-review-bot') && | ||
| (github.event_name == 'pull_request_review_comment' || | ||
| github.event.issue.pull_request != null)) | ||
|
|
||
| steps: | ||
| - name: Check commenter trust level | ||
| id: trust | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
| run: | | ||
| # Only OWNER, MEMBER, and COLLABORATOR can trigger reviews. | ||
| # This prevents external contributors or bots from burning review quota. | ||
| # | ||
| # For review_requested events author_association is absent from the | ||
| # sender payload, so query the collaborator permission API instead. | ||
| # The endpoint returns a top-level .permission string: | ||
| # "admin" | "write" | "read" | "none" | ||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| ACTOR="${{ github.event.sender.login }}" | ||
| PERM=$(gh api /repos/${{ github.repository }}/collaborators/${{ github.event.sender.login }}/permission \ | ||
| --jq '.permission' 2>/dev/null || echo "none") | ||
| case "$PERM" in | ||
| admin|write) | ||
| echo "trusted=true" >> "$GITHUB_OUTPUT" | ||
| echo "Actor @$ACTOR has permission $PERM — trusted" | ||
| ;; | ||
| *) | ||
| echo "trusted=false" >> "$GITHUB_OUTPUT" | ||
| echo "Actor @$ACTOR has permission $PERM — not trusted, skipping" | ||
| ;; | ||
| esac | ||
| else | ||
| ACTOR="${{ github.event.comment.user.login }}" | ||
| ASSOC="${{ github.event.comment.author_association }}" | ||
| case "$ASSOC" in | ||
| OWNER|MEMBER|COLLABORATOR) | ||
| echo "trusted=true" >> "$GITHUB_OUTPUT" | ||
| echo "Actor @$ACTOR has association $ASSOC — trusted" | ||
| ;; | ||
| *) | ||
| echo "trusted=false" >> "$GITHUB_OUTPUT" | ||
| echo "Actor @$ACTOR has association $ASSOC — not trusted, skipping" | ||
| ;; | ||
| esac | ||
| fi | ||
|
|
||
| - name: Resolve PR URL | ||
| id: pr | ||
| if: steps.trust.outputs.trusted == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| PR_URL="${{ github.event.pull_request.html_url }}" | ||
| elif [ "${{ github.event_name }}" = "pull_request_review_comment" ]; then | ||
| PR_URL="${{ github.event.pull_request.html_url }}" | ||
| else | ||
| # issue_comment: resolve the PR URL from the issue's pull_request link | ||
| PR_URL=$(gh api "${{ github.event.issue.pull_request.url }}" --jq '.html_url') | ||
| fi | ||
| echo "pr_url=$PR_URL" >> "$GITHUB_OUTPUT" | ||
| echo "PR URL: $PR_URL" | ||
|
|
||
| - name: Post acknowledgement comment | ||
| if: steps.trust.outputs.trusted == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
| PR_URL: ${{ steps.pr.outputs.pr_url }} | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| ACTOR="${{ github.event.sender.login }}" | ||
| MSG="@${ACTOR} assigned me as reviewer — starting a fresh review now. Results will appear in a few minutes." | ||
| else | ||
| ACTOR="${{ github.event.comment.user.login }}" | ||
| MSG="@${ACTOR} I'm on it — starting a fresh review now. Results will appear in a few minutes." | ||
| fi | ||
| gh pr comment "$PR_URL" --body "$(printf '<!-- pr-review-agent mention-ack -->\n%s' "${MSG}")" | ||
|
|
||
| - name: Trigger review agent | ||
| if: steps.trust.outputs.trusted == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
| PR_URL: ${{ steps.pr.outputs.pr_url }} | ||
| run: | | ||
| # repository_dispatch requires only Contents: write, not Actions: write. | ||
| # pr-review.yml in .github-private listens for "pr-review-mention" and | ||
| # extracts client_payload.pr_url to run the cascade. | ||
| gh api \ | ||
| --method POST \ | ||
| --header "Accept: application/vnd.github+json" \ | ||
| /repos/petry-projects/.github-private/dispatches \ | ||
| --field event_type=pr-review-mention \ | ||
| --field "client_payload[pr_url]=$PR_URL" | ||
| echo "Dispatch sent for $PR_URL" | ||
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
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
Oops, something went wrong.
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.