@@ -12,11 +12,14 @@ const CONFIG = {
12
12
const getDateMonthsAgo = ( months = CONFIG . INACTIVE_MONTHS ) => {
13
13
const date = new Date ( ) ;
14
14
date . setMonth ( date . getMonth ( ) - months ) ;
15
- return date . toISOString ( ) . split ( "T" ) [ 0 ] ;
15
+ const result = date . toISOString ( ) . split ( "T" ) [ 0 ] ;
16
+ console . log ( `getDateMonthsAgo(${ months } ): ${ result } ` ) ;
17
+ return result ;
16
18
} ;
17
19
18
20
// Check if there's already an open issue
19
21
async function hasOpenIssue ( github , context ) {
22
+ console . log ( "Checking for existing open issues..." ) ;
20
23
const { owner, repo } = context . repo ;
21
24
const { data : issues } = await github . rest . issues . listForRepo ( {
22
25
owner,
@@ -26,34 +29,52 @@ async function hasOpenIssue(github, context) {
26
29
per_page : 1 ,
27
30
} ) ;
28
31
29
- return issues . length > 0 ;
32
+ const hasIssue = issues . length > 0 ;
33
+ console . log ( `Found ${ issues . length } open issues with label "${ CONFIG . ISSUE_LABELS [ 1 ] } "` ) ;
34
+ return hasIssue ;
30
35
}
31
36
32
37
// Parse collaborator usernames from governance file
33
38
async function parseCollaborators ( ) {
39
+ console . log ( `Reading collaborators from ${ CONFIG . FILE } ...` ) ;
34
40
const content = await readFile ( CONFIG . FILE , "utf8" ) ;
35
41
const lines = content . split ( "\n" ) ;
36
42
const collaborators = [ ] ;
37
43
38
44
const startIndex = lines . findIndex ( ( l ) => l . startsWith ( CONFIG . HEADER ) ) + 1 ;
39
- if ( startIndex <= 0 ) return collaborators ;
45
+ console . log ( `Header found at line ${ startIndex - 1 } , starting parse at line ${ startIndex } ` ) ;
46
+
47
+ if ( startIndex <= 0 ) {
48
+ console . log ( "Header not found, returning empty collaborators array" ) ;
49
+ return collaborators ;
50
+ }
40
51
41
52
for ( let i = startIndex ; i < lines . length ; i ++ ) {
42
53
const line = lines [ i ] ;
43
- if ( line . startsWith ( "#" ) ) break ;
54
+ if ( line . startsWith ( "#" ) ) {
55
+ console . log ( `Reached next section at line ${ i } , stopping parse` ) ;
56
+ break ;
57
+ }
44
58
45
59
const match = line . match ( / ^ \s * - \s * \[ ( [ ^ \] ] + ) \] / ) ;
46
- if ( match ) collaborators . push ( match [ 1 ] ) ;
60
+ if ( match ) {
61
+ collaborators . push ( match [ 1 ] . slice ( 1 ) ) ;
62
+ console . log ( `Found collaborator: ${ match [ 1 ] } ` ) ;
63
+ }
47
64
}
48
65
66
+ console . log ( `Total collaborators found: ${ collaborators . length } ` ) ;
49
67
return collaborators ;
50
68
}
51
69
52
70
// Check if users have been active since cutoff date
53
71
async function getInactiveUsers ( github , usernames , repo , cutoffDate ) {
72
+ console . log ( `Checking activity for ${ usernames . length } users since ${ cutoffDate } ...` ) ;
54
73
const inactiveUsers = [ ] ;
55
74
56
75
for ( const username of usernames ) {
76
+ console . log ( `Checking activity for ${ username } ...` ) ;
77
+
57
78
// Check commits
58
79
const { data : commits } = await github . rest . search . commits ( {
59
80
q : `author:${ username } repo:${ repo } committer-date:>=${ cutoffDate } ` ,
@@ -62,25 +83,36 @@ async function getInactiveUsers(github, usernames, repo, cutoffDate) {
62
83
63
84
// Check issues and PRs
64
85
const { data : issues } = await github . rest . search . issuesAndPullRequests ( {
65
- q : `involves :${ username } repo:${ repo } updated:>=${ cutoffDate } ` ,
86
+ q : `commenter :${ username } repo:${ repo } updated:>=${ cutoffDate } ` ,
66
87
per_page : 1 ,
67
88
} ) ;
68
89
90
+ console . log ( `${ username } : ${ commits . total_count } commits, ${ issues . total_count } issues/PRs` ) ;
91
+
69
92
// User is inactive if they have no commits AND no issues/PRs
70
93
if ( commits . total_count === 0 && issues . total_count === 0 ) {
71
94
inactiveUsers . push ( username ) ;
95
+ console . log ( `${ username } is inactive` ) ;
96
+ } else {
97
+ console . log ( `${ username } is active` ) ;
72
98
}
73
99
}
74
100
101
+ console . log ( `Total inactive users: ${ inactiveUsers . length } ` ) ;
75
102
return inactiveUsers ;
76
103
}
77
104
78
105
// Generate report for inactive members
79
106
function formatReport ( inactiveMembers , cutoffDate ) {
80
- if ( ! inactiveMembers . length ) return null ;
107
+ console . log ( `Formatting report for ${ inactiveMembers . length } inactive members...` ) ;
108
+
109
+ if ( ! inactiveMembers . length ) {
110
+ console . log ( "No inactive members found, skipping report generation" ) ;
111
+ return null ;
112
+ }
81
113
82
114
const today = getDateMonthsAgo ( 0 ) ;
83
- return `# Inactive Collaborators Report
115
+ const report = `# Inactive Collaborators Report
84
116
85
117
Last updated: ${ today }
86
118
Checking for inactivity since: ${ cutoffDate }
@@ -94,11 +126,18 @@ ${inactiveMembers.map((m) => `| @${m} |`).join("\n")}
94
126
## What happens next?
95
127
96
128
@nodejs/nodejs-website should review this list and contact inactive collaborators to confirm their continued interest in participating in the project.` ;
129
+
130
+ console . log ( "Report generated successfully" ) ;
131
+ return report ;
97
132
}
98
133
99
134
async function createIssue ( github , context , report ) {
100
- if ( ! report ) return ;
135
+ if ( ! report ) {
136
+ console . log ( "No report to create issue from" ) ;
137
+ return ;
138
+ }
101
139
140
+ console . log ( "Creating new issue..." ) ;
102
141
const { owner, repo } = context . repo ;
103
142
await github . rest . issues . create ( {
104
143
owner,
@@ -107,17 +146,26 @@ async function createIssue(github, context, report) {
107
146
body : report ,
108
147
labels : CONFIG . ISSUE_LABELS ,
109
148
} ) ;
149
+ console . log ( "Issue created successfully" ) ;
110
150
}
111
151
112
152
export default async function ( github , context ) {
153
+ console . log ( "Starting inactive collaborator check..." ) ;
154
+
113
155
// Check for existing open issue first - exit early if one exists
114
156
if ( await hasOpenIssue ( github , context ) ) {
157
+ console . log ( "Open issue already exists, exiting early" ) ;
115
158
return ;
116
159
}
117
160
118
161
const cutoffDate = getDateMonthsAgo ( ) ;
119
162
const collaborators = await parseCollaborators ( ) ;
120
163
164
+ if ( collaborators . length === 0 ) {
165
+ console . log ( "No collaborators found, exiting" ) ;
166
+ return ;
167
+ }
168
+
121
169
const inactiveMembers = await getInactiveUsers (
122
170
github ,
123
171
collaborators ,
@@ -127,4 +175,5 @@ export default async function (github, context) {
127
175
const report = formatReport ( inactiveMembers , cutoffDate ) ;
128
176
129
177
await createIssue ( github , context , report ) ;
178
+ console . log ( "Inactive collaborator check completed" ) ;
130
179
}
0 commit comments