-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
b3b55d5
feat: progress_alram.yml 추가 #443
novice0840 6f5dfa2
feat: test commit #443
novice0840 59c847a
refactor: commit test #443
novice0840 a21219e
refactor: github actions 스크립트 파일명 변경 #443
novice0840 f3837a0
refactor: branch 이름 변경 #443
novice0840 0587d3e
refactor: actions/checkout 사용 #443
novice0840 2049610
refactor: github-scripts 변경 #443
novice0840 c8c25e7
refactor: commit.data 콘솔 출력 #443
novice0840 6bc622c
refactor: owner, repo 로그 출력 #443
novice0840 a09dc4d
refactor: test commit #443
novice0840 7f64084
feat: test commit #443
novice0840 518b9e4
refactor: commit list 가져오는 방식 변경 #443
novice0840 fd2afe4
refactor: 메시지 출력 형식 변경 #443
novice0840 04ff3de
refactor: 출력 형식 변경 #443
novice0840 23cb080
refactor: commit 갯수가 0개인 경우 제외 #443
novice0840 b0e939d
refactor: 메세지 출력 시 오늘 날짜 포함 #443
novice0840 92096f6
refactor: 메세지에 Issue 문자열 추가 #443
novice0840 80be05c
refactor: cron 스케줄러로 변경 #443
novice0840 e6daaca
refactor: webhook test #443
novice0840 260c02a
refactor: test 용 코드 제거 #443
novice0840 f9da269
fix: 불필요한 공백 제거 #443
novice0840 d5e8881
refactor: 알람 시간대 변경 #443
novice0840 ff9193e
feat: progress-alarm 스크립트 수동 실행 기능 추가 #443
novice0840 9819649
refactor: progress alram name 변경 #443
novice0840 aed8f35
fix: 자정 시간 한국기준으로 변경 #443
novice0840 02d829b
test: discord alram 테스트 #443
novice0840 03b0672
fix: branch 명 오류 수정 #443
novice0840 61aa429
fix: branch 명 전체브랜치에서 개별 브랜치로 수정 #443
novice0840 5053a06
test: discord hook 테스트 #443
novice0840 457405c
refactor: 메세지 변경 #443
novice0840 96d22d9
refactor: commit 0개인 경우 메세지 전송 취소 #443
novice0840 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
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 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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
시간대 한국 기준으로 수정하였습니다. !