@@ -12,11 +12,14 @@ const CONFIG = {
1212const getDateMonthsAgo = ( months = CONFIG . INACTIVE_MONTHS ) => {
1313 const date = new Date ( ) ;
1414 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 ;
1618} ;
1719
1820// Check if there's already an open issue
1921async function hasOpenIssue ( github , context ) {
22+ console . log ( "Checking for existing open issues..." ) ;
2023 const { owner, repo } = context . repo ;
2124 const { data : issues } = await github . rest . issues . listForRepo ( {
2225 owner,
@@ -26,34 +29,52 @@ async function hasOpenIssue(github, context) {
2629 per_page : 1 ,
2730 } ) ;
2831
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 ;
3035}
3136
3237// Parse collaborator usernames from governance file
3338async function parseCollaborators ( ) {
39+ console . log ( `Reading collaborators from ${ CONFIG . FILE } ...` ) ;
3440 const content = await readFile ( CONFIG . FILE , "utf8" ) ;
3541 const lines = content . split ( "\n" ) ;
3642 const collaborators = [ ] ;
3743
3844 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+ }
4051
4152 for ( let i = startIndex ; i < lines . length ; i ++ ) {
4253 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+ }
4458
4559 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+ }
4764 }
4865
66+ console . log ( `Total collaborators found: ${ collaborators . length } ` ) ;
4967 return collaborators ;
5068}
5169
5270// Check if users have been active since cutoff date
5371async function getInactiveUsers ( github , usernames , repo , cutoffDate ) {
72+ console . log ( `Checking activity for ${ usernames . length } users since ${ cutoffDate } ...` ) ;
5473 const inactiveUsers = [ ] ;
5574
5675 for ( const username of usernames ) {
76+ console . log ( `Checking activity for ${ username } ...` ) ;
77+
5778 // Check commits
5879 const { data : commits } = await github . rest . search . commits ( {
5980 q : `author:${ username } repo:${ repo } committer-date:>=${ cutoffDate } ` ,
@@ -62,25 +83,36 @@ async function getInactiveUsers(github, usernames, repo, cutoffDate) {
6283
6384 // Check issues and PRs
6485 const { data : issues } = await github . rest . search . issuesAndPullRequests ( {
65- q : `involves :${ username } repo:${ repo } updated:>=${ cutoffDate } ` ,
86+ q : `commenter :${ username } repo:${ repo } updated:>=${ cutoffDate } ` ,
6687 per_page : 1 ,
6788 } ) ;
6889
90+ console . log ( `${ username } : ${ commits . total_count } commits, ${ issues . total_count } issues/PRs` ) ;
91+
6992 // User is inactive if they have no commits AND no issues/PRs
7093 if ( commits . total_count === 0 && issues . total_count === 0 ) {
7194 inactiveUsers . push ( username ) ;
95+ console . log ( `${ username } is inactive` ) ;
96+ } else {
97+ console . log ( `${ username } is active` ) ;
7298 }
7399 }
74100
101+ console . log ( `Total inactive users: ${ inactiveUsers . length } ` ) ;
75102 return inactiveUsers ;
76103}
77104
78105// Generate report for inactive members
79106function 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+ }
81113
82114 const today = getDateMonthsAgo ( 0 ) ;
83- return `# Inactive Collaborators Report
115+ const report = `# Inactive Collaborators Report
84116
85117Last updated: ${ today }
86118Checking for inactivity since: ${ cutoffDate }
@@ -94,11 +126,18 @@ ${inactiveMembers.map((m) => `| @${m} |`).join("\n")}
94126## What happens next?
95127
96128@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 ;
97132}
98133
99134async function createIssue ( github , context , report ) {
100- if ( ! report ) return ;
135+ if ( ! report ) {
136+ console . log ( "No report to create issue from" ) ;
137+ return ;
138+ }
101139
140+ console . log ( "Creating new issue..." ) ;
102141 const { owner, repo } = context . repo ;
103142 await github . rest . issues . create ( {
104143 owner,
@@ -107,17 +146,26 @@ async function createIssue(github, context, report) {
107146 body : report ,
108147 labels : CONFIG . ISSUE_LABELS ,
109148 } ) ;
149+ console . log ( "Issue created successfully" ) ;
110150}
111151
112152export default async function ( github , context ) {
153+ console . log ( "Starting inactive collaborator check..." ) ;
154+
113155 // Check for existing open issue first - exit early if one exists
114156 if ( await hasOpenIssue ( github , context ) ) {
157+ console . log ( "Open issue already exists, exiting early" ) ;
115158 return ;
116159 }
117160
118161 const cutoffDate = getDateMonthsAgo ( ) ;
119162 const collaborators = await parseCollaborators ( ) ;
120163
164+ if ( collaborators . length === 0 ) {
165+ console . log ( "No collaborators found, exiting" ) ;
166+ return ;
167+ }
168+
121169 const inactiveMembers = await getInactiveUsers (
122170 github ,
123171 collaborators ,
@@ -127,4 +175,5 @@ export default async function (github, context) {
127175 const report = formatReport ( inactiveMembers , cutoffDate ) ;
128176
129177 await createIssue ( github , context , report ) ;
178+ console . log ( "Inactive collaborator check completed" ) ;
130179}
0 commit comments