Skip to content

Commit 1c893d6

Browse files
authored
[ci] Updated CI failure bot caller and docs #616
- Set write permissions only on "call-ci-failure-bot" - Handled case in which PR author cannot be fetched Related to #616
1 parent 3e8c51a commit 1c893d6

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

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

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

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

1414
concurrency:
@@ -34,8 +34,8 @@ 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 "")
38-
if [ -z "$pr_author" ]; then
37+
pr_author=$(gh pr view "$pr_number" --repo "$REPO" --json author --jq '.author.login // empty' 2>/dev/null || echo "")
38+
if [ -z "$pr_author" ] || [ "$pr_author" = "null" ]; then
3939
echo "::warning::Could not fetch PR author for PR #$pr_number"
4040
fi
4141
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
@@ -68,6 +68,10 @@ jobs:
6868
call-ci-failure-bot:
6969
needs: find-pr
7070
if: ${{ needs.find-pr.outputs.pr_number != '' }}
71+
permissions:
72+
pull-requests: write
73+
actions: write
74+
contents: read
7175
uses: openwisp/openwisp-utils/.github/workflows/reusable-bot-ci-failure.yml@master
7276
with:
7377
pr_number: ${{ needs.find-pr.outputs.pr_number }}

docs/developer/reusable-github-utils.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ job:
383383
- completed
384384
385385
permissions:
386-
pull-requests: write
387-
actions: write
386+
pull-requests: read
387+
actions: read
388388
contents: read
389389
390390
concurrency:
@@ -410,8 +410,8 @@ job:
410410
emit_pr() {
411411
local pr_number="$1"
412412
local pr_author
413-
pr_author=$(gh pr view "$pr_number" --repo "$REPO" --json author --jq '.author.login' 2>/dev/null || echo "")
414-
if [ -z "$pr_author" ]; then
413+
pr_author=$(gh pr view "$pr_number" --repo "$REPO" --json author --jq '.author.login // empty' 2>/dev/null || echo "")
414+
if [ -z "$pr_author" ] || [ "$pr_author" = "null" ]; then
415415
echo "::warning::Could not fetch PR author for PR #$pr_number"
416416
fi
417417
echo "number=$pr_number" >> "$GITHUB_OUTPUT"
@@ -444,6 +444,10 @@ job:
444444
call-ci-failure-bot:
445445
needs: find-pr
446446
if: ${{ needs.find-pr.outputs.pr_number != '' }}
447+
permissions:
448+
pull-requests: write
449+
actions: write
450+
contents: read
447451
uses: openwisp/openwisp-utils/.github/workflows/reusable-bot-ci-failure.yml@master
448452
with:
449453
pr_number: ${{ needs.find-pr.outputs.pr_number }}

0 commit comments

Comments
 (0)