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: Update Discord hook formatting (#3563)

authored by

Phil Pluckthun and committed by
GitHub
3f573fb9 e93496c0

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