Skip to content

Commit

Permalink
chore: Fix discord message output
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Apr 22, 2024
1 parent de97db6 commit c4630f6
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions .github/actions/discord-message/action.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ 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();
};

Expand Down Expand Up @@ -63,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 @@ -74,10 +72,7 @@ async function main() {
if (!response.ok) {
console.error('Something went wrong while sending the discord webhook.', response.status);
console.error(await response.text());
return;
}

return response;
}

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

0 comments on commit c4630f6

Please sign in to comment.