11#!/usr/bin/env node
22
3- // Validates the list in the README are in the correct order.
3+ // Validates the list in the README are in the correct order, and consistent with the actual GitHub teams .
44
5+ import assert from 'node:assert' ;
56import { open } from 'node:fs/promises' ;
7+ import { argv } from 'node:process' ;
68
7- const lists = [
8- 'TSC voting members' ,
9- 'TSC regular members' ,
10- 'TSC emeriti members' ,
11- 'Collaborators' ,
12- 'Collaborator emeriti' ,
13- 'Triagers' ,
14- ] ;
9+ const lists = {
10+ '__proto__' : null ,
11+
12+ 'TSC voting members' : 'tsc' ,
13+ 'TSC regular members' : null ,
14+ 'TSC emeriti members' : null ,
15+ 'Collaborators' : 'collaborators' ,
16+ 'Collaborator emeriti' : null ,
17+ 'Triagers' : 'issue-triage' ,
18+ } ;
19+ const actualMembers = {
20+ __proto__ : null ,
21+ // The bot is part of `@nodejs/collaborators`, but is not listed in the README.
22+ collaborators : new Set ( ) . add ( 'nodejs-github-bot' ) ,
23+ } ;
1524const tscMembers = new Set ( ) ;
1625
1726const readme = await open ( new URL ( '../README.md' , import . meta. url ) , 'r' ) ;
@@ -23,26 +32,47 @@ let lineNumber = 0;
2332for await ( const line of readme . readLines ( ) ) {
2433 lineNumber ++ ;
2534 if ( line . startsWith ( '### ' ) ) {
26- currentList = lists [ lists . indexOf ( line . slice ( 4 ) ) ] ;
35+ currentList = line . slice ( 4 ) ;
2736 previousGithubHandle = null ;
2837 } else if ( line . startsWith ( '#### ' ) ) {
29- currentList = lists [ lists . indexOf ( line . slice ( 5 ) ) ] ;
38+ currentList = line . slice ( 5 ) ;
3039 previousGithubHandle = null ;
31- } else if ( currentList && line . startsWith ( '* [' ) ) {
32- const currentGithubHandle = line . slice ( 3 , line . indexOf ( ']' ) ) . toLowerCase ( ) ;
33- if ( previousGithubHandle && previousGithubHandle >= currentGithubHandle ) {
34- throw new Error ( `${ currentGithubHandle } should be listed before ${ previousGithubHandle } in the ${ currentList } list (README.md:${ lineNumber } )` ) ;
40+ } else if ( currentList in lists && line . startsWith ( '* [' ) ) {
41+ const currentGithubHandle = line . slice ( 3 , line . indexOf ( ']' ) ) ;
42+ const currentGithubHandleLowerCase = currentGithubHandle . toLowerCase ( ) ;
43+ if (
44+ previousGithubHandle &&
45+ previousGithubHandle >= currentGithubHandleLowerCase
46+ ) {
47+ throw new Error (
48+ `${ currentGithubHandle } should be listed before ${ previousGithubHandle } in the ${ currentList } list (README.md:${ lineNumber } )` ,
49+ ) ;
3550 }
3651
37- if ( currentList === 'TSC voting members' || currentList === 'TSC regular members' ) {
52+ if (
53+ currentList === 'TSC voting members' ||
54+ currentList === 'TSC regular members'
55+ ) {
3856 tscMembers . add ( currentGithubHandle ) ;
3957 } else if ( currentList === 'Collaborators' ) {
4058 tscMembers . delete ( currentGithubHandle ) ;
4159 }
42- previousGithubHandle = currentGithubHandle ;
60+ if ( lists [ currentList ] ) {
61+ ( actualMembers [ lists [ currentList ] ] ??= new Set ( ) ) . add ( currentGithubHandle ) ;
62+ }
63+ previousGithubHandle = currentGithubHandleLowerCase ;
4364 }
4465}
66+ console . info ( 'Lists are in the alphabetical order.' ) ;
67+
68+ assert . deepStrictEqual ( tscMembers , new Set ( ) , 'Some TSC members are not listed as Collaborators' ) ;
4569
46- if ( tscMembers . size !== 0 ) {
47- throw new Error ( `Some TSC members are not listed as Collaborators: ${ Array . from ( tscMembers ) } ` ) ;
70+ if ( argv [ 2 ] && argv [ 2 ] !== '{}' ) {
71+ const reviver = ( _ , value ) =>
72+ ( typeof value === 'string' && value [ 0 ] === '[' && value . at ( - 1 ) === ']' ?
73+ new Set ( JSON . parse ( value ) ) :
74+ value ) ;
75+ assert . deepStrictEqual ( JSON . parse ( argv [ 2 ] , reviver ) , { ...actualMembers } ) ;
76+ } else {
77+ console . warn ( 'Skipping the check of GitHub teams membership.' ) ;
4878}
0 commit comments