const axios = require('axios'); const fs = require('fs'); // Indentation function function indentString(string, indentation) { return string.split('\n').map(line => indentation + line).join('\n'); } let contributors = '\n'; let index = 0; let page = 1; function fetchPage() { axios.get(`https://api.github.com/repos/FonduemangVI/Guides/contributors?per_page=100&page=${page}`) .then((response) => { if (response.data.length === 0) { // No more contributors, write the file contributors += '
\n'; contributors = indentString(contributors, ''); fs.writeFileSync('CONTRIBUTORS.md', `## Contributors\n\n\n${contributors}\n\n`); return; } response.data.forEach((user) => { // Exclude bots if (user.type === 'Bot' || user.login.toLowerCase().includes('bot')) return; if (index % 6 === 0) { contributors += ''; } const userHtml = ` ${user.login}
${user.login}
`; contributors += indentString(userHtml, ' '); if ((index + 1) % 6 === 0 || index === response.data.length - 1) { contributors += '\n\n'; } index++; }); // Fetch the next page page++; fetchPage(); }) .catch((error) => { console.error(`Could not fetch contributors: ${error}`); }); } fetchPage();