From fa95076a94db99b09971dc120f2cb01983370fde Mon Sep 17 00:00:00 2001 From: Thomas Hohn Date: Fri, 20 Dec 2024 20:31:13 +0100 Subject: [PATCH 1/2] Run eslint-fix --- runok.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runok.js b/runok.js index d7d731610..83ba227dc 100755 --- a/runok.js +++ b/runok.js @@ -526,7 +526,7 @@ ${changelog}` if (match) { const updatedContent = content.replace( contributorsSectionRegex, - `${match[1]}\n${contributorsTable}\n${match[3]}` + `${match[1]}\n${contributorsTable}\n${match[3]}`, ); fs.writeFileSync(readmePath, updatedContent, 'utf-8'); } else { From 046081219ad4a9c288d3e7bbb2a433f8ce444732 Mon Sep 17 00:00:00 2001 From: Thomas Hohn Date: Fri, 20 Dec 2024 21:20:23 +0100 Subject: [PATCH 2/2] Follow up --- runok.js | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/runok.js b/runok.js index 83ba227dc..ec12fe910 100755 --- a/runok.js +++ b/runok.js @@ -478,19 +478,14 @@ ${changelog}` const token = process.env.GH_TOKEN try { - const response = await axios.get( - `https://api.github.com/repos/${owner}/${repo}/contributors`, - { - headers: { Authorization: `token ${token}` }, - }, - ); + const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/contributors`, { + headers: { Authorization: `token ${token}` }, + }) // Filter out bot accounts - const excludeUsers = ['dependabot[bot]', 'actions-user']; + const excludeUsers = ['dependabot[bot]', 'actions-user'] - const filteredContributors = response.data.filter( - (contributor) => !excludeUsers.includes(contributor.login), - ); + const filteredContributors = response.data.filter((contributor) => !excludeUsers.includes(contributor.login)) const contributors = filteredContributors.map((contributor) => { return ` @@ -499,14 +494,14 @@ ${changelog}` ${contributor.login}
${contributor.login} -`; - }); +` + }) // Chunk contributors into rows of 4 - const rows = []; - const chunkSize = 4; + const rows = [] + const chunkSize = 4 for (let i = 0; i < contributors.length; i += chunkSize) { - rows.push(`${contributors.slice(i, i + chunkSize).join('')}`); + rows.push(`${contributors.slice(i, i + chunkSize).join('')}`) } // Combine rows into a table @@ -514,30 +509,30 @@ ${changelog}` ${rows.join('\n')}
- `; + ` - const readmePath = path.join(__dirname, 'README.md'); - let content = fs.readFileSync(readmePath, 'utf-8'); + const readmePath = path.join(__dirname, 'README.md') + let content = fs.readFileSync(readmePath, 'utf-8') // Replace or add the contributors section in the README - const contributorsSectionRegex = /(## Contributors\s*\n)([\s\S]*?)(\n##|$)/; - const match = content.match(contributorsSectionRegex); + const contributorsSectionRegex = /(## Contributors\s*\n)([\s\S]*?)(\n##|$)/ + const match = content.match(contributorsSectionRegex) if (match) { const updatedContent = content.replace( contributorsSectionRegex, `${match[1]}\n${contributorsTable}\n${match[3]}`, - ); - fs.writeFileSync(readmePath, updatedContent, 'utf-8'); + ) + fs.writeFileSync(readmePath, updatedContent, 'utf-8') } else { // If no contributors section exists, add one at the end - content += `\n${contributorsTable}`; - fs.writeFileSync(readmePath, content, 'utf-8'); + content += `\n${contributorsTable}` + fs.writeFileSync(readmePath, content, 'utf-8') } - console.log('Contributors section updated successfully!'); + console.log('Contributors section updated successfully!') } catch (error) { - console.error('Error fetching contributors:', error.message); + console.error('Error fetching contributors:', error.message) } },