1
1
#!/usr/bin/env node
2
2
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 .
4
4
5
+ import assert from 'node:assert' ;
5
6
import { open } from 'node:fs/promises' ;
7
+ import { argv } from 'node:process' ;
6
8
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
+ } ;
15
24
const tscMembers = new Set ( ) ;
16
25
17
26
const readme = await open ( new URL ( '../README.md' , import . meta. url ) , 'r' ) ;
@@ -23,26 +32,47 @@ let lineNumber = 0;
23
32
for await ( const line of readme . readLines ( ) ) {
24
33
lineNumber ++ ;
25
34
if ( line . startsWith ( '### ' ) ) {
26
- currentList = lists [ lists . indexOf ( line . slice ( 4 ) ) ] ;
35
+ currentList = line . slice ( 4 ) ;
27
36
previousGithubHandle = null ;
28
37
} else if ( line . startsWith ( '#### ' ) ) {
29
- currentList = lists [ lists . indexOf ( line . slice ( 5 ) ) ] ;
38
+ currentList = line . slice ( 5 ) ;
30
39
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
+ ) ;
35
50
}
36
51
37
- if ( currentList === 'TSC voting members' || currentList === 'TSC regular members' ) {
52
+ if (
53
+ currentList === 'TSC voting members' ||
54
+ currentList === 'TSC regular members'
55
+ ) {
38
56
tscMembers . add ( currentGithubHandle ) ;
39
57
} else if ( currentList === 'Collaborators' ) {
40
58
tscMembers . delete ( currentGithubHandle ) ;
41
59
}
42
- previousGithubHandle = currentGithubHandle ;
60
+ if ( lists [ currentList ] ) {
61
+ ( actualMembers [ lists [ currentList ] ] ??= new Set ( ) ) . add ( currentGithubHandle ) ;
62
+ }
63
+ previousGithubHandle = currentGithubHandleLowerCase ;
43
64
}
44
65
}
66
+ console . info ( 'Lists are in the alphabetical order.' ) ;
67
+
68
+ assert . deepStrictEqual ( tscMembers , new Set ( ) , 'Some TSC members are not listed as Collaborators' ) ;
45
69
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.' ) ;
48
78
}
0 commit comments