Skip to content

Commit d5666d6

Browse files
authored
Merge pull request #45 from NixOS/delay-retire
Implement retirement delay by closing PR
2 parents e13f399 + eaadc3f commit d5666d6

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

.github/workflows/retire.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ jobs:
3737
# Fetch full history to determine when committers were added
3838
fetch-depth: 0
3939
- name: Run script
40-
# One month plus a bit of leeway
41-
run: scripts/retire.sh NixOS nixpkgs nixpkgs-committers members "yesterday 1 month ago"
40+
run: scripts/retire.sh NixOS nixpkgs nixpkgs-committers members "yesterday 1 month ago" "1 year ago"
4241
env:
4342
GH_TOKEN: ${{ steps.app-token.outputs.token }}
4443
PROD: "1"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ The PR will ping the user and inform them that it will by default be merged and
2828
If the PR is still open one month later,
2929
an automated comment will be posted with the next steps for the Nixpkgs commit delegators.
3030

31+
If the PR is closed, retirement is delayed by another year.
32+
3133
## Automation setup
3234

3335
Automation depends on a GitHub App with the following permissions:

scripts/README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,40 +72,47 @@ The following sequence tests all code paths:
7272

7373
1. Run the script with the `active` repo argument to simulate CI running without inactive users:
7474
```bash
75-
scripts/retire.sh infinisil-test-org active nixpkgs-committers members-test 'yesterday 1 month ago'
75+
scripts/retire.sh infinisil-test-org active nixpkgs-committers members-test 'yesterday 1 month ago' now
7676
```
7777

7878
Check that no PR would be opened.
7979
2. Run the script with the `empty` repo argument to simulate CI running with inactive users:
8080

8181
```bash
82-
scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago'
82+
scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago' now
8383
```
8484

8585
Check that it would only create a PR for your own user and not the "new-committer-1" or "new-committer-2" user before running it again with `PROD=1` to actually do it:
8686

8787
```bash
88-
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago'
88+
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago' now
8989
```
9090

9191
Check that it created the PR appropriately, including assigning the "retirement" label.
9292
You can undo this step by closing the PR.
9393
3. Run it again to simulate CI running again later:
9494
```bash
95-
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago'
95+
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test 'yesterday 1 month ago' now
9696
```
9797
Check that no other PR is opened.
98-
4. Run it again with `now` as the date to simulate the time interval passing:
98+
4. Run it again with `now` as the notice cutoff date to simulate the time interval passing:
9999
```bash
100-
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now
100+
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now now
101101
```
102102
Check that it undrafted the previous PR and posted an appropriate comment.
103103
5. Run it again to simulate CI running again later:
104104
```bash
105-
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now
105+
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now now
106106
```
107-
6. Reset by marking the PR as a draft again.
108-
7. Run it again with the `active` repo argument to simulate activity during the time interval:
107+
Check that no other PR is opened.
108+
6. Reset by marking the PR as a draft again, then run it again with the `active` repo argument to simulate activity during the time interval:
109+
```bash
110+
PROD=1 scripts/retire.sh infinisil-test-org active nixpkgs-committers members-test now now
111+
```
112+
Check that it gets undrafted with a comment listing the new activity.
113+
8. Close the PR, then run the script again with no activity and for an earlier close cutoff, simulating that the retirement was delayed:
109114
```bash
110-
PROD=1 scripts/retire.sh infinisil-test-org active nixpkgs-committers members-test now
115+
PROD=1 scripts/retire.sh infinisil-test-org empty nixpkgs-committers members-test now '1 day ago'
111116
```
117+
118+
Check that no other PR is opened.

scripts/retire.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ effect() {
2626
}
2727

2828
usage() {
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)}
3535
MEMBER_REPO=${3:-$(usage)}
3636
DIR=${4:-$(usage)}
3737
NOTICE_CUTOFF=${5:-$(usage)}
38+
CLOSE_CUTOFF=${6:-$(usage)}
3839

3940
mainBranch=$(git branch --show-current)
4041
noticeCutoff=$(date --date="$NOTICE_CUTOFF" +%s)
4142

4243
# People that received the commit bit after this date won't be retired
4344
newCutoff=$(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

Comments
 (0)