-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
84 lines (77 loc) · 3.79 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
name: 'Slack Review Request Notify'
description: 'Send actions notification to Idobata'
inputs:
channel-id: # channel of input
description: 'Slack Channel ID to post message'
required: true
default: ''
SLACK_BOT_TOKEN: # channel of input
description: 'Slack token to post message'
required: true
default: ''
runs:
using: "composite"
steps:
- name: 👤 Fix different username between GitHub <-> Slack
shell: bash
run: |
requestor=${{ github.triggering_actor }}
requestee=${{ github.event.requested_reviewer.login || 'yasulab' }}
# MEMO: 'requestee' can be null when triggered by workflow dispatch.
echo "REQUESTOR=$requestor" | \
sed -e "s/rakuda-san-desu/rakuda/" | \
sed -e "s/Yuppymam/yuppy/" | \
sed -e "s/dependabot\[bot\]/dependabot/" >> $GITHUB_ENV
echo "REQUESTEE=$requestee" | \
sed -e "s/rakuda-san-desu/rakuda/" | \
sed -e "s/Yuppymam/yuppy/" | \
sed -e "s/dependabot\[bot\]/dependabot/" >> $GITHUB_ENV
- name: ⏰ Set timezone and check if business days
env:
TZ: 'Asia/Tokyo' # タイムゾーン指定
shell: bash
run: |
# 祝日ではなく、営業時間内(平日の10時〜18時)であれば即日通知
current_time=$(date +'%H'); echo "CURRENT_TIME: $current_time"
current_week=$(date +'%w'); echo "CURRENT_TIME: $current_week"
is_holiday=$(
ruby -r open-uri -e 'holidays = URI.open("https://yasslab.jp/holidays.json").read' \
-r json -r date -e "puts JSON.parse(holidays).to_a.include? Date.today.to_s"
)
# 祝日であれば業務時間外
if [[ "$is_holiday" == "true" ]] ; then
echo "Current status: Japanese holidays"
echo "IS_BUSINESS_TIME=false" >> $GITHUB_ENV
# 平日の業務時間内かどうかの判定(月曜 = 1、金曜 = 5)
elif [ "$current_time" -ge "10" ] && [ "$current_time" -lt "18" ] && \
[ "$current_week" -ge "1" ] && [ "$current_week" -le "5" ] ; then
echo "Current status: Business hours"
echo "IS_BUSINESS_TIME=true" >> $GITHUB_ENV
# 上記以外であれば業務時間外(早朝/深夜など)
else
echo "Current status: Not business hours"
echo "IS_BUSINESS_TIME=false" >> $GITHUB_ENV
fi
- name: 📝 Compose prefix message to mention in Slack
shell: bash
run: |
# 営業時間内なら即時通知、時間外なら翌営業日に通知
if [ "${{ env.IS_BUSINESS_TIME }}" = "true" ]; then
mention="<@${{ env.REQUESTEE }}>"
else
mention="<@tasslab> memo ${{ env.REQUESTEE }}"
fi
echo "SLACK_POST_MENTION=$mention" >> $GITHUB_ENV
echo "ACTIONS_URL=https://github.com/${{ github.repository }}/actions" >> $GITHUB_ENV
# The ACTIONS_URL can be reffered when triggered by workflow dispatch.
- name: 🔔 Review Request Notify
uses: slackapi/[email protected]
# cf. https://github.com/slackapi/slack-github-action
id: slack
env:
SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }}
with:
channel-id: ${{ inputs.channel-id }}
slack-message: |
${{ env.SLACK_POST_MENTION }} :${{ env.REQUESTOR }}: ${{ env.REQUESTOR }} さんからレビュー依頼が来てるよ (◍˃̶ᗜ˂̶◍)ノ
> :github: <${{ github.event.pull_request.html_url || github.event.head_commit.url || env.ACTIONS_URL }}|`${{ github.repository }}#${{ github.event.number || 'workflow_dispatch' }}`> - *<${{ github.event.pull_request.html_url || github.event.head_commit.url || env.ACTIONS_URL }}|${{ github.event.pull_request.title || 'workflow_dispatch' }}>*