Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: Fix Discord release message

+22 -31
+22 -31
.github/actions/discord-message/action.mjs
··· 1 - import * as core from "@actions/core"; 2 - import * as github from "@actions/github"; 3 - import fetch from 'node-fetch'; 1 + import * as core from '@actions/core'; 2 + import * as github from '@actions/github'; 4 3 5 4 const GITHUB_TOKEN = process.env.GITHUB_TOKEN; 6 - const WEBHOOK_URL = process.env.DISCORD_URQL_WEBHOOK_URL; 5 + const WEBHOOK_URL = process.env.DISCORD_WEBHOOK_URL; 7 6 8 7 const octokit = github.getOctokit(GITHUB_TOKEN); 9 8 10 9 const formatBody = (input) => { 11 10 const titleRe = /(?:^|\n)#+[^\n]+/g; 12 - const updatedDepsRe = /\n-\s*Updated dependencies[\s\S]+\n(\n\s+-[\s\S]+)*/ig; 11 + const updatedDepsRe = /\n-\s*Updated dependencies[\s\S]+\n(\n\s+-[\s\S]+)*/gi; 13 12 const markdownLinkRe = /\[([^\]]+)\]\(([^\)]+)\)/g; 14 13 const creditRe = new RegExp(`Submitted by (?:undefined|${markdownLinkRe.source})`, 'ig'); 15 - const repeatedNewlineRe = /(\n[ ]*)+/g; 14 + const repeatedNewlineRe = /(?:\n[ ]*)*(\n[ ]*)/g; 16 15 return input 17 16 .replace(titleRe, '') 18 17 .replace(updatedDepsRe, '') 19 18 .replace(creditRe, (_match, text, url) => { 20 - if (!text || /@kitten|@JoviDeCroock/i.test(text)) 21 - return ''; 19 + if (!text || /@kitten|@JoviDeCroock/i.test(text)) return ''; 22 20 return `Submitted by [${text}](${url})`; 23 21 }) 24 - .replace(markdownLinkRe, (_match, text, url) => { 25 - return `[${text}](<${url}>)`; 26 - }) 27 - .replace(repeatedNewlineRe, '\n') 22 + .replace(markdownLinkRe, (_match, text, url) => `[${text}](<${url}>)`) 23 + .replace(repeatedNewlineRe, (_match, text) => text ? ` ${text}` : '\n') 28 24 .trim(); 29 25 }; 30 26 31 27 async function getReleaseBody(name, version) { 32 28 const tag = `${name}@${version}`; 33 - const result = await octokit.rest.repos.getReleaseByTag({ 34 - owner: 'urql-graphql', 35 - repo: 'urql', 36 - tag, 37 - }); 29 + const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); 30 + const result = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag }); 38 31 39 32 const release = result.status === 200 ? result.data : undefined; 40 33 if (!release || !release.body) return; 41 34 42 - const title = ':package: [${tag}](<${release.html_url}>)\n'; 35 + const title = `:package: [${tag}](<${release.html_url}>)`; 43 36 const body = formatBody(release.body); 44 37 if (!body) return; 45 38 ··· 47 40 } 48 41 49 42 async function main() { 50 - const inputPackages = core.getInput("publishedPackages"); 43 + const inputPackages = core.getInput('publishedPackages'); 51 44 let packages; 52 45 53 46 try { 54 - packages = JSON.parse(inputPackages) 47 + packages = JSON.parse(inputPackages); 55 48 } catch (e) { 56 - console.error('invalid JSON in publishedPackages input.') 49 + console.error('invalid JSON in publishedPackages input.'); 57 50 return; 58 51 } 59 52 60 53 // Get releases 61 - const releasePromises = packages.map(entry => { 54 + const releasePromises = packages.map((entry) => { 62 55 return getReleaseBody(entry.name, entry.version); 63 56 }); 64 57 65 58 const content = (await Promise.allSettled(releasePromises)) 66 - .map(x => x.status === 'fulfilled' && x.value) 59 + .map((x) => x.status === 'fulfilled' && x.value) 67 60 .filter(Boolean) 68 61 .join('\n\n'); 69 62 70 63 // Send message through a discord webhook or bot 71 - const response = fetch(WEBHOOK_URL, { 64 + const response = await fetch(WEBHOOK_URL, { 72 65 method: 'POST', 73 66 headers: { 74 67 'Content-Type': 'application/json', 75 68 }, 76 - body: JSON.stringify({ content }) 77 - }) 69 + body: JSON.stringify({ content }), 70 + }); 78 71 79 72 if (!response.ok) { 80 - console.log('Something went wrong while sending the discord webhook.'); 81 - return; 73 + console.error('Something went wrong while sending the discord webhook.', response.status); 74 + console.error(await response.text()); 82 75 } 83 - 84 - return response; 85 76 } 86 77 87 - main().then().catch(console.error) 78 + main().then().catch(console.error);