-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.js
More file actions
82 lines (71 loc) · 2.09 KB
/
Copy pathgithub.js
File metadata and controls
82 lines (71 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// bot.js - GitHub Release Notifier (Stable CommonJS, PM2 kompatibilis)
const fs = require('fs');
const fetch = require('node-fetch'); // node-fetch v2 szükséges
// Webhook URL
const WEBHOOK_URL = "YOUR-DISCROD-WEBHOOK-URL";
// GitHub repositories to monitor
const REPOS = [
"YOUR-REPO1", // No url needed, just author/reponame
"YOUR-REPO2"
];
// Storage file for last checked versions
const DATA_FILE = "last_releases.json";
let lastReleases = {};
if (fs.existsSync(DATA_FILE)) {
lastReleases = JSON.parse(fs.readFileSync(DATA_FILE));
}
async function checkRepo(repo) {
try {
const response = await fetch(`https://api.github.com/repos/${repo}/releases/latest`);
if (!response.ok) return;
const data = await response.json();
const latestTag = data.tag_name;
if (!latestTag) return;
if (lastReleases[repo] !== latestTag) {
await sendDiscordNotification(repo, data);
lastReleases[repo] = latestTag;
fs.writeFileSync(DATA_FILE, JSON.stringify(lastReleases, null, 2));
}
} catch (err) {
console.error(`Error checking ${repo}:`, err);
}
}
async function sendDiscordNotification(repo, release) {
const payload = {
username: "Github",
embeds: [
{
title: `🆕 New Release: ${release.name || release.tag_name}`,
url: release.html_url,
description: `Repo: **${repo}**`,
color: 16750848,
fields: [
{
name: "Changelog",
value: release.body ? release.body.substring(0, 1024) : "(nincs leírás)"
}
],
timestamp: new Date()
}
]
};
try {
await fetch(WEBHOOK_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
});
console.log(`Notification sent for ${repo}`);
} catch (err) {
console.error(`Error sending Discord notification for ${repo}:`, err);
}
}
async function checkAll() {
console.log("Checking repositories...");
for (const repo of REPOS) {
await checkRepo(repo);
}
}
// Run every 5 minutes
setInterval(checkAll, 1000 * 60 * 5);
checkAll();