nixos-configs/common/pkgs/discommit/index.ts

34 lines
924 B
TypeScript
Raw Normal View History

2023-12-22 16:20:10 -05:00
#!/usr/bin/env node
2023-12-22 03:06:15 -05:00
import { Commit } from 'commit'; // Custom type
import fetch from 'node-fetch';
const DATA = {
2023-12-22 16:20:10 -05:00
sha: process.env.GITHUB_SHA,
webhook: process.argv[2],
2023-12-22 03:06:15 -05:00
};
2023-12-22 16:20:10 -05:00
const commitInfo = await (await fetch(`https://git.nelim.org/api/v1/repos/matt1432/nixos-configs/git/commits/${DATA.sha}`)).json() as Commit;
2023-12-22 03:06:15 -05:00
const commit = JSON.stringify({
content: null,
embeds: [{
title: 'New commit containing changes to server configs:',
2023-12-22 16:20:10 -05:00
description: commitInfo.commit.message,
url: commitInfo.url,
2023-12-22 03:06:15 -05:00
author: {
2023-12-22 16:20:10 -05:00
name: commitInfo.author.username,
icon_url: commitInfo.author.avatar_url,
2023-12-22 03:06:15 -05:00
},
}],
// Diff: await (await fetch(`${last['url']}.diff`)).text()
});
const post = await fetch(`${DATA.webhook}?wait=true`, {
method: 'post',
body: commit,
headers: { 'Content-Type': 'application/json' },
});
console.log(await post.text());