-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (155 loc) · 6.14 KB
/
auto-reviewer.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Auto Reviewer
on:
pull_request:
branches:
- 'develop'
types: [ opened, reopened ]
jobs:
assign-reviewer:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Assign Reviewers
uses: kentaro-m/[email protected]
with:
configuration-path: '.github/reviewer.yml'
- name: Get PR Labels
run: echo "PR_LABELS=${{ github.event.pull_request.labels[0].name }}" >> $GITHUB_ENV
- name: Get PR URL
run: echo "PR_URL=${{ github.event.pull_request.html_url }}" >> $GITHUB_ENV
- name: Get PR Author
run: echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- name: Get Assigned Reviewer
id: assigned_reviewers_id
uses: actions/github-script@v6
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const reviewers = pullRequest.requested_reviewers.map(reviewer => reviewer.login).join(',');
core.setOutput('reviewers', reviewers)
# highest: until 24hours
# high: until 48hours
# medium: until 72hours
# low: until 120hours
# lowest: until 168hours
- name: Calculate Review Due Date
id: calculate_due_date_id
uses: actions/github-script@v6
with:
script: |
const createdAt = new Date(process.env.CREATED_AT);
const label = process.env.PR_LABELS;
const hour_abs = 60 * 60 * 1000;
let dueDate;
if (label.includes("highest")) {
dueDate = new Date(createdAt.getTime() + (24 * hour_abs));
} else if (label.includes("high")) {
dueDate = new Date(createdAt.getTime() + (48 * hour_abs));
} else if (label.includes("medium")) {
dueDate = new Date(createdAt.getTime() + (72 * hour_abs));
} else if (label.includes("low")) {
dueDate = new Date(createdAt.getTime() + (120 * hour_abs));
} else if (label.includes("lowest")) {
dueDate = new Date(createdAt.getTime() + (168 * hour_abs));
} else {
core.setFailed(`Not Matched Labels.`);
}
const year = dueDate.getFullYear();
const month = dueDate.getMonth() + 1;
const day = dueDate.getDate();
const hours = dueDate.getHours();
const period = hours >= 12 ? '오후' : '오전';
const formattedHour = hours % 12 || 12;
const formattedTime = `${year}년 ${month}월 ${day}일 ${period} ${formattedHour}시`;
core.setOutput('due_date', formattedTime);
env:
PR_LABELS: ${{ env.PR_LABELS }}
CREATED_AT: ${{ github.event.pull_request.created_at }}
- name: Get Slack Member ID
id: slack_id
uses: actions/github-script@v6
with:
script: |
const reviewer = process.env.PR_REVIEWER
let selectedId;
if (reviewer === "Heonbyeong") {
selectedId = process.env.SLACK_ID_ABH;
} else if (reviewer === "jhg3410") {
selectedId = process.env.SLACK_ID_JHG;
} else if (reviewer === "eunseo0105") {
selectedId = process.env.SLACK_ID_KES;
} else {
core.setFailed(`Not Found Author.`);
}
core.setOutput('selected_id', selectedId);
env:
PR_REVIEWER: ${{ steps.assigned_reviewers_id.outputs.reviewers }}
SLACK_ID_ABH: ${{ secrets.SLACK_ID_ABH }}
SLACK_ID_JHG: ${{ secrets.SLACK_ID_JHG }}
SLACK_ID_KES: ${{ secrets.SLACK_ID_KES }}
- name: Save Slack Member ID to Github ENV
run: echo "SLACK_MEMBER_ID=${{ steps.slack_id.outputs.selected_id }}" >> $GITHUB_ENV
- name: Send custom JSON data to Slack workflow
id: slack
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_CHANNEL_ID }}
payload: |
{
"text": "새로운 PR이 등록되었습니다! 👾\n마감일 전까지 늦지 않게 리뷰를 완료하고, 해당 스레드에 공유해주세요!",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "새로운 PR이 등록되었습니다! 👾",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "마감일 전까지 늦지 않게 리뷰를 완료하고, 해당 스레드에 공유해주세요!\n<${{ env.PR_URL }}>"
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*PR Author*\n${{ env.PR_AUTHOR }}"
},
{
"type": "mrkdwn",
"text": "*Reviewer*\n<@${{ env.SLACK_MEMBER_ID }}>"
}
]
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Priority*\n${{ env.PR_LABELS }}"
},
{
"type": "mrkdwn",
"text": "*Due Date*\n${{ env.DUE_DATE }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_PR_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_ANDROID_CHANNEL_ID }}
DUE_DATE: ${{ steps.calculate_due_date_id.outputs.due_date }}