22const fs = require ( 'fs' ) ;
33const getTeamMembers = require ( '../../utils/get-team-members' ) ;
44const addTeamMember = require ( '../../utils/add-team-member' ) ;
5+ const getOpenAssignedIssues = require ( '../../utils/get-open-assigned-issues' ) ;
56
67// Global variables
78var github ;
@@ -10,6 +11,7 @@ var context;
1011const baseTeam = 'website' ;
1112const writeTeam = 'website-write' ;
1213const mergeTeam = 'website-merge' ;
14+ const PMTeam = 'website-pm' ;
1315
1416
1517
@@ -21,10 +23,11 @@ const mergeTeam = 'website-merge';
2123 * @param {Object } c - context object from actions/github-script
2224 * @param {Object } recentContributors - recentContributors since the dates[0] = recent cutoff
2325 * @param {Object } previousContributors - previousContributors since the dates[1] = previous cutoff
26+ * @param {Object } inactiveWithOpenSkills- Inactive contributors that have open Skills issues
2427 * @param {Object } inactiveWithOpenIssue - Inactive contributors that have open issues
2528 * @param {Object } dates - [recent, previous] dates of oneMonthAgo, twoMonthsAgo
2629 */
27- async function main ( { g, c } , { recentContributors, previousContributors, inactiveWithOpenIssue, dates } ) {
30+ async function main ( { g, c } , { recentContributors, previousContributors, inactiveWithOpenSkills , inactiveWithOpenIssue, dates } ) {
2831 github = g ;
2932 context = c ;
3033
@@ -33,69 +36,71 @@ async function main({ g, c }, { recentContributors, previousContributors, inacti
3336 console . log ( 'Current members of ' + writeTeam + ':' ) ;
3437 console . log ( currentTeamMembers ) ;
3538
36- const [ removedContributors , cannotRemoveYet ] = await removeInactiveMembers ( previousContributors , inactiveWithOpenIssue , currentTeamMembers ) ;
39+ const removedContributors = await removeInactiveMembers ( previousContributors , inactiveWithOpenSkills , inactiveWithOpenIssue , currentTeamMembers ) ;
3740 console . log ( `-` . repeat ( 60 ) ) ;
3841 console . log ( 'Removed members from ' + writeTeam + ' inactive since ' + dates [ 1 ] . slice ( 0 , 10 ) + ':' ) ;
3942 console . log ( removedContributors ) ;
4043
41- console . log ( `-` . repeat ( 60 ) ) ;
42- console . log ( 'Members inactive since ' + dates [ 1 ] . slice ( 0 , 10 ) + ' with open issues preventing removal:' ) ;
43- console . log ( cannotRemoveYet ) ;
44-
4544 // Repeat getTeamMembers() after removedContributors to compare with recentContributors
4645 const updatedTeamMembers = await getTeamMembers ( github , context , writeTeam ) ;
4746 const notifiedContributors = await notifyInactiveMembers ( updatedTeamMembers , recentContributors ) ;
4847 console . log ( `-` . repeat ( 60 ) ) ;
4948 console . log ( 'Notified members from ' + writeTeam + ' inactive since ' + dates [ 0 ] . slice ( 0 , 10 ) + ':' ) ;
5049 console . log ( notifiedContributors ) ;
5150
52- writeData ( removedContributors , notifiedContributors , cannotRemoveYet ) ;
51+ // Final pass to get all open, assigned issues to check whether assignee either isn't a team member or is inactive
52+ const currentPMTeam = await getTeamMembers ( github , context , PMTeam ) ;
53+ const writeAndPMTeam = { ...updatedTeamMembers , ...currentPMTeam } ;
54+ const [ nonTeamOpenIssue , inactiveOpenIssue ] = await getOpenAssignedIssues ( github , context , writeAndPMTeam , inactiveWithOpenIssue ) ;
55+ console . log ( `-` . repeat ( 60 ) ) ;
56+ console . log ( 'Members inactive since ' + dates [ 1 ] . slice ( 0 , 10 ) + ' with open issues preventing removal:' ) ;
57+ console . log ( inactiveOpenIssue ) ;
58+
59+ writeData ( removedContributors , notifiedContributors , nonTeamOpenIssue , inactiveOpenIssue ) ;
5360} ;
5461
5562
5663
5764/**
5865 * Remove contributors that were last active **before** the previous (twoMonthsAgo) date
5966 * @param {Object } previousContributors - List of contributors active since previous date
67+ * @param {Object } inactiveWithOpenSkills - Inactive members with open Skills Issue
6068 * @param {Object } inactiveWithOpenIssue - Inactive members with open issues
61- * @returns { Array } removedMembers - List of members that were removed
62- * @returns {Object } cannotRemoveYet - List of members that cannot be removed due to open issues
69+ * @param { Object } currentTeamMembers - Current team members
70+ * @returns {Object } removedMembers - List of members that were removed
6371 */
64- async function removeInactiveMembers ( previousContributors , inactiveWithOpenIssue , currentTeamMembers ) {
72+ async function removeInactiveMembers ( previousContributors , inactiveWithOpenSkills , inactiveWithOpenIssue , currentTeamMembers ) {
6573 const removedMembers = [ ] ;
66- const cannotRemoveYet = { } ;
6774 const previouslyNotified = await readPreviousNotifyList ( ) ;
6875
69- // Loop over team members and remove them from the team if they are not in previousContributors list
70- for ( const username in currentTeamMembers ) {
71- if ( ! previousContributors [ username ] ) {
76+ // Loop over team members and remove them from the team if they
77+ // are not in either previousContributors or inactiveWithOpenIssue
78+ for ( const username in currentTeamMembers ) {
79+ if ( ( ! previousContributors [ username ] ) || ! ( username in inactiveWithOpenIssue ) ) {
7280 // Prior to deletion, confirm that member is on the baseTeam
7381 await addTeamMember ( github , context , baseTeam , username ) ;
74- // But if member has an open issue or was not on the previouslyNotified list, do not remove yet
75- if ( username in inactiveWithOpenIssue && inactiveWithOpenIssue [ username ] [ 1 ] === false ) {
76- cannotRemoveYet [ username ] = inactiveWithOpenIssue [ username ] [ 0 ] ;
77- } else if ( ( previouslyNotified . length > 0 ) && ! ( previouslyNotified . includes ( username ) ) ) {
78- console . log ( 'Member was not on last month\'s \'Inactive Members\' list, do not remove: ' + username ) ;
82+ // If member was not on the previouslyNotified list, do not remove yet
83+ if ( ( previouslyNotified . length > 0 ) && ! ( previouslyNotified . includes ( username ) ) ) {
84+ console . log ( `Member was not on last month's 'Inactive Members' list, do not remove: ${ username } ` ) ;
7985 } else {
8086 // Remove member from all teams (except baseTeam)
81- const teams = [ writeTeam , mergeTeam ] ;
82- for ( const team of teams ) {
87+ for ( const team of [ writeTeam , mergeTeam ] ) {
8388 // https://docs.github.com/en/rest/teams/members?apiVersion=2022-11-28#remove-team-membership-for-a-user
8489 await github . request ( 'DELETE /orgs/{org}/teams/{team_slug}/memberships/{username}' , {
8590 org : context . repo . owner ,
8691 team_slug : team ,
87- username : username ,
92+ username,
8893 } ) ;
8994 }
9095 removedMembers . push ( username ) ;
9196 // After removal, close member's "Skills Issue", if open
92- if ( username in inactiveWithOpenIssue && inactiveWithOpenIssue [ username ] [ 1 ] === true ) {
93- closePrework ( username , inactiveWithOpenIssue [ username ] [ 0 ] ) ;
97+ if ( username in inactiveWithOpenSkills ) {
98+ closePrework ( username , inactiveWithOpenSkills [ username ] ) ;
9499 }
95100 }
96101 }
97102 }
98- return [ removedMembers , cannotRemoveYet ] ;
103+ return removedMembers ;
99104}
100105
101106
@@ -200,14 +205,15 @@ async function checkMemberIsNotNew(member){
200205
201206/**
202207 * Function to save inactive members list to local repo for use in next job
203- * @param {Array } removedContributors - List of contributors that were removed
204- * @param {Array } notifiedContributors - List of contributors to be notified
205- * @param {Array } cannotRemoveYet - List of contributors that can't be removed yet
208+ * @param {Array } removedContributors - List of contributors that were removed
209+ * @param {Array } notifiedContributors - List of contributors to be notified
210+ * @param {Array } nonTeamOpenIssue - List of non-team members with open issues
211+ * @param {Array } inactiveOpenIssue - List of inactive members that can't be removed yet
206212 */
207- function writeData ( removedContributors , notifiedContributors , cannotRemoveYet ) {
213+ function writeData ( removedContributors , notifiedContributors , nonTeamOpenIssue , inactiveOpenIssue ) {
208214
209215 const filepath = 'github-actions/utils/_data/inactive-members.json' ;
210- const inactiveMemberLists = { removedContributors, notifiedContributors, cannotRemoveYet } ;
216+ const inactiveMemberLists = { removedContributors, notifiedContributors, nonTeamOpenIssue , inactiveOpenIssue } ;
211217
212218 fs . writeFile ( filepath , JSON . stringify ( inactiveMemberLists , null , 2 ) , ( err ) => {
213219 if ( err ) throw err ;
0 commit comments