@@ -3,6 +3,11 @@ name: First contribution
33# Thanks someone the first time a PR of theirs is merged. On merge rather than on open:
44# at that point they've actually given something, so it reads as thanks instead of a pitch.
55#
6+ # Note on the check: author_association is NOT usable here. Merging a PR promotes its author
7+ # from FIRST_TIME_CONTRIBUTOR to CONTRIBUTOR, and the payload delivered with the `closed`
8+ # event already carries the new value — so a condition on it never matches. Counting the
9+ # author's merged PRs is the signal that survives that.
10+ #
611# pull_request_target is required to comment on a fork's PR — it runs with the base repo's
712# permissions. It therefore MUST NOT check out or execute the PR's code; this job only
813# posts a comment, and has no checkout step for that reason.
1116 types : [closed]
1217
1318permissions :
14- pull-requests : write
19+ pull-requests : read
20+ issues : write
1521
1622jobs :
1723 thanks :
18- if : >-
19- github.event.pull_request.merged == true &&
20- (github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' ||
21- github.event.pull_request.author_association == 'FIRST_TIMER')
24+ if : github.event.pull_request.merged == true && github.event.pull_request.user.type != 'Bot'
2225 runs-on : ubuntu-latest
2326 steps :
2427 - env :
2528 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
29+ REPO : ${{ github.repository }}
2630 PR : ${{ github.event.pull_request.number }}
2731 AUTHOR : ${{ github.event.pull_request.user.login }}
2832 run : |
29- gh api --method POST "repos/${{ github.repository }}/issues/$PR/comments" -F body=@- <<EOF
33+ set -euo pipefail
34+ merged=$(gh api --paginate "repos/$REPO/pulls?state=closed&per_page=100" \
35+ --jq ".[] | select(.user.login==\"$AUTHOR\" and .merged_at != null) | .number" | wc -l)
36+ echo "$AUTHOR has $merged merged PR(s) here."
37+ if [ "$merged" -ne 1 ]; then
38+ echo "Not their first — nothing to say."
39+ exit 0
40+ fi
41+ gh api --method POST "repos/$REPO/issues/$PR/comments" -F body=@- <<EOF
3042 Merged — thanks @$AUTHOR, that's your first one here.
3143
3244 If the project turned out to be useful to you, a ⭐ genuinely helps: stacktale is
3345 new, and stars are most of what decides whether anyone else finds it.
3446
35- Either way you're welcome back — the [\`good first issue\`](https://github.com/${{ github.repository }} /labels/good%20first%20issue)
47+ Either way you're welcome back — the [\`good first issue\`](https://github.com/$REPO /labels/good%20first%20issue)
3648 list is kept honest, and each one names the files to touch and how to verify.
3749 EOF
0 commit comments