changes
This commit is contained in:
parent
76a7335c7c
commit
372b7c1f66
4 changed files with 22 additions and 8 deletions
11
.env.example
Normal file
11
.env.example
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Discord
|
||||
DISCORD_TOKEN=
|
||||
CHANNEL_ID=1389308172531011615
|
||||
|
||||
# GitHub
|
||||
GITHUB_TOKEN=
|
||||
|
||||
# Eden Git (Generate Personal Token on your Eden Git account)
|
||||
EDEN_TOKEN=
|
||||
GITHUB_REPO=Eden-CI/PR
|
||||
POLL_INTERVAL_MS=30000
|
|
@ -8,7 +8,7 @@ import initializeDescriptionWatcher from './functions/description_watcher.js';
|
|||
const { DISCORD_TOKEN } = process.env;
|
||||
|
||||
if (!DISCORD_TOKEN) {
|
||||
console.error('Fatal: DISCORD_TOKEN is not set in the .env file.');
|
||||
console.error('DISCORD_TOKEN is not set in the .env file.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ const client = new Client({
|
|||
client.once('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
|
||||
initializeReleaseWatcher(client);
|
||||
// Release Watcher disabled for now, after the RAID have to setup again
|
||||
//initializeReleaseWatcher(client);
|
||||
initializeDescriptionWatcher(client);
|
||||
});
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ let isCheckingDescriptions = false;
|
|||
|
||||
function disabled() {
|
||||
console.log('[Description Watcher] Service is disabled due to missing environment variables.');
|
||||
console.log('[Description Watcher] CHANNEL_ID = ' + CHANNEL_ID + ' GITHUB_TOKEN = ' + GITHUB_TOKEN + ' EDEN_TOKEN = ' + EDEN_TOKEN);
|
||||
console.log('[Description Watcher][DEBUG] CHANNEL_ID = ' + CHANNEL_ID + ' GITHUB_TOKEN = ' + GITHUB_TOKEN + ' EDEN_TOKEN = ' + EDEN_TOKEN);
|
||||
}
|
||||
|
||||
const wait = ms => new Promise(res => setTimeout(res, ms));
|
||||
|
@ -24,16 +24,15 @@ async function buildThreadContent(buildNumber) {
|
|||
let release;
|
||||
let relRes = await fetch(`https://api.github.com/repos/${REPO}/releases/tags/${buildNumber}`, {
|
||||
headers: {
|
||||
'User-Agent': 'description-watcher',
|
||||
'User-Agent': 'description-watcher, EDEN',
|
||||
Authorization: `token ${GITHUB_TOKEN}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (relRes.status === 404) {
|
||||
// Tag lookup failed – list the latest 100 releases and find one whose tag_name == buildNumber
|
||||
const listRes = await fetch(`https://api.github.com/repos/${REPO}/releases?per_page=100`, {
|
||||
headers: {
|
||||
'User-Agent': 'description-watcher',
|
||||
'User-Agent': 'description-watcher, EDEN',
|
||||
Authorization: `token ${GITHUB_TOKEN}`,
|
||||
},
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ let isCheckingReleases = false;
|
|||
|
||||
function disabled() {
|
||||
console.log('[Release Watcher] Service is disabled due to missing environment variables.');
|
||||
console.log('[Release Watcher] CHANNEL_ID = '+CHANNEL_ID+' GITHUB_TOKEN = '+GITHUB_TOKEN+' EDEN_TOKEN = '+EDEN_TOKEN);
|
||||
console.log('[Release Watcher][DEBUG] CHANNEL_ID = '+CHANNEL_ID+' GITHUB_TOKEN = '+GITHUB_TOKEN+' EDEN_TOKEN = '+EDEN_TOKEN);
|
||||
}
|
||||
|
||||
async function announceRelease(release, channel, baseTag) {
|
||||
|
@ -31,6 +31,7 @@ async function announceRelease(release, channel, baseTag) {
|
|||
}
|
||||
const title = `Build ${baseTag}`;
|
||||
const prUrl = `https://git.eden-emu.dev/eden-emu/eden/pulls/${baseTag}`;
|
||||
// maybe a better with templating? dunno yet
|
||||
let content = `**${title} - ${release.name}**\n\n${desc}\n\n🔗 [Go to pull request](${prUrl})\n\n📝 [Go to downloads](${release.html_url})`;
|
||||
if (content.length > 2000) content = content.slice(0, 1997) + '...';
|
||||
|
||||
|
@ -53,8 +54,9 @@ async function checkReleases(client) {
|
|||
isCheckingReleases = true;
|
||||
try {
|
||||
const res = await fetch(`https://api.github.com/repos/${REPO}/releases`, {
|
||||
headers: { 'User-Agent': 'release-watcher', 'Authorization': `token ${GITHUB_TOKEN}` }
|
||||
headers: { 'User-Agent': 'release-watcher, EDEN', 'Authorization': `token ${GITHUB_TOKEN}` }
|
||||
});
|
||||
// i hate checking for status code like this
|
||||
if (res.status === 403) {
|
||||
console.error('[Release Watcher] GitHub API error: Rate limit or access denied.');
|
||||
return;
|
||||
|
@ -76,6 +78,7 @@ async function checkReleases(client) {
|
|||
allUniqueReleases.sort((a, b) => parseInt(b.tag_name) - parseInt(a.tag_name));
|
||||
const toProcess = allUniqueReleases.slice(0, 10).reverse();
|
||||
|
||||
// currently, we only support one channel
|
||||
const channel = await client.channels.fetch(CHANNEL_ID);
|
||||
if (channel.type !== ChannelType.GuildForum) {
|
||||
console.error(`[Release Watcher] Channel ${CHANNEL_ID} is not a Forum Channel.`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue