-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
112 lines (99 loc) · 4.65 KB
/
Copy pathaction.yml
File metadata and controls
112 lines (99 loc) · 4.65 KB
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
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.
# Fetch username mapping from members.json API
members_json=$(curl -s https://yasslab.jp/members.json || echo "[]")
# Function to map GitHub username to Slack username
map_username() {
local github_username=$1
local slack_username=""
# Special handling for bots
if [[ "$github_username" == "dependabot[bot]" ]]; then
echo "dependabot"
return
fi
# Try to find mapping in members.json
slack_username=$(echo "$members_json" | ruby -r json -e "
members = JSON.parse(STDIN.read)
member = members.find { |m| m['username_github'] == '$github_username' }
puts member['username_slack'] if member
")
# If mapping found, use it; otherwise use GitHub username as fallback
if [[ -n "$slack_username" ]]; then
echo "$slack_username"
else
echo "$github_username"
fi
}
# Map usernames
REQUESTOR=$(map_username "$requestor")
REQUESTEE=$(map_username "$requestee")
# Export to environment
echo "REQUESTOR=$REQUESTOR" >> $GITHUB_ENV
echo "REQUESTEE=$REQUESTEE" >> $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/slack-github-action@v1.23.0
# 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' }}>*