-
Notifications
You must be signed in to change notification settings - Fork 223
96 lines (78 loc) · 2.99 KB
/
Copy pathauto-approve-bot-prs.yaml
File metadata and controls
96 lines (78 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Auto-Approve Bot PRs
# This workflow automatically adds labels and approves PRs that match specific criteria:
# - Created by rhdh-bot (via RHDH GitHub App)
# - Branch name matches specific patterns (base image updates, version bumps, etc.)
# - Adds lgtm and approved labels if not present
on:
pull_request_target:
types: [opened, reopened, labeled, ready_for_review]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
auto-approve:
name: Auto-Approve and Label PRs
runs-on: ubuntu-latest
# Only run if PR is from rhdh-bot
if: github.event.pull_request.user.login == 'rhdh-bot'
steps:
- name: Check PR eligibility
id: check-eligibility
env:
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
PR_DRAFT: ${{ github.event.pull_request.draft }}
run: |
# Don't auto-approve draft PRs
if [[ "$PR_DRAFT" == "true" ]]; then
echo "eligible=false" >> $GITHUB_OUTPUT
echo "reason=PR is in draft state" >> $GITHUB_OUTPUT
exit 0
fi
# Labels will be added automatically if eligible
# Define branch patterns that are eligible for auto-approval
# Add more patterns as needed
ELIGIBLE_PATTERNS=(
"^chore/automated-.*"
)
ELIGIBLE=false
for pattern in "${ELIGIBLE_PATTERNS[@]}"; do
if [[ "$PR_BRANCH" =~ $pattern ]]; then
ELIGIBLE=true
break
fi
done
if [[ "$ELIGIBLE" == "true" ]]; then
echo "eligible=true" >> $GITHUB_OUTPUT
else
echo "eligible=false" >> $GITHUB_OUTPUT
fi
- name: Add required labels and approve PR
if: steps.check-eligibility.outputs.eligible == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Add the required labels if not already present
gh pr edit "$PR_NUMBER" --add-label "lgtm,approved" --repo "$GITHUB_REPOSITORY"
# Auto-approve the PR
gh pr review "$PR_NUMBER" \
--approve \
--repo "$GITHUB_REPOSITORY" \
--body "**Auto-Approved**
This PR has been automatically approved by the auto-approve workflow.
/override ci/prow/e2e-ocp-helm
**Labels Added:** \`lgtm\`, \`approved\`"