GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — node/tools/find-inactive-tsc.mjs at main · styfle/node Expand file tree/ Copy pathfind-inactive-tsc.mjsMore file actions executable file ·285 lines (253 loc) · 9 KB / Copy pathfind-inactive-tsc.mjsFile metadata and controlsexecutable file ·285 lines (253 loc) · 9 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 #!/usr/bin/env node // Identify inactive TSC members. // From the TSC Charter: // A TSC member is automatically removed from the TSC if, during a 3-month // period, all of the following are true: // * They attend fewer than 25% of the regularly scheduled meetings. // * They do not participate in any TSC votes. import cp from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import readline from 'node:readline'; import { parseArgs } from 'node:util'; const args = parseArgs({ allowPositionals: true, options: { verbose: { type: 'boolean', short: 'v' } } }); const verbose = args.values.verbose; const SINCE = args.positionals[0] || '3 months ago'; async function runGitCommand(cmd, options = {}) { const childProcess = cp.spawn('/bin/sh', ['-c', cmd], { cwd: options.cwd ?? new URL('..', import.meta.url), encoding: 'utf8', stdio: ['inherit', 'pipe', 'inherit'], }); const lines = readline.createInterface({ input: childProcess.stdout, }); const errorHandler = new Promise( (_, reject) => childProcess.on('error', reject) ); let returnValue = options.mapFn ? new Set() : ''; await Promise.race([errorHandler, Promise.resolve()]); // If no mapFn, return the value. If there is a mapFn, use it to make a Set to // return. for await (const line of lines) { await Promise.race([errorHandler, Promise.resolve()]); if (options.mapFn) { const val = options.mapFn(line); if (val) { returnValue.add(val); } } else { returnValue += line; } } return Promise.race([errorHandler, Promise.resolve(returnValue)]); } async function getTscFromReadme() { const readmeText = readline.createInterface({ input: fs.createReadStream(new URL('../README.md', import.meta.url)), crlfDelay: Infinity, }); const returnedArray = []; let foundTscHeading = false; for await (const line of readmeText) { // If we've found the TSC heading already, stop processing at the next // heading. if (foundTscHeading && line.startsWith('#')) { break; } const isTsc = foundTscHeading && line.length; if (line === '### TSC (Technical Steering Committee)') { foundTscHeading = true; } if (line.startsWith('* ') && isTsc) { const handle = line.match(/^\* \[([^\]]+)]/)[1]; returnedArray.push(handle); } } if (!foundTscHeading) { throw new Error('Could not find TSC section of README'); } return returnedArray; } async function getAttendance(tscMembers, meetings) { const attendance = {}; for (const member of tscMembers) { attendance[member] = 0; } for (const meeting of meetings) { // Get the file contents. const meetingFile = await fs.promises.readFile(path.join('.tmp', meeting), 'utf8'); // Extract the attendee list. const startMarker = '## Present'; const start = meetingFile.indexOf(startMarker) + startMarker.length; const end = meetingFile.indexOf('## Agenda'); meetingFile.substring(start, end).trim().split('\n') .map((line) => { const match = line.match(/@(\S+)/); if (match) { return match[1]; } // Using `console.warn` so that stdout output is not generated. // The stdout output is consumed in find-inactive-tsc.yml. console.warn(`Attendee entry does not contain GitHub handle: ${line}`); return ''; }) .filter((handle) => tscMembers.includes(handle)) .forEach((handle) => { attendance[handle]++; }); } return attendance; } async function getVotingRecords(tscMembers, votes) { const votingRecords = {}; for (const member of tscMembers) { votingRecords[member] = 0; } for (const vote of votes) { // Get the vote data. const voteData = JSON.parse( await fs.promises.readFile(path.join('.tmp', vote), 'utf8') ); for (const member in voteData.votes) { if (tscMembers.includes(member)) { votingRecords[member]++; } } } return votingRecords; } async function moveTscToEmeritus(peopleToMove) { const readmeText = readline.createInterface({ input: fs.createReadStream(new URL('../README.md', import.meta.url)), crlfDelay: Infinity, }); let fileContents = ''; let inTscSection = false; let inTscEmeritusSection = false; let memberFirstLine = ''; const textToMove = []; let moveToInactive = false; for await (const line of readmeText) { // If we've been processing TSC emeriti and we reach the end of // the list, print out the remaining entries to be moved because they come // alphabetically after the last item. if (inTscEmeritusSection && line === '' && fileContents.endsWith('>\n')) { while (textToMove.length) { fileContents += textToMove.pop(); } } // If we've found the TSC heading already, stop processing at the // next heading. if (line.startsWith('#')) { inTscSection = false; inTscEmeritusSection = false; } const isTsc = inTscSection && line.length; const isTscEmeritus = inTscEmeritusSection && line.length; if (line === '### TSC (Technical Steering Committee)') { inTscSection = true; } if (line === '### TSC emeriti') { inTscEmeritusSection = true; } if (isTsc) { if (line.startsWith('* ')) { memberFirstLine = line; const match = line.match(/^\* \[([^\]]+)/); if (match && peopleToMove.includes(match[1])) { moveToInactive = true; } } else if (line.startsWith(' **')) { if (moveToInactive) { textToMove.push(`${memberFirstLine}\n${line}\n`); moveToInactive = false; } else { fileContents += `${memberFirstLine}\n${line}\n`; } } else { fileContents += `${line}\n`; } } if (isTscEmeritus) { if (line.startsWith('* ')) { memberFirstLine = line; } else if (line.startsWith(' **')) { const currentLine = `${memberFirstLine}\n${line}\n`; // If textToMove is empty, this still works because when undefined is // used in a comparison with <, the result is always false. while (textToMove[0]?.toLowerCase() < currentLine.toLowerCase()) { fileContents += textToMove.shift(); } fileContents += currentLine; } else { fileContents += `${line}\n`; } } if (!isTsc && !isTscEmeritus) { fileContents += `${line}\n`; } } return fileContents; } // Get current TSC members, then get TSC members at start of period. Only check // TSC members who are on both lists. This way, we don't flag someone who has // only been on the TSC for a week and therefore hasn't attended any meetings. const tscMembersAtEnd = await getTscFromReadme(); const startCommit = await runGitCommand(`git rev-list -1 --before '${SINCE}' HEAD`); await runGitCommand(`git checkout ${startCommit} -- README.md`); const tscMembersAtStart = await getTscFromReadme(); await runGitCommand('git reset HEAD README.md'); await runGitCommand('git checkout -- README.md'); const tscMembers = tscMembersAtEnd.filter( (memberAtEnd) => tscMembersAtStart.includes(memberAtEnd) ); // Get all meetings since SINCE. // Assumes that the TSC repo is cloned in the .tmp dir. const meetings = await runGitCommand( `git whatchanged --since '${SINCE}' --name-only --pretty=format: meetings`, { cwd: '.tmp', mapFn: (line) => line } ); // Get TSC meeting attendance. const attendance = await getAttendance(tscMembers, meetings); const lightAttendance = tscMembers.filter( (member) => attendance[member] < meetings.size * 0.25 ); // Get all votes since SINCE. // Assumes that the TSC repo is cloned in the .tmp dir. const votes = await runGitCommand( `git whatchanged --since '${SINCE}' --name-only --pretty=format: votes/*.json`, { cwd: '.tmp', mapFn: (line) => line } ); // Check voting record. const votingRecords = await getVotingRecords(tscMembers, votes); const noVotes = tscMembers.filter( (member) => votingRecords[member] === 0 ); const inactive = lightAttendance.filter((member) => noVotes.includes(member)); if (inactive.length) { // The stdout output is consumed in find-inactive-tsc.yml. If format of output // changes, find-inactive-tsc.yml may need to be updated. console.log(`INACTIVE_TSC_HANDLES=${inactive.map((entry) => '@' + entry).join(' ')}`); const commitDetails = inactive.map((entry) => { let details = `Since ${SINCE}, `; details += `${entry} attended ${attendance[entry]} out of ${meetings.size} meetings`; details += ` and voted in ${votingRecords[entry]} of ${votes.size} votes.`; return details; }); console.log(`DETAILS_FOR_COMMIT_BODY=${commitDetails.join(' ')}`); if (process.env.GITHUB_ACTIONS) { // Using console.warn() to avoid messing with find-inactive-tsc which // consumes stdout. console.warn('Generating new README.md file...'); const newReadmeText = await moveTscToEmeritus(inactive); fs.writeFileSync(new URL('../README.md', import.meta.url), newReadmeText); } } if (verbose) { console.log(attendance); console.log(votingRecords); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |