@@ -26,7 +26,7 @@ effect() {
2626}
2727
2828usage () {
29- log " Usage: $0 ORG ACTIVITY_REPO MEMBER_REPO DIR NOTICE_CUTOFF"
29+ log " Usage: $0 ORG ACTIVITY_REPO MEMBER_REPO DIR NOTICE_CUTOFF CLOSE_CUTOFF "
3030 exit 1
3131}
3232
@@ -35,12 +35,15 @@ ACTIVITY_REPO=${2:-$(usage)}
3535MEMBER_REPO=${3:- $(usage)}
3636DIR=${4:- $(usage)}
3737NOTICE_CUTOFF=${5:- $(usage)}
38+ CLOSE_CUTOFF=${6:- $(usage)}
3839
3940mainBranch=$( git branch --show-current)
4041noticeCutoff=$( date --date=" $NOTICE_CUTOFF " +%s)
4142
4243# People that received the commit bit after this date won't be retired
4344newCutoff=$( date --date=" 1 year ago" +%s)
45+ # Users whose retirement PRs were closed after this date won't be retired
46+ closeCutoff=$( date --date=" $CLOSE_CUTOFF " +%s)
4447
4548# We need to know when people received their commit bit to avoid retiring them within the first year.
4649# For now this is done either with the git creation date of the file, or its contents:
@@ -96,6 +99,23 @@ for login in *; do
9699 receptionEpoch=$fileCommitEpoch
97100 fi
98101
102+ # Latest retirement PR, whether draft, open or closed
103+ branchName=retire-$login
104+ prInfo=$( trace gh api -X GET /repos/" $ORG " /" $MEMBER_REPO " /pulls \
105+ -f state=all \
106+ -f head=" $ORG " :" $branchName " \
107+ --jq ' .[0]' )
108+ if [[ -n " $prInfo " ]]; then
109+ prState=$( jq -r .state <<< " $prInfo" )
110+ else
111+ prState=none
112+ fi
113+
114+ if [[ " $prState " == closed ]] && resetEpoch=$( jq ' .closed_at | fromdateiso8601' <<< " $prInfo" ) && (( closeCutoff < resetEpoch )) ; then
115+ log " $login had a retirement PR that was closed recently, skipping retirement check"
116+ continue
117+ fi
118+
99119 # If the commit bit was received after the cutoff date, don't retire in any case
100120 if (( newCutoff < receptionEpoch )) ; then
101121 log " $login became a committer less than 1 year ago, skipping retirement check"
@@ -119,12 +139,10 @@ for login in *; do
119139 > " $tmp /$login "
120140 activityCount=$( wc -l < " $tmp /$login " )
121141
122- branchName=retire-$login
123- prInfo=$( trace gh api -X GET /repos/" $ORG " /" $MEMBER_REPO " /pulls -f head=" $ORG " :" $branchName " --jq ' .[0]' )
124- if [[ -n " $prInfo " ]]; then
125- # If there is a PR already
142+ if [[ " $prState " == open ]]; then
143+ # If there is an open PR already
126144 prNumber=$( jq .number <<< " $prInfo" )
127- epochCreatedAt=$( date --date= " $( jq -r .created_at <<< " $prInfo" ) " +%s )
145+ epochCreatedAt=$( jq ' .created_at | fromdateiso8601 ' <<< " $prInfo" )
128146 if jq -e .draft <<< " $prInfo" > /dev/null && (( epochCreatedAt < noticeCutoff )) ; then
129147 log " $login has a retirement PR due, unmarking PR as draft and commenting with next steps"
130148 effect gh pr ready --repo " $ORG /$MEMBER_REPO " " $prNumber "
0 commit comments