Skip to content

Commit

Permalink
chore: Add discord-message action logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 22, 2024
1 parent c063ef6 commit 123f797
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions .github/actions/discord-message/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,23 @@ const formatBody = (input) => {
const updatedDepsRe = /\n-\s*Updated dependencies[\s\S]+\n(\n\s+-[\s\S]+)*/gi;
const markdownLinkRe = /\[([^\]]+)\]\(([^\)]+)\)/g;
const creditRe = new RegExp(`Submitted by (?:undefined|${markdownLinkRe.source})`, 'ig');
const repeatedNewlineRe = /(\n[ ]*)+/g;
const repeatedNewlineRe = /(?:\n[ ]*)*(\n[ ]*)/g;
return input
.replace(titleRe, '')
.replace(updatedDepsRe, '')
.replace(creditRe, (_match, text, url) => {
if (!text || /@kitten|@JoviDeCroock/i.test(text)) return '';
return `Submitted by [${text}](${url})`;
})
.replace(markdownLinkRe, (_match, text, url) => {
return `[${text}](<${url}>)`;
})
.replace(repeatedNewlineRe, '\n')
.replace(markdownLinkRe, (_match, text, url) => `[${text}](<${url}>)`)
.replace(repeatedNewlineRe, (_match, text) => text ? ` ${text}` : '\n')
.trim();
};

async function getReleaseBody(name, version) {
const tag = `${name}@${version}`;
const result = await octokit.rest.repos.getReleaseByTag({
owner: 'urql-graphql',
repo: 'urql',
tag,
});
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const result = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });

const release = result.status === 200 ? result.data : undefined;
if (!release || !release.body) return;
Expand Down Expand Up @@ -66,7 +61,7 @@ async function main() {
.join('\n\n');

// Send message through a discord webhook or bot
const response = fetch(WEBHOOK_URL, {
const response = await fetch(WEBHOOK_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -75,11 +70,9 @@ async function main() {
});

if (!response.ok) {
console.log('Something went wrong while sending the discord webhook.');
return;
console.error('Something went wrong while sending the discord webhook.', response.status);
console.error(await response.text());
}

return response;
}

main().then().catch(console.error);

0 comments on commit 123f797

Please sign in to comment.