Skip to content

Commit 97e087c

Browse files
authored
Merge pull request #67 from JS-Ninjaaaa/feature-add-pr-workflow
Feature add pr workflow
2 parents 5c697c2 + 91bbdf2 commit 97e087c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Notify Discord on PR Events
2+
3+
on:
4+
pull_request:
5+
types: [review_requested]
6+
issue_comment:
7+
types: [created]
8+
9+
jobs:
10+
notify_review_requested:
11+
if: github.event_name == 'pull_request' && github.event.action == 'review_requested'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install jq
15+
run: sudo apt-get update && sudo apt-get install -y jq
16+
17+
- name: Write user_map.json from Secret
18+
run: echo '${{ secrets.DISCORD_USER_MAP_JSON }}' > user_map.json
19+
20+
- name: Notify reviewer on PR review request
21+
env:
22+
REVIEWER: ${{ github.event.requested_reviewer.login }}
23+
PR_URL: ${{ github.event.pull_request.html_url }}
24+
PR_TITLE: ${{ github.event.pull_request.title }}
25+
WEBHOOK: ${{ secrets.DISCORD_PR_WEBHOOK }}
26+
run: |
27+
USER="$REVIEWER"
28+
DISCORD_ID=$(jq -r --arg user "$USER" '.[$user]' user_map.json)
29+
MENTION="@here"
30+
[ "$DISCORD_ID" != "null" ] && [ -n "$DISCORD_ID" ] && MENTION="<@$DISCORD_ID>"
31+
32+
cat <<EOF > message.json
33+
{
34+
"content": "$MENTION 👀レビューがリクエストされました: [$PR_TITLE]($PR_URL)"
35+
}
36+
EOF
37+
curl -H "Content-Type: application/json" -X POST -d @message.json "$WEBHOOK"
38+
39+
notify_comment:
40+
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Install jq
44+
run: sudo apt-get update && sudo apt-get install -y jq
45+
46+
- name: Write user_map.json from Secret
47+
run: echo '${{ secrets.DISCORD_USER_MAP_JSON }}' > user_map.json
48+
49+
- name: Notify PR author on comment
50+
env:
51+
AUTHOR: ${{ github.event.issue.user.login }}
52+
COMMENT_URL: ${{ github.event.comment.html_url }}
53+
WEBHOOK: ${{ secrets.DISCORD_PR_WEBHOOK }}
54+
run: |
55+
USER="$AUTHOR"
56+
DISCORD_ID=$(jq -r --arg user "$USER" '.[$user]' user_map.json)
57+
MENTION="@here"
58+
[ "$DISCORD_ID" != "null" ] && [ -n "$DISCORD_ID" ] && MENTION="<@$DISCORD_ID>"
59+
60+
cat <<EOF > message.json
61+
{
62+
"content": "$MENTION 💬コメントされました: $COMMENT_URL"
63+
}
64+
EOF
65+
curl -H "Content-Type: application/json" -X POST -d @message.json "$WEBHOOK"

0 commit comments

Comments
 (0)