Skip to content

Commit 2b884f6

Browse files
authored
Merge pull request #2040 from cuthbertLab/fix-profiler-issues-permission
Grant profile_contributors the issues:read scope gh-profiler needs
2 parents eebac0e + c3ee613 commit 2b884f6

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

‎.github/workflows/profile_contributors.yml‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Profile the author of a PR from someone with no merged PR here yet, and comment
2-
# only when gh-profiler raises a yellow or red flag.
2+
# only when gh-profiler raises a yellow or red flag, or when it could not run.
33
#
44
# gh-profiler is by Eric Matthes: https://github.com/ehmatthes/gh-profiler
55

@@ -11,6 +11,9 @@ on:
1111
types: [opened]
1212

1313
permissions:
14+
# gh-profiler reads the author's recent issues; without issues:read the Actions
15+
# token cannot resolve Issue objects and every search node comes back empty.
16+
issues: read
1417
pull-requests: write
1518

1619
jobs:
@@ -41,9 +44,18 @@ jobs:
4144
GH_TOKEN: ${{ github.token }}
4245
AUTHOR: ${{ github.event.pull_request.user.login }}
4346
run: |
44-
uvx gh-profiler==0.9.0 "$AUTHOR" --concise | tee profile.txt
47+
# gh-profiler raises on an issue or PR the token cannot resolve
48+
# (ehmatthes/gh-profiler#143), and an unprofiled author is not a red check.
49+
if ! uvx gh-profiler==0.9.0 "$AUTHOR" --concise > profile.txt; then
50+
cat profile.txt
51+
echo "::warning::gh-profiler failed on $AUTHOR; profile by hand."
52+
echo "concern=false" >> "$GITHUB_OUTPUT"
53+
echo "failed=true" >> "$GITHUB_OUTPUT"
54+
exit 0
55+
fi
56+
cat profile.txt
4557
echo '===================== Full profile ====================='
46-
uvx gh-profiler==0.9.0 "$AUTHOR"
58+
uvx gh-profiler==0.9.0 "$AUTHOR" || true
4759
4860
# A yellow on the profile section alone means only that the account is
4961
# newish or has empty bio fields, which is not worth a public comment.
@@ -72,3 +84,18 @@ jobs:
7284
} > comment.txt
7385
7486
gh pr comment "$PR" --body-file comment.txt
87+
88+
# The traceback stays in the log; a public comment does not need it.
89+
- name: Comment on PR when profiling could not run
90+
if: steps.previous.outputs.count == '0' && steps.profile.outputs.failed == 'true'
91+
env:
92+
GH_TOKEN: ${{ github.token }}
93+
PR: ${{ github.event.pull_request.number }}
94+
run: |
95+
{
96+
echo 'Contributor profiling ([gh-profiler](https://github.com/ehmatthes/gh-profiler))'
97+
echo 'could not run here, so a maintainer will read this PR without it.'
98+
echo 'Nothing is wrong with the pull request itself.'
99+
} > comment.txt
100+
101+
gh pr comment "$PR" --body-file comment.txt

0 commit comments

Comments
 (0)