|
1 | 1 | # 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. |
3 | 3 | # |
4 | 4 | # gh-profiler is by Eric Matthes: https://github.com/ehmatthes/gh-profiler |
5 | 5 |
|
|
11 | 11 | types: [opened] |
12 | 12 |
|
13 | 13 | 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 |
14 | 17 | pull-requests: write |
15 | 18 |
|
16 | 19 | jobs: |
|
41 | 44 | GH_TOKEN: ${{ github.token }} |
42 | 45 | AUTHOR: ${{ github.event.pull_request.user.login }} |
43 | 46 | 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 |
45 | 57 | echo '===================== Full profile =====================' |
46 | | - uvx gh-profiler==0.9.0 "$AUTHOR" |
| 58 | + uvx gh-profiler==0.9.0 "$AUTHOR" || true |
47 | 59 |
|
48 | 60 | # A yellow on the profile section alone means only that the account is |
49 | 61 | # newish or has empty bio fields, which is not worth a public comment. |
|
72 | 84 | } > comment.txt |
73 | 85 |
|
74 | 86 | 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