Files
Northbound/git-hooks/send-discord.js
dal4segno 4e852b9da6 깃 디스코드 연동
nodejs 설치 필요. 가이드 참조
2026-02-01 13:47:35 +09:00

58 lines
1.6 KiB
JavaScript

const fs = require('fs');
const https = require('https');
const { execSync } = require('child_process');
process.env.LANG = 'en_US.UTF-8';
process.env.LC_ALL = 'en_US.UTF-8';
process.env.GIT_PAGER = '';
const webhookUrl = 'https://discordapp.com/api/webhooks/1467361257693642918/6KByhX070Cw1Y5-fHjOgxI-AtXfFyxZKMIv0QeGts8bR9Z6YzQHmsmHKvoLCOxj-SmwX';
const shortHash = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).toString().trim();
const commitAuthor = execSync('git show -s --format=%an HEAD', { encoding: 'utf8' }).toString().trim();
const commitMessage = execSync('git log -1 --pretty=%B', { encoding: 'utf8' }).toString().trim();
const repoName = 'Northbound';
const embed = {
title: `New Commit: ${repoName}`,
color: 5814783,
description: commitMessage,
fields: [
{ name: 'Commit', value: shortHash, inline: true },
{ name: 'Author', value: commitAuthor, inline: true },
{ name: 'Changed Files', value: 'No files', inline: false }
]
};
const data = JSON.stringify({ embeds: [embed] });
const url = new URL(webhookUrl);
const options = {
hostname: url.hostname,
path: url.pathname + url.search,
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': Buffer.byteLength(data, 'utf8')
}
};
const req = https.request(options, (res) => {
console.log('OK');
process.exit(0);
});
req.on('error', (e) => {
console.error(`Error: ${e.message}`);
process.exit(0);
});
req.setTimeout(10000, () => {
console.log('Timeout');
process.exit(0);
});
req.write(data, 'utf8');
req.end();