|
| 1 | +import { readFile } from 'node:fs/promises'; |
| 2 | + |
| 3 | +const CONFIG = { |
| 4 | + GOVERNANCE_FILE: 'GOVERNANCE.md', |
| 5 | + CURRENT_MEMBERS_HEADER: '#### Current Members', |
| 6 | + INACTIVE_MONTHS: 12, |
| 7 | + ISSUE_TITLE: 'Inactive Collaborator Report', |
| 8 | + ISSUE_LABELS: ['meta', 'inactive-collaborator-report'], |
| 9 | +}; |
| 10 | + |
| 11 | +// Get date N months ago in YYYY-MM-DD format |
| 12 | +const getDateMonthsAgo = (months = CONFIG.INACTIVE_MONTHS) => { |
| 13 | + const date = new Date(); |
| 14 | + date.setMonth(date.getMonth() - months); |
| 15 | + return date.toISOString().split('T')[0]; |
| 16 | +}; |
| 17 | + |
| 18 | +// Parse collaborator usernames from governance file |
| 19 | +async function parseCollaborators() { |
| 20 | + const content = await readFile(CONFIG.GOVERNANCE_FILE, 'utf8'); |
| 21 | + const lines = content.split('\n'); |
| 22 | + const collaborators = []; |
| 23 | + |
| 24 | + const startIndex = |
| 25 | + lines.findIndex(l => l.startsWith(CONFIG.CURRENT_MEMBERS_HEADER)) + 1; |
| 26 | + if (startIndex <= 0) return collaborators; |
| 27 | + |
| 28 | + for (let i = startIndex; i < lines.length; i++) { |
| 29 | + const line = lines[i]; |
| 30 | + if (line.startsWith('#')) break; |
| 31 | + |
| 32 | + const match = line.match(/^\s*-\s*\[([^\]]+)\]/); |
| 33 | + if (match) collaborators.push(match[1]); |
| 34 | + } |
| 35 | + |
| 36 | + return collaborators; |
| 37 | +} |
| 38 | + |
| 39 | +// Check if users have been active since cutoff date |
| 40 | +async function getInactiveUsers(github, usernames, repo, cutoffDate) { |
| 41 | + const inactiveUsers = []; |
| 42 | + |
| 43 | + for (const username of usernames) { |
| 44 | + const { data } = await github.rest.search.commits({ |
| 45 | + q: `author:${username} repo:${repo} committer-date:>=${cutoffDate}`, |
| 46 | + per_page: 1, |
| 47 | + }); |
| 48 | + |
| 49 | + if (data.total_count === 0) { |
| 50 | + inactiveUsers.push(username); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + return inactiveUsers; |
| 55 | +} |
| 56 | + |
| 57 | +// Generate report for inactive members |
| 58 | +function formatReport(inactiveMembers, cutoffDate) { |
| 59 | + if (!inactiveMembers.length) return null; |
| 60 | + |
| 61 | + const today = getDateMonthsAgo(0); |
| 62 | + return `# Inactive Collaborators Report |
| 63 | +
|
| 64 | +Last updated: ${today} |
| 65 | +Checking for inactivity since: ${cutoffDate} |
| 66 | +
|
| 67 | +## Inactive Collaborators (${inactiveMembers.length}) |
| 68 | +
|
| 69 | +| Login | |
| 70 | +| ----- | |
| 71 | +${inactiveMembers.map(m => `| @${m} |`).join('\n')} |
| 72 | +
|
| 73 | +## What happens next? |
| 74 | +
|
| 75 | +@nodejs/nodejs-website should review this list and contact inactive collaborators to confirm their continued interest in participating in the project.`; |
| 76 | +} |
| 77 | + |
| 78 | +async function createOrUpdateIssue(github, context, report) { |
| 79 | + if (!report) return; |
| 80 | + |
| 81 | + const { owner, repo } = context.repo; |
| 82 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 83 | + owner, |
| 84 | + repo, |
| 85 | + state: 'open', |
| 86 | + labels: CONFIG.ISSUE_LABELS[1], |
| 87 | + per_page: 1, |
| 88 | + }); |
| 89 | + |
| 90 | + if (issues.total_count > 0) { |
| 91 | + await github.rest.issues.update({ |
| 92 | + owner, |
| 93 | + repo, |
| 94 | + issue_number: issues.items[0].number, |
| 95 | + body: report, |
| 96 | + }); |
| 97 | + } else { |
| 98 | + await github.rest.issues.create({ |
| 99 | + owner, |
| 100 | + repo, |
| 101 | + title: CONFIG.ISSUE_TITLE, |
| 102 | + body: report, |
| 103 | + labels: CONFIG.ISSUE_LABELS, |
| 104 | + }); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +export default async function (github, context) { |
| 109 | + const cutoffDate = getDateMonthsAgo(); |
| 110 | + const collaborators = await parseCollaborators(); |
| 111 | + |
| 112 | + const inactiveMembers = await getInactiveUsers( |
| 113 | + github, |
| 114 | + collaborators, |
| 115 | + `${context.repo.owner}/${context.repo.repo}`, |
| 116 | + cutoffDate |
| 117 | + ); |
| 118 | + const report = formatReport(inactiveMembers, cutoffDate); |
| 119 | + |
| 120 | + await createOrUpdateIssue(github, context, report); |
| 121 | +} |
0 commit comments