-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (98 loc) · 3.96 KB
/
dn-rule.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
name: PR Label Automation
on:
schedule:
- cron: '0 10 * * *'
jobs:
update-labels:
runs-on: ubuntu-latest
steps:
- name: Check and Update PR Labels
uses: actions/github-script@v5
with:
script: |
const repo = context.repo;
// Fetch all open PRs
const prs = await github.rest.pulls.list({
owner: repo.owner,
repo: repo.repo,
state: 'open',
});
// Define the Discord webhook URL
const webhookUrl = 'https://discord.com/api/webhooks/1273159249672802304/vU5b6gC9bAHzyLXzWRzV7YqjIVCtO5_gLJ1URonjnbqn45Xa5kixYT1vMWxwLXqFi2y3';
for (const pr of prs.data) {
const prNumber = pr.number;
let labels = pr.labels.map(label => label.name);
// Function to update label
async function updateLabel(oldLabel, newLabel) {
if (oldLabel) {
await github.rest.issues.removeLabel({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
name: oldLabel,
});
}
await github.rest.issues.addLabels({
owner: repo.owner,
repo: repo.repo,
issue_number: prNumber,
labels: [newLabel],
});
}
// Check and update 'D-x' labels
let dLabel = labels.find(label => label.startsWith("D-"));
if (dLabel) {
let day = parseInt(dLabel.split("-")[1]);
if (day > 0) {
const newDayLabel = `D-${day - 1}`;
await updateLabel(dLabel, newDayLabel);
console.log(`Updated label from ${dLabel} to ${newDayLabel} on PR #${prNumber}`);
// Send a notification to Discord
await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'PR Bot',
avatar_url: 'https://avatars.githubusercontent.com/u/9919?s=200&v=4',
embeds: [
{
title: `📢 **PR #${prNumber} - ${pr.title} Review D-${day - 1}** 📢`,
description: `리뷰를 작성해주세요! 리뷰 작성 기간이 ${day - 1}일 남았습니다.`,
url: pr.html_url,
color: 4620980,
footer: {
text: `D-day가 업데이트 되었습니다. ${dLabel} → ${newDayLabel}`
}
}
]
})
});
} else if (day === 0) {
await fetch(webhookUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'PR Bot',
avatar_url: 'https://avatars.githubusercontent.com/u/9919?s=200&v=4',
embeds: [
{
title: `❗ **PR #${prNumber} - ${pr.title} Review D-0** ❗`,
description: `리뷰 마감일이 지났습니다! 리뷰를 작성해주세요.`,
url: pr.html_url,
color: 4620980,
footer: {
text: `D-day 상태: D-0`
}
}
]
})
});
}
} else {
await updateLabel(null, 'D-3');
}
}