Skip to content

Commit f9bf0a8

Browse files
authored
fix: auto-approve workflow test (redhat-developer#3683)
* fix(auto-approve): add checkout step to fix 'not a git repository' error The gh CLI commands were failing because the repository wasn't checked out. Added actions/checkout@v4 step to ensure git context is available. * test: temporarily enable workflow for polasudo to test functionality * test: add fix/auto-approve-bot to eligible patterns for testing * fix(auto-approve): add issues:write permission for label management * fix(auto-approve): use pull_request_target for proper permissions Using pull_request_target instead of pull_request allows the workflow to run with write permissions even for PRs from forks or bot accounts. This is necessary for adding labels and approving PRs. * Fix auto-approve workflow: use REST API for adding labels instead of gh CLI * test: trigger workflow re-run * test: remove trigger file * test: temporarily disable user condition to test workflow * fix(auto-approve): use pull_request_target and add issues:write permission - Change trigger from pull_request to pull_request_target for proper permissions - Add issues:write permission required for label management - Add --repo flag to gh commands for explicit repository context - Remove checkout step (not needed with pull_request_target) - Fixes GraphQL: Resource not accessible by integration error * fix(auto-approve): add fix/auto-approve-bot pattern for testing * feat(auto-approve): add push trigger for faster testing feedback - Add push trigger on fix/auto-approve-bot branch for immediate testing - Handle both push and pull_request_target events in workflow logic - Add logging step for push events to show eligibility check results - Only run label/approve actions on actual PR events * test: trigger workflow rerun * test: simplify push logging to debug workflow triggering * test: add temporary PR labeling simulation for fork testing * test: enable real PR labeling on push events for testing * test: target PR #1 in fork for labeling test * test: target PR #2 for labeling demonstration * feat: clean up auto-approve workflow for production use - Remove all testing code (push triggers, test PR numbers, debug logging) - Simplify workflow to only run on pull_request_target events - Only run for rhdh-bot PRs - Keep fix/auto-approve-bot pattern for final testing before merge - Ready for production deployment * test: temporarily allow polasudo for final workflow testing * feat: finalize auto-approve workflow for production - Remove temporary polasudo testing allowance - Remove fix/auto-approve-bot test pattern - Clean, production-ready workflow for rhdh-bot PRs - Ready to merge and deploy * test: trigger workflow to demonstrate PR #2 labeling * Delete test-workflow-final.md * chore: reorganize auto-approve workflow flags for better readability
1 parent 59cfbd2 commit f9bf0a8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

.github/workflows/auto-approve-bot-prs.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ name: Auto-Approve Bot PRs
2020
# - Adds lgtm and approved labels if not present
2121

2222
on:
23-
pull_request:
23+
pull_request_target:
2424
types: [opened, reopened, labeled, ready_for_review]
2525

2626
permissions:
2727
contents: read
2828
pull-requests: write
29+
issues: write
2930

3031
jobs:
3132
auto-approve:
@@ -54,7 +55,7 @@ jobs:
5455
# Define branch patterns that are eligible for auto-approval
5556
# Add more patterns as needed
5657
ELIGIBLE_PATTERNS=(
57-
"^chore/automated-.*" # Automated chore tasks, such as version bumps, base image bumps, or RPM lock file version bumps
58+
"^chore/automated-.*"
5859
)
5960
6061
ELIGIBLE=false
@@ -76,16 +77,17 @@ jobs:
7677
if: steps.check-eligibility.outputs.eligible == 'true'
7778
run: |
7879
# Add the required labels if not already present
79-
gh pr edit ${{ github.event.pull_request.number }} --add-label "lgtm,approved"
80+
gh pr edit ${{ github.event.pull_request.number }} --add-label "lgtm,approved" --repo ${{ github.repository }}
8081
8182
# Auto-approve the PR
8283
gh pr review ${{ github.event.pull_request.number }} \
8384
--approve \
85+
--repo ${{ github.repository }} \
8486
--body "**Auto-Approved**
8587
86-
This PR has been automatically approved (rhdh-bot branch).
88+
This PR has been automatically approved by the auto-approve workflow.
8789
88-
**Labels Added:** \`lgtm\`, \`approved\`
90+
**Labels Added:** \`lgtm\`, \`approved\`"
8991
env:
9092
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9193

0 commit comments

Comments
 (0)