-
Notifications
You must be signed in to change notification settings - Fork 2
114 lines (94 loc) · 3.9 KB
/
progress-alarm.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
name: Progress Alarm for Discord
on:
schedule:
- cron: "0 22 * * *" # 한국 시간 기준 아침 7시 실행
workflow_dispatch:
jobs:
review-reminder:
runs-on: ubuntu-latest
steps:
- name: Send Reminder to Discord
uses: actions/github-script@v7
env:
DISCORD_WEBHOOK: ${{ secrets.PROGRESS_ALARM_DISCORD_WEBHOOK_URL }}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const commitSummary = {};
const nicknames = {
"rbgksqkr": "마루",
"useon": "썬데이",
"PgmJun": "이든",
"novice0840": "포메",
"GIVEN53": "프린",
"leegwichan": "커찬",
"jhon3242": "타칸"
};
async function getCommits(owner, repo, branch) {
try {
const now = new Date();
// 오전 7시에 작업이 시작되므로 7시간 전이 전날 밤 12시가 된다
const until = new Date(now.getTime() - 7 * 60 * 60 * 1000);
// until로부터 24시간 전이 전날 자정이 된다
const since = new Date(until.getTime() - 24 * 60 * 60 * 1000);
const commits = await github.rest.repos.listCommits({
owner,
repo,
sha: branch,
since: since.toISOString(),
until: until.toISOString()
});
return commits.data;
} catch (error) {
console.error(`Error fetching commits for branch ${branch}:`, error.message);
return [];
}
}
try {
const pullRequests = await github.rest.pulls.list({
owner,
repo,
state: 'open',
});
for (const pr of pullRequests.data) {
const branch = pr.head.ref;
const commits = await getCommits(owner, repo, branch);
const author = pr.user.login;
const nickname = nicknames[author];
if (!nickname) continue;
const prTitle = pr.title;
const prUrl = pr.html_url;
const commitCount = commits.length;
if (commitCount === 0) continue;
if (commitSummary[nickname]) {
commitSummary[nickname].push(`Issue: [${prTitle}](${prUrl}): ${commitCount} commit(s)`);
} else {
commitSummary[nickname] = [`Issue: [${prTitle}](${prUrl}): ${commitCount} commit(s)`];
}
}
const messageList = Object.keys(commitSummary).map(nickname => {
const prSummaries = commitSummary[nickname].join('\n');
return `${nickname}\n${prSummaries}`;
});
if (messageList.length === 0) {
console.log(`🍀 오늘은 commit이 없습니다 🍀)
return;
}
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1;
const day = today.getDate();
const formattedDate = `${year}년 ${month}월 ${day}일`;
const response = await fetch(process.env.DISCORD_WEBHOOK, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
content: `🍀 ${formattedDate} 진행 상황 공유 🍀\n\n${messageList.join('\n\n')}`,
}),
});
console.log('Response status:', response.status);
} catch (error) {
console.error('Error fetching pull requests:', error.message);
throw error;
}