-
Notifications
You must be signed in to change notification settings - Fork 16
40 lines (40 loc) · 1.92 KB
/
thank-contributor.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: 'Thank contributor for contribution'
on:
pull_request:
types:
- closed
jobs:
Congratulate:
if: github.event.pull_request.merged == true &&
github.event.pull_request.user.login != 'dependabot[bot]'
runs-on: ubuntu-latest
steps:
- name: Sleep for 120 seconds
run: sleep 120s
shell: bash
- name: Thank contributor for contribution
env:
ISSUES_BOT_TOKEN: ${{ secrets.ISSUES_BOT_TOKEN }}
run: |
username="${{ github.event.pull_request.user.login }}"
repo="${{ github.repository }}"
if [[ "$username" =~ [[:punct:]] ]]; then
message="Hi @$username. :wave:\n\nYour PR has been approved and merged. :tada:\n\nThank you for your contribution to starter.dev. :heart:\n\nKeep up the great work!"
else
response=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer $ISSUES_BOT_TOKEN" "https://api.github.com/repos/$repo/collaborators/$username")
if [ "$response" = "204" ]; then
message="Hi @$username. :wave:\n\nYour PR has been approved and merged. :tada:\n\nThank you for your continued contributions to starter.dev. :heart:\n\nKeep up the great work!"
elif [ "$response" = "404" ]; then
message="Hi @$username. :wave:\n\nCongrats on your first PR being approved and merged! :tada:\n\nThank you for taking the time to contribute to starter.dev. :heart:\n\nWe look forward to your next contribution. :rocket:"
else
echo "Invalid or expired token: $ISSUES_BOT_TOKEN"
exit 1
fi
fi
curl -X POST \
-H "Authorization: Bearer $ISSUES_BOT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"body": "'"$message"'"
}' \
"https://api.github.com/repos/$repo/issues/${{ github.event.pull_request.number }}/comments"