-
Notifications
You must be signed in to change notification settings - Fork 2
89 lines (84 loc) · 2.66 KB
/
gh_discussion_comment_to_slack.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# ## Summary
#
# Github Discussionのコメントが投稿された際に、内容をSlackに送信します。
# ## Background
#
# 現在GitHubのSlack連携ではコメント通知をサポートしていません。
#
# Get notifications for comment/reply of Discussions in slack (or equivalent)
# https://github.com/orgs/community/discussions/56821
# ## Usage
#
# name: Post GitHub Discussion comment to Slack
#
# on:
# discussion_comment:
# types: [created]
#
# jobs:
# discussion_commented:
# if: github.event.discussion && github.event.comment
# uses: route06/actions/.github/workflows/gh_discussion_comment_to_slack.yml@v2
# secrets:
# slack-webhook-url: ${{ secrets.SLACK_XXX_WEBHOOK_URL }} # Set this secret
name: Post GitHub Discussion comment to Slack
on:
workflow_call:
secrets:
slack-webhook-url:
required: true
jobs:
gh-discussion-comment-to-slack:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# Note:
# - 一度変数に入れることで、$や`をエスケープしている
# - printfしないといい感じに"\n"が変換されない
# - ref: https://times.hrbrain.co.jp/entry/2021/11/16/github-discussions-noti
- name: Post to Slack
env:
COMMENT_BODY: ${{ github.event.comment.body }}
DISCUSSION_TITLE: ${{ github.event.discussion.title }}
run: |
set -o pipefail
body=$(
cat <<"EOF"
${{ env.COMMENT_BODY }}
EOF
)
printf -v markdown_message_escaped %b "$body"
jq -n \
--arg pretext "New discussion comment by <${{ github.event.comment.user.html_url }}|${{ github.event.comment.user.login }}>" \
--arg title "*<${{ github.event.comment.html_url }}|Comment on #${{ toJSON(github.event.discussion.number) }} ${{ env.DISCUSSION_TITLE }}>*" \
--arg text "$markdown_message_escaped" '
{
"attachments": [
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": $pretext
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": $title
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": $text
}
}
]
}
]
}
' | curl -X POST ${{ secrets.slack-webhook-url }} -d @-