Skip to content

Commit 123f797

Browse files
committed
chore: Add discord-message action logging
1 parent c063ef6 commit 123f797

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

.github/actions/discord-message/action.mjs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,23 @@ const formatBody = (input) => {
1111
const updatedDepsRe = /\n-\s*Updated dependencies[\s\S]+\n(\n\s+-[\s\S]+)*/gi;
1212
const markdownLinkRe = /\[([^\]]+)\]\(([^\)]+)\)/g;
1313
const creditRe = new RegExp(`Submitted by (?:undefined|${markdownLinkRe.source})`, 'ig');
14-
const repeatedNewlineRe = /(\n[ ]*)+/g;
14+
const repeatedNewlineRe = /(?:\n[ ]*)*(\n[ ]*)/g;
1515
return input
1616
.replace(titleRe, '')
1717
.replace(updatedDepsRe, '')
1818
.replace(creditRe, (_match, text, url) => {
1919
if (!text || /@kitten|@JoviDeCroock/i.test(text)) return '';
2020
return `Submitted by [${text}](${url})`;
2121
})
22-
.replace(markdownLinkRe, (_match, text, url) => {
23-
return `[${text}](<${url}>)`;
24-
})
25-
.replace(repeatedNewlineRe, '\n')
22+
.replace(markdownLinkRe, (_match, text, url) => `[${text}](<${url}>)`)
23+
.replace(repeatedNewlineRe, (_match, text) => text ? ` ${text}` : '\n')
2624
.trim();
2725
};
2826

2927
async function getReleaseBody(name, version) {
3028
const tag = `${name}@${version}`;
31-
const result = await octokit.rest.repos.getReleaseByTag({
32-
owner: 'urql-graphql',
33-
repo: 'urql',
34-
tag,
35-
});
29+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
30+
const result = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });
3631

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

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

7772
if (!response.ok) {
78-
console.log('Something went wrong while sending the discord webhook.');
79-
return;
73+
console.error('Something went wrong while sending the discord webhook.', response.status);
74+
console.error(await response.text());
8075
}
81-
82-
return response;
8376
}
8477

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

0 commit comments

Comments
 (0)