-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 진행 상황 알림 Discord 봇 구현 #454
base: develop
Are you sure you want to change the base?
Changes from 22 commits
b3b55d5
6f5dfa2
59c847a
a21219e
f3837a0
0587d3e
2049610
c8c25e7
6bc622c
a09dc4d
7f64084
518b9e4
fd2afe4
04ff3de
23cb080
b0e939d
92096f6
80be05c
e6daaca
260c02a
f9da269
d5e8881
ff9193e
9819649
aed8f35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: Webhook on Push | ||
|
||
on: | ||
schedule: | ||
- cron: "0 22 * * *" # 한국 시간 기준 아침 7시 실행 | ||
|
||
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(); | ||
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0); | ||
const startOfYesterday = new Date(startOfToday.getTime() - 24 * 60 * 60 * 1000); | ||
|
||
const commits = await github.rest.repos.listCommits({ | ||
owner, | ||
repo, | ||
sha: branch, | ||
since: startOfYesterday.toISOString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 질문 💭toISOString는 utc 기준이여서 한국 기준으로 계산되어야 할 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자정 시간을 잘못 계산했네요 ㅠ 한국 기준에 맞게 수정하였습니다! |
||
until: startOfToday.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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 질문 💭하루동안 한 작업량을 알림준다고 생각했는데 이러면 열려있는 PR의 커밋 중 오늘 날짜의 커밋만 가져오는 건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오전 7시에 전날 24시간 동안 작업된 commit들을 가져오는 방식입니다! |
||
|
||
const author = pr.user.login; | ||
const nickname = nicknames[author]; | ||
|
||
if (!nickname) continue; | ||
|
||
const prTitle = pr.title; | ||
const commitCount = commits.length; | ||
|
||
if (commitCount === 0) continue; | ||
|
||
if (commitSummary[nickname]) { | ||
commitSummary[nickname].push(`Issue: ${prTitle}: ${commitCount} commit`); | ||
} else { | ||
commitSummary[nickname] = [`Issue: ${prTitle}: ${commitCount} commit`]; | ||
} | ||
} | ||
|
||
const messageList = Object.keys(commitSummary).map(nickname => { | ||
const prSummaries = commitSummary[nickname].join('\n'); | ||
return `${nickname}\n${prSummaries}`; | ||
}); | ||
|
||
if (messageList.length === 0) { | ||
console.log('오늘의 커밋이 없습니다.'); | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 질문 💭
한국 기준으로 계산되는 건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
시간대 한국 기준으로 수정하였습니다. !