Skip to content
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

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b3b55d5
feat: progress_alram.yml 추가 #443
novice0840 Dec 30, 2024
6f5dfa2
feat: test commit #443
novice0840 Dec 30, 2024
59c847a
refactor: commit test #443
novice0840 Dec 30, 2024
a21219e
refactor: github actions 스크립트 파일명 변경 #443
novice0840 Dec 30, 2024
f3837a0
refactor: branch 이름 변경 #443
novice0840 Dec 30, 2024
0587d3e
refactor: actions/checkout 사용 #443
novice0840 Dec 30, 2024
2049610
refactor: github-scripts 변경 #443
novice0840 Dec 30, 2024
c8c25e7
refactor: commit.data 콘솔 출력 #443
novice0840 Dec 30, 2024
6bc622c
refactor: owner, repo 로그 출력 #443
novice0840 Dec 30, 2024
a09dc4d
refactor: test commit #443
novice0840 Dec 31, 2024
7f64084
feat: test commit #443
novice0840 Dec 31, 2024
518b9e4
refactor: commit list 가져오는 방식 변경 #443
novice0840 Dec 31, 2024
fd2afe4
refactor: 메시지 출력 형식 변경 #443
novice0840 Dec 31, 2024
04ff3de
refactor: 출력 형식 변경 #443
novice0840 Dec 31, 2024
23cb080
refactor: commit 갯수가 0개인 경우 제외 #443
novice0840 Dec 31, 2024
b0e939d
refactor: 메세지 출력 시 오늘 날짜 포함 #443
novice0840 Dec 31, 2024
92096f6
refactor: 메세지에 Issue 문자열 추가 #443
novice0840 Dec 31, 2024
80be05c
refactor: cron 스케줄러로 변경 #443
novice0840 Dec 31, 2024
e6daaca
refactor: webhook test #443
novice0840 Dec 31, 2024
260c02a
refactor: test 용 코드 제거 #443
novice0840 Dec 31, 2024
f9da269
fix: 불필요한 공백 제거 #443
novice0840 Dec 31, 2024
d5e8881
refactor: 알람 시간대 변경 #443
novice0840 Dec 31, 2024
ff9193e
feat: progress-alarm 스크립트 수동 실행 기능 추가 #443
novice0840 Jan 1, 2025
9819649
refactor: progress alram name 변경 #443
novice0840 Jan 1, 2025
aed8f35
fix: 자정 시간 한국기준으로 변경 #443
novice0840 Jan 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/progress-alarm.yml
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 질문 💭

한국 기준으로 계산되는 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간대 한국 기준으로 수정하였습니다. !

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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 질문 💭

toISOString는 utc 기준이여서 한국 기준으로 계산되어야 할 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 질문 💭

하루동안 한 작업량을 알림준다고 생각했는데 이러면 열려있는 PR의 커밋 중 오늘 날짜의 커밋만 가져오는 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}