Skip to content

Fix#397 페이지 리뉴얼을 위한 모달창 추가 #898

Fix#397 페이지 리뉴얼을 위한 모달창 추가

Fix#397 페이지 리뉴얼을 위한 모달창 추가 #898

name: Notify Discord Webhook
on:
issue_comment:
types: [created]
pull_request:
types: [opened, reopened, closed]
pull_request_review_comment:
types: [created]
jobs:
notify-with-js:
runs-on: ubuntu-latest
steps:
- name: Send Notification using JavaScript
uses: actions/github-script@v7
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
with:
script: |
const { eventName, payload } = context;
const webhookUrl = process.env.DISCORD_WEBHOOK;
let embed;
if (eventName === 'pull_request') {
const pr = payload.pull_request;
let color, statusMessage;
if (pr.merged) {
color = 15158332;
statusMessage = "Pull Request가 머지되었습니다.";
} else if (payload.action === 'closed') {
color = 15105570;
statusMessage = "Pull Request가 병합 없이 닫혔습니다.";
} else {
color = 3447003;
statusMessage = "새로운 Pull Request가 열렸습니다.";
}
embed = {
title: `[${context.repo.repo}] PR #${pr.number}: ${pr.title}`,
description: statusMessage,
url: pr.html_url,
color: color,
author: {
name: pr.user.login,
icon_url: pr.user.avatar_url
}
};
} else if (eventName === 'issue_comment') {
const comment = payload.comment;
const body = comment.body.length > 1000 ? comment.body.substring(0, 1000) + '...' : comment.body;
embed = {
title: `[${context.repo.repo}] 새로운 댓글`,
description: body,
url: comment.html_url,
color: 15844367, // 회색
author: {
name: comment.user.login,
icon_url: comment.user.avatar_url
}
};
} else if (eventName === 'pull_request_review_comment') {
const comment = payload.comment;
const pr = payload.pull_request;
const body = comment.body.length > 1000 ? comment.body.substring(0, 1000) + '...' : comment.body;
embed = {
title: `[${context.repo.repo}] PR #${pr.number}에 새로운 리뷰 댓글`,
description: body,
url: comment.html_url,
color: 15844367, // 회색 또는 원하는 다른 색상
author: {
name: comment.user.login,
icon_url: comment.user.avatar_url
}
};
}
if (!embed) {
console.log('처리할 이벤트가 없습니다.');
return;
}
const discordPayload = {
embeds: [embed]
};
const response = await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(discordPayload)
});
if (!response.ok) {
console.error(`Error sending to Discord: ${response.status} ${response.statusText}`);
const responseBody = await response.text();
console.error(`Response body: ${responseBody}`);
core.setFailed(`디스코드 알림 전송 실패: ${response.status}`);
} else {
console.log('디스코드 알림 전송 성공');
}