diff --git a/.github/scripts/update-contributors.js b/.github/scripts/update-contributors.js index 97647e680..cce8dd82e 100644 --- a/.github/scripts/update-contributors.js +++ b/.github/scripts/update-contributors.js @@ -1,62 +1,42 @@ - const fs = require('fs'); const axios = require('axios'); + const fs = require('fs'); - const owner = 'FonduemangVI'; - const repo = 'Guides'; - - async function updateContributors() { - try { - const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/contributors`); - - if (!response.data || !Array.isArray(response.data)) { - throw new Error('Invalid response from GitHub API'); - } + // Indentation function + function indentString(string, indentation) { + return string.split('\n').map(line => indentation + line).join('\n'); + } - let contributors = '\n\n'; - let count = 0; + axios.get('https://api.github.com/repos/FonduemangVI/Guides/contributors') + .then((response) => { + let contributors = '
\n'; response.data.forEach((user, index) => { - if (!user.login || !user.html_url || !user.avatar_url) { - throw new Error('Invalid user data from GitHub API'); + if (index % 6 === 0) { + contributors += '\n'; } - contributors += ` - `; - - // Add a new row every 6th user - if ((index + 1) % 6 === 0) { - contributors += '\n\n\n'; - count = 0; - } else { - count++; + + `; + + contributors += indentString(userHtml, ' '); + + if ((index + 1) % 6 === 0 || index === response.data.length - 1) { + contributors += '\n'; } }); - // Add empty cells if there are fewer than 6 contributors in the last row - for (let i = count; i < 6; i++) { - contributors += ''; - } - - contributors += '\n
- - ${user.login} + const userHtml = ` + + + ${user.login}
${user.login} -
-
'; + contributors += '\n'; + contributors = indentString(contributors, ''); fs.writeFileSync('CONTRIBUTORS.md', `## Contributors\n\n\n${contributors}\n\n`); - } catch (error) { - console.error('Error updating contributors:', error.message); - - if (error.response) { - console.error('Response status:', error.response.status); - console.error('Response data:', error.response.data); - } - - process.exit(1); - } - } - - updateContributors(); + }) + .catch((error) => { + console.error(`Could not fetch contributors: ${error}`); + }); \ No newline at end of file