2021-10-18 04:15:45 +00:00
|
|
|
import { MessageEmbed, WebhookClient } from "discord.js";
|
2023-08-03 05:58:10 +00:00
|
|
|
import { Octokit } from "@octokit/rest";
|
|
|
|
import { throttling } from "@octokit/plugin-throttling";
|
|
|
|
import { retry } from "@octokit/plugin-retry";
|
2021-10-18 04:15:45 +00:00
|
|
|
|
2023-08-03 05:58:10 +00:00
|
|
|
let owner = process.env.OWNER;
|
|
|
|
let repo = process.env.REPO;
|
|
|
|
|
|
|
|
Octokit.plugin(throttling);
|
|
|
|
Octokit.plugin(retry);
|
|
|
|
const octokit = new Octokit({
|
|
|
|
auth: process.env.GITHUB_TOKEN,
|
|
|
|
userAgent: `${owner}/${repo}`,
|
|
|
|
log: {
|
|
|
|
debug: () => { },
|
|
|
|
info: () => { },
|
|
|
|
warn: console.warn,
|
|
|
|
error: console.error
|
|
|
|
},
|
|
|
|
throttle: {
|
|
|
|
onRateLimit: (retryAfter, options) => {
|
|
|
|
octokit.log.warn(
|
|
|
|
`Request quota exhausted for request ${options.method} ${options.url}`
|
|
|
|
);
|
|
|
|
|
|
|
|
// Retry twice after hitting a rate limit error, then give up
|
|
|
|
if (options.request.retryCount <= 2) {
|
|
|
|
console.log(`Retrying after ${retryAfter} seconds!`);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onAbuseLimit: (retryAfter, options) => {
|
|
|
|
// does not retry, only logs a warning
|
|
|
|
octokit.log.warn(
|
|
|
|
`Abuse detected for request ${options.method} ${options.url}`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (process.env.TAG_VAL === undefined || process.env.TAG_VAL === "") {
|
|
|
|
console.log(`Not announcing - TAG_VAL not defined`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { data: releaseInfo } = await octokit.rest.repos.getReleaseByTag({
|
|
|
|
owner: owner,
|
|
|
|
repo: repo,
|
|
|
|
tag: process.env.TAG_VAL,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (releaseInfo === undefined) {
|
|
|
|
console.log(`Not announcing - could not locate release with tag ${process.env.TAG_VAL}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2021-11-23 01:02:18 +00:00
|
|
|
|
|
|
|
if (!releaseInfo.prerelease) {
|
|
|
|
console.log("Not announcing - release was not a pre-release (aka a Nightly)");
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2021-10-18 04:15:45 +00:00
|
|
|
// Publish Webhook
|
|
|
|
const embed = new MessageEmbed()
|
|
|
|
.setColor('#FF8000')
|
|
|
|
.setTitle('New PCSX2 Nightly Build Available!')
|
2022-03-31 00:29:51 +00:00
|
|
|
.setDescription("To download the latest or previous builds, [visit the official downloads page](https://pcsx2.net/downloads/).")
|
2021-10-18 04:15:45 +00:00
|
|
|
.addFields(
|
2021-11-23 01:02:18 +00:00
|
|
|
{ name: 'Version', value: releaseInfo.tag_name, inline: true },
|
2021-11-03 23:42:14 +00:00
|
|
|
{ name: 'Installation Steps', value: '[See Here](https://github.com/PCSX2/pcsx2/wiki/Nightly-Build-Usage-Guide)', inline: true },
|
2022-03-31 00:29:51 +00:00
|
|
|
{ name: 'Included Changes', value: releaseInfo.body, inline: false }
|
2021-10-18 04:15:45 +00:00
|
|
|
);
|
2023-08-03 05:58:10 +00:00
|
|
|
console.log(embed);
|
2021-10-18 04:15:45 +00:00
|
|
|
|
2022-11-04 04:14:41 +00:00
|
|
|
// Get all webhooks, simple comma-sep string
|
|
|
|
const webhookUrls = process.env.DISCORD_BUILD_WEBHOOK.split(",");
|
|
|
|
|
|
|
|
for (const url of webhookUrls) {
|
|
|
|
const webhookClient = new WebhookClient({ url: url });
|
|
|
|
await webhookClient.send({
|
|
|
|
embeds: [embed],
|
|
|
|
});
|
|
|
|
}
|