Skip to content

Commit 8a28ddf

Browse files
authored
[ci] Updated CI failure bot caller: permissions, PR author
1 parent 98afa9b commit 8a28ddf

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

.github/workflows/bot-ci-failure.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- completed
88

99
permissions:
10-
pull-requests: write
10+
pull-requests: read
1111
actions: read
1212
contents: read
1313

@@ -18,7 +18,7 @@ concurrency:
1818
jobs:
1919
find-pr:
2020
runs-on: ubuntu-latest
21-
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
21+
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }}
2222
outputs:
2323
pr_number: ${{ steps.pr.outputs.number }}
2424
pr_author: ${{ steps.pr.outputs.author }}
@@ -34,9 +34,10 @@ jobs:
3434
emit_pr() {
3535
local pr_number="$1"
3636
local pr_author
37-
pr_author=$(gh pr view "$pr_number" --repo "$REPO" --json author --jq '.author.login' 2>/dev/null || echo "")
37+
pr_author=$(gh pr view "$pr_number" --repo "$REPO" --json author --jq '.author.login // empty' 2>/dev/null || echo "")
3838
if [ -z "$pr_author" ]; then
39-
echo "::warning::Could not fetch PR author for PR #$pr_number"
39+
pr_author="${{ github.event.workflow_run.actor.login }}"
40+
echo "::warning::Could not fetch PR author for PR #$pr_number; falling back to @$pr_author"
4041
fi
4142
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
4243
echo "author=$pr_author" >> "$GITHUB_OUTPUT"
@@ -49,7 +50,7 @@ jobs:
4950
fi
5051
HEAD_SHA="$EVENT_HEAD_SHA"
5152
echo "Payload empty. Searching for PR via Commits API..."
52-
PR_NUMBER=$(gh api repos/$REPO/commits/$HEAD_SHA/pulls -q '.[0].number' 2>/dev/null || true)
53+
PR_NUMBER=$(gh api repos/$REPO/commits/$HEAD_SHA/pulls -q '[.[] | select(.state == "open")][0].number' 2>/dev/null || true)
5354
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
5455
echo "Found PR #$PR_NUMBER using Commits API."
5556
emit_pr "$PR_NUMBER"
@@ -68,6 +69,10 @@ jobs:
6869
call-ci-failure-bot:
6970
needs: find-pr
7071
if: ${{ needs.find-pr.outputs.pr_number != '' }}
72+
permissions:
73+
pull-requests: write
74+
actions: write
75+
contents: read
7176
uses: openwisp/openwisp-utils/.github/workflows/reusable-bot-ci-failure.yml@master
7277
with:
7378
pr_number: ${{ needs.find-pr.outputs.pr_number }}

0 commit comments

Comments
 (0)