Skip to content

Commit d710363

Browse files
committed
Profile contributors
1 parent ce4147b commit d710363

2 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Run gh-profiler against the author of each new issue.
2+
# Delete the profile output when the issue is closed.
3+
# PR authors are profiled by the unprivileged profile-pr-authors.yml instead,
4+
# so no dangerous trigger is needed for PRs from forks.
5+
6+
name: Profile issue authors
7+
8+
on:
9+
issues:
10+
types: [opened, closed]
11+
12+
jobs:
13+
profile-author:
14+
if: github.event.action == 'opened'
15+
16+
permissions:
17+
issues: write
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
23+
with:
24+
enable-cache: false
25+
ignore-empty-workdir: true
26+
27+
- name: Run gh-profiler (=== Expand this to see full profile output ===)
28+
env:
29+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
LOGIN: ${{ github.event.issue.user.login }}
31+
run: |
32+
uvx gh-profiler@latest "$LOGIN" --concise > profiler.txt
33+
echo
34+
echo "======================== Full profile ========================="
35+
echo
36+
uvx gh-profiler@latest "$LOGIN"
37+
echo
38+
echo "==============================================================="
39+
40+
- name: Comment on issue
41+
env:
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
SERVER_URL: ${{ github.server_url }}
44+
REPOSITORY: ${{ github.repository }}
45+
RUN_ID: ${{ github.run_id }}
46+
CHECK_RUN_ID: ${{ job.check_run_id }}
47+
NUMBER: ${{ github.event.issue.number }}
48+
run: |
49+
{
50+
echo "<!-- gh-profiler:profile-link run-id=$RUN_ID -->"
51+
echo "Profile summary:"
52+
echo
53+
echo '```text'
54+
cat profiler.txt
55+
echo '```'
56+
echo
57+
echo "<a href=\"$SERVER_URL/$REPOSITORY/actions/runs/$RUN_ID/job/$CHECK_RUN_ID\">Full profile</a>"
58+
echo
59+
echo "(This comment and the linked profile output will auto-delete when this issue is closed.)"
60+
} > body.txt
61+
62+
jq -Rs '{body: .}' body.txt > payload.json
63+
64+
gh api \
65+
"repos/$REPOSITORY/issues/$NUMBER/comments" \
66+
--input payload.json
67+
68+
delete-profile:
69+
if: github.event.action == 'closed'
70+
71+
permissions:
72+
actions: write
73+
issues: write
74+
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
- name: Delete profile comment
79+
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
REPOSITORY: ${{ github.repository }}
82+
NUMBER: ${{ github.event.issue.number }}
83+
run: |
84+
gh api --paginate \
85+
"repos/$REPOSITORY/issues/$NUMBER/comments" \
86+
--jq '
87+
.[]
88+
| select(.user.login == "github-actions[bot]")
89+
| select(.body | startswith("<!-- gh-profiler:profile-link run-id="))
90+
| [.id, (.body | capture("gh-profiler:profile-link run-id=(?<id>[0-9]+)").id)]
91+
| @tsv
92+
' |
93+
while IFS=$'\t' read -r comment_id run_id; do
94+
echo "Deleting logs from workflow run $run_id."
95+
gh api --method DELETE \
96+
"repos/$REPOSITORY/actions/runs/$run_id/logs"
97+
98+
echo "Deleting profile comment $comment_id."
99+
gh api --method DELETE \
100+
"repos/$REPOSITORY/issues/comments/$comment_id"
101+
done
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Run gh-profiler against the author of each new PR and show the output in
2+
# the job log and step summary, reachable via the PR's checks.
3+
#
4+
# This runs unprivileged (read-only token, safe for PRs from forks), so it
5+
# cannot post a comment like profile-issue-authors.yml does for issues.
6+
# There is also nothing to delete when the PR is closed: the output expires
7+
# with the run logs.
8+
9+
name: Profile PR authors
10+
11+
on:
12+
pull_request:
13+
types: [opened]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
profile-author:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
24+
with:
25+
enable-cache: false
26+
ignore-empty-workdir: true
27+
28+
- name: Run gh-profiler (=== Expand this to see full profile output ===)
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
LOGIN: ${{ github.event.pull_request.user.login }}
32+
run: |
33+
uvx gh-profiler@latest "$LOGIN" > profiler.txt
34+
cat profiler.txt
35+
{
36+
echo '```text'
37+
cat profiler.txt
38+
echo '```'
39+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)