깃 디스코드 연동
nodejs 설치 필요. 가이드 참조
This commit is contained in:
3
git-hooks/post-commit
Normal file
3
git-hooks/post-commit
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
node .git/hooks/send-discord.js
|
||||
57
git-hooks/send-discord.js
Normal file
57
git-hooks/send-discord.js
Normal file
@@ -0,0 +1,57 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user