(reports, missingCount = 0)
| 461 | * @returns {string} |
| 462 | */ |
| 463 | export const generateMarkdownReport = (reports, missingCount = 0) => { |
| 464 | if (!missingCount) { |
| 465 | return 'No missing contributors detected.\n'; |
| 466 | } |
| 467 | |
| 468 | const nowIso = new Date().toISOString(); |
| 469 | |
| 470 | const computeTypesArg = (report) => { |
| 471 | const typeSet = new Set(); |
| 472 | for (const pr of report.prs || []) { |
| 473 | for (const type of pr.contributionTypes || []) { |
| 474 | if (type) { |
| 475 | typeSet.add(type); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | const types = Array.from(typeSet).sort((a, b) => a.localeCompare(b)); |
| 481 | return types.length > 0 ? types.join(',') : 'code'; |
| 482 | }; |
| 483 | |
| 484 | const lines = []; |
| 485 | |
| 486 | lines.push( |
| 487 | '# Missing Contributors Report', |
| 488 | '', |
| 489 | `Generated (ISO): ${nowIso}`, |
| 490 | '', |
| 491 | `Missing contributors: ${missingCount}`, |
| 492 | '' |
| 493 | ); |
| 494 | |
| 495 | for (const report of reports) { |
| 496 | lines.push(`## @${report.username}`); |
| 497 | |
| 498 | const prs = Array.from(report.prs || []).sort((a, b) => { |
| 499 | // Prefer most recent PRs first. |
| 500 | const aTime = a.mergedAt ? Date.parse(a.mergedAt) : 0; |
| 501 | const bTime = b.mergedAt ? Date.parse(b.mergedAt) : 0; |
| 502 | if (aTime !== bTime) return bTime - aTime; |
| 503 | return (b.prNumber ?? 0) - (a.prNumber ?? 0); |
| 504 | }); |
| 505 | |
| 506 | if (prs.length === 0) { |
| 507 | lines.push( |
| 508 | '', |
| 509 | '_No eligible PRs found._', |
| 510 | '', |
| 511 | `Alternate CLI: \`npx all-contributors add ${report.username} ${computeTypesArg(report)}\``, |
| 512 | '', |
| 513 | '---', |
| 514 | '' |
| 515 | ); |
| 516 | continue; |
| 517 | } |
| 518 | |
| 519 | lines.push(''); |
| 520 |
no test coverage detected