Skip to content

test: discord alram 테스트 #443 #15

test: discord alram 테스트 #443

test: discord alram 테스트 #443 #15

Workflow file for this run

name: Progress Alarm for Discord
on:
push: # Trigger the workflow on every push
branches:
- "**" # Matches all branches
schedule:
- cron: "0 22 * * *" # 한국 시간 기준 아침 7시 실행
workflow_dispatch: # Allows manual triggering
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('오늘의 커밋이 없습니다.');
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;
}