generated from snow-actions/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
135 lines (133 loc) · 4.53 KB
/
action.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: 'GitHub Discussions Notifier'
description: 'Notify GitHub Discussion & Comment to Slack'
branding:
icon: 'at-sign'
color: 'orange'
inputs:
SLACK_CHANNEL_ID:
description: 'Slack Channel Id'
required: true
SLACK_BOT_TOKEN:
description: 'Slack Bot Token'
required: true
send-discussion-create:
description: 'send discussion create notification?'
required: false
default: true
send-discussion-comment:
description: 'send discussion comment notification?'
required: false
default: true
unfurl-links:
description: 'Pass true to enable unfurling of primarily text-based content.'
required: false
default: false
unfurl-media:
description: 'Pass false to disable unfurling of media content.'
required: false
default: false
runs:
using: "composite"
steps:
- name: Send GitHub Discussion Notification to Slack
if: ${{ github.event.discussion && !github.event.comment && inputs.send-discussion-create }}
# Note:
# - 一度変数に入れることで、$や`をエスケープしている
# - https://stackoverflow.com/questions/69982822/is-there-a-way-to-escape-and-single-quotes-together-in-bash
# - printfしないといい感じに"\n"が変換されない
run: |
title=$(
cat <<"EOF"
${{ env.DISCUSSION_TITLE }}
EOF
)
body=$(
cat <<"EOF"
${{ env.DISCUSSION_BODY }}
EOF
)
printf -v markdown_message_unescaped %b "<${{ env.DISCUSSION_URL }}|*$title*>\n$body"
jq -n -r --arg text "$markdown_message_unescaped" '{
"token":"${{ inputs.SLACK_BOT_TOKEN }}",
"channel":"${{ inputs.SLACK_CHANNEL_ID }}",
"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"New Discussion by <${{ env.USER_URL }}|${{ env.USER_NAME }}>"
}
}
],
"attachments":[
{
"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":$text
}
}
]
}
],
"unfurl_links": ${{ inputs.unfurl-links }},
"unfurl_media": ${{ inputs.unfurl-media }}
}
'|curl -X POST -H 'Authorization: Bearer ${{ inputs.SLACK_BOT_TOKEN }}' -H "Content-Type: application/json" -d @- https://slack.com/api/chat.postMessage
shell: bash
env:
DISCUSSION_URL: ${{ github.event.discussion.html_url }}
DISCUSSION_TITLE: ${{ github.event.discussion.title }}
DISCUSSION_BODY: ${{ github.event.discussion.body }}
USER_URL: ${{ github.event.discussion.user.html_url }}
USER_NAME: ${{ github.event.discussion.user.login }}
- name: Send GitHub Discussions Comment Notification to Slack
if: ${{ github.event.comment && inputs.send-discussion-comment }}
run: |
title=$(cat << "EOF"
${{ env.DISCUSSION_TITLE }}
EOF
)
body=$(cat << "EOF"
${{ env.COMMENT_BODY }}
EOF
)
printf -v markdown_message_unescaped %b "*<${{ env.COMMENT_URL }}|Comment on $title>*\n$body"
jq -n -r --arg text "$markdown_message_unescaped" '{
"token":"${{ inputs.SLACK_BOT_TOKEN }}",
"channel":"${{ inputs.SLACK_CHANNEL_ID }}",
"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":"New comment by <${{ env.USER_URL }}|${{ env.USER_NAME }}>"
}
}
],
"attachments":[
{
"blocks":[
{
"type":"section",
"text":{
"type":"mrkdwn",
"text":$text
}
}
]
}
],
"unfurl_links": ${{ inputs.unfurl-links }},
"unfurl_media": ${{ inputs.unfurl-media }}
}
'|curl -X POST -H 'Authorization: Bearer ${{ inputs.SLACK_BOT_TOKEN }}' -H "Content-Type: application/json" -d @- https://slack.com/api/chat.postMessage
shell: bash
env:
DISCUSSION_TITLE: ${{ github.event.discussion.title }}
COMMENT_URL: ${{ github.event.comment.html_url }}
COMMENT_BODY: ${{ github.event.comment.body }}
USER_URL: ${{ github.event.comment.user.html_url }}
USER_NAME: ${{ github.event.comment.user.login }}