| 475 | * Update the contributors table in README.md from the GitHub API. |
| 476 | */ |
| 477 | export async function contributorFaces() { |
| 478 | const owner = 'codeceptjs' |
| 479 | const repo = 'codeceptjs' |
| 480 | const token = process.env.GH_TOKEN |
| 481 | |
| 482 | try { |
| 483 | const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/contributors`, { |
| 484 | headers: { Authorization: `token ${token}` }, |
| 485 | }) |
| 486 | |
| 487 | const excludeUsers = ['dependabot[bot]', 'actions-user'] |
| 488 | const filteredContributors = response.data.filter(contributor => !excludeUsers.includes(contributor.login)) |
| 489 | |
| 490 | const contributors = filteredContributors.map(contributor => { |
| 491 | return ` |
| 492 | <td align="center"> |
| 493 | <a href="${contributor.html_url}"> |
| 494 | <img src="${contributor.avatar_url}" width="100" height="100" alt="${contributor.login}"/><br /> |
| 495 | <sub><b>${contributor.login}</b></sub> |
| 496 | </a> |
| 497 | </td>` |
| 498 | }) |
| 499 | |
| 500 | const rows = [] |
| 501 | const chunkSize = 4 |
| 502 | for (let i = 0; i < contributors.length; i += chunkSize) { |
| 503 | rows.push(`<tr>${contributors.slice(i, i + chunkSize).join('')}</tr>`) |
| 504 | } |
| 505 | |
| 506 | const contributorsTable = ` |
| 507 | <table> |
| 508 | ${rows.join('\n')} |
| 509 | </table> |
| 510 | ` |
| 511 | |
| 512 | const readmePath = path.join(process.cwd(), 'README.md') |
| 513 | let content = fs.readFileSync(readmePath, 'utf-8') |
| 514 | |
| 515 | const contributorsSectionRegex = /(## Contributors\s*\n)([\s\S]*?)(\n##|$)/ |
| 516 | const match = content.match(contributorsSectionRegex) |
| 517 | |
| 518 | if (match) { |
| 519 | const updatedContent = content.replace(contributorsSectionRegex, `${match[1]}\n${contributorsTable}\n${match[3]}`) |
| 520 | fs.writeFileSync(readmePath, updatedContent, 'utf-8') |
| 521 | } else { |
| 522 | content += `\n${contributorsTable}` |
| 523 | fs.writeFileSync(readmePath, content, 'utf-8') |
| 524 | } |
| 525 | |
| 526 | say('Contributors section updated successfully!') |
| 527 | } catch (error) { |
| 528 | yell(`Error fetching contributors: ${error.message}`) |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /** |