Feature#388 실시간 순위 발표 및 공유 안내 추가 #889
Workflow file for this run
This file contains hidden or 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
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('디스코드 알림 전송 성공'); | |
} |