Skip to content

Commit fd1768c

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 fd1768c

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

.github/workflows/label-command.yml

Lines changed: 36 additions & 6 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,39 @@ 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+
EVENT_NAME: ${{ github.event_name }}
52+
run: |
53+
if [ "${EVENT_NAME}" = "issue_comment" ]; then
54+
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
55+
COMMENT_AUTHOR="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")"
56+
ISSUE_NUMBER="${{ github.event.issue.number }}"
57+
else
58+
PR_URL="$(jq -r '.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
59+
COMMENT_AUTHOR="$(jq -r '.review.user.login' "${GITHUB_EVENT_PATH}")"
60+
ISSUE_NUMBER="${{ github.event.pull_request.number }}"
61+
fi
62+
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
63+
echo "comment_author=${COMMENT_AUTHOR}" >> $GITHUB_OUTPUT
64+
echo "issue_number=${ISSUE_NUMBER}" >> $GITHUB_OUTPUT
65+
4066
- name: Get base ref
4167
id: base_ref
4268
env:
4369
GH_TOKEN: ${{ github.token }}
70+
PR_URL: ${{ steps.event_data.outputs.pr_url }}
4471
run: |
45-
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
4672
REF="$(gh pr view "${PR_URL}" --json baseRefName --jq .baseRefName)"
4773
echo "BASE_REF=${REF}" >>"${GITHUB_OUTPUT}"
4874
@@ -58,15 +84,14 @@ jobs:
5884
id: authorized
5985
env:
6086
GH_TOKEN: ${{ github.token }}
87+
PR_URL: ${{ steps.event_data.outputs.pr_url }}
88+
COMMENT_AUTHOR: ${{ steps.event_data.outputs.comment_author }}
6189
run: |
6290
authorization() {
6391
echo "AUTHORIZED=$1" >>"${GITHUB_OUTPUT}"
6492
echo "Authorized: $1"
6593
exit 0
6694
}
67-
68-
PR_URL="$(jq -r '.issue.pull_request.html_url' "${GITHUB_EVENT_PATH}")"
69-
COMMENT_AUTHOR="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")"
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)