Skip to content

Commit a7a3414

Browse files
committed
update approved workflow to also handle pull request review comments
Signed-off-by: Adam D. Cornett <adc@redhat.com>
1 parent 436edac commit a7a3414

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

.github/workflows/label-command.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Handle PR comments
33
on:
44
issue_comment:
55
types: [created, edited]
6+
pull_request_review:
7+
types: [submitted]
68
workflow_call:
79

810
jobs:
@@ -34,15 +36,38 @@ jobs:
3436
labels: pipeline/trigger-release
3537

3638
approve:
37-
if: ${{ github.event.issue.pull_request && startsWith(github.event.repository.name, 'community-') && github.event.issue.state == 'open' && startsWith(github.event.comment.body, '/approve') }}
39+
if: |
40+
startsWith(github.event.repository.name, 'community-') &&
41+
(
42+
(github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.issue.state == 'open' && startsWith(github.event.comment.body, '/approve')) ||
43+
(github.event_name == 'pull_request_review' && github.event.pull_request.state == 'open' && startsWith(github.event.review.body, '/approve'))
44+
)
3845
runs-on: [ubuntu-latest]
3946
steps:
47+
- name: Normalize event data
48+
id: event_data
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
run: |
52+
if [ "${{ github.event_name }}" = "issue_comment" ]; then
53+
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
54+
COMMENT_AUTHOR="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")"
55+
ISSUE_NUMBER="${{ github.event.issue.number }}"
56+
else
57+
PR_URL="$(jq -r '.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
58+
COMMENT_AUTHOR="$(jq -r '.review.user.login' "${GITHUB_EVENT_PATH}")"
59+
ISSUE_NUMBER="${{ github.event.pull_request.number }}"
60+
fi
61+
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
62+
echo "comment_author=${COMMENT_AUTHOR}" >> $GITHUB_OUTPUT
63+
echo "issue_number=${ISSUE_NUMBER}" >> $GITHUB_OUTPUT
64+
4065
- name: Get base ref
4166
id: base_ref
4267
env:
4368
GH_TOKEN: ${{ github.token }}
4469
run: |
45-
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
70+
PR_URL="${{ steps.event_data.outputs.pr_url }}"
4671
REF="$(gh pr view "${PR_URL}" --json baseRefName --jq .baseRefName)"
4772
echo "BASE_REF=${REF}" >>"${GITHUB_OUTPUT}"
4873
@@ -65,8 +90,8 @@ jobs:
6590
exit 0
6691
}
6792
68-
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
69-
COMMENT_AUTHOR="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")"
93+
PR_URL="${{ steps.event_data.outputs.pr_url }}"
94+
COMMENT_AUTHOR="${{ steps.event_data.outputs.comment_author }}"
7095
mapfile -t AFFECTED_OPERATORS < <(
7196
gh pr diff "${PR_URL}" --name-only |
7297
awk -F/ '$1=="operators"&&NF>2{operators[$2]=1} $1=="catalogs"&&NF>3{operators[$3]=1} END{for (o in operators) print o}'
@@ -82,7 +107,12 @@ jobs:
82107
83108
- name: Apply approved label
84109
uses: actions-ecosystem/action-add-labels@v1
85-
if: ${{ steps.authorized.outputs.AUTHORIZED == 'true' && !contains(github.event.issue.labels.*.name, 'approved') }}
110+
if: |
111+
steps.authorized.outputs.AUTHORIZED == 'true' &&
112+
(
113+
(github.event_name == 'issue_comment' && !contains(github.event.issue.labels.*.name, 'approved')) ||
114+
(github.event_name == 'pull_request_review' && !contains(github.event.pull_request.labels.*.name, 'approved'))
115+
)
86116
with:
87117
labels: approved
88118

0 commit comments

Comments
 (0)