Skip to content

Commit 9c08aaf

Browse files
committed
scripts/retire.sh: use commits endpoint rather than activity
The activity endpoint does not work with the merge queue, and counts things like branch creations that we don’t really want to include. This finds two‐parent merge commits with the correct author committed and signed by the GitHub key that are reachable from the main branch; I believe that PR merges are the only such commits, but any exceptions should be very marginal. Closes: #69
1 parent 2a14cf5 commit 9c08aaf

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

scripts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ whose identifiers will be used here.
1010

1111
- [infinisil-test-org](https://github.com/infinisil-test-org): A GitHub organisation you're part of
1212
- Repositories:
13-
- [infinisil-test-org/empty](https://github.com/infinisil-test-org/empty): An empty one with no activity on it
13+
- [infinisil-test-org/empty](https://github.com/infinisil-test-org/empty): A repository with only one commit, not attributed to your GitHub user
1414
- [infinisil-test-org/active](https://github.com/infinisil-test-org/active): One where you have some activity
1515
- [infinisil-test-org/nixpkgs-committers](https://github.com/infinisil-test-org/nixpkgs-committers): A fork of the upstream repo
1616

@@ -22,7 +22,7 @@ whose identifiers will be used here.
2222
Once you have the above setup (or got @infinisil to add yourself to his), you have to prepare the following:
2323

2424
- Add some activity of yours to the `active` repo.
25-
To cover all code branches it's recommended to create, push to and delete a branch.
25+
To match Nixpkgs, it’s recommended to do this by setting the “Default commit message” for merge commits to “Pull request title”, then creating and merging a PR.
2626
You can do this from the web interface.
2727
- Get the GitHub CLI available (`pkgs.github-cli`) and authenticate it using `gh auth login`
2828
- A local Git clone of this repository with the `origin` remote set to the test repository:

scripts/retire.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,20 @@ for login in *; do
108108
continue
109109
fi
110110

111-
trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/activity \
112-
-f time_period=year \
113-
-f actor="$login" \
111+
PR_PREFIX="$ORG/$ACTIVITY_REPO" \
112+
trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/commits \
113+
-f since="$(date --date='1 year ago' --iso-8601=seconds)" \
114+
-f author="$login" \
115+
-f committer=web-flow \
114116
-f per_page=100 \
115117
--jq '.[] |
116-
"- \(.timestamp) [\(.activity_type) on \(.ref | ltrimstr("refs/heads/"))](https://github.com/'"$ORG/$ACTIVITY_REPO"'/\(
117-
if .activity_type == "branch_creation" then
118-
"commit/\(.after)"
119-
elif .activity_type == "branch_deletion" then
120-
"commit/\(.before)"
121-
else
122-
"compare/\(.before)...\(.after)"
123-
end
124-
))"' \
118+
# PR merge commits have two parents. We also check it’s an
119+
# authentic GitHub commit, because… why not?
120+
select((.parents | length) == 2 and .commit.verification.verified) |
121+
(.commit.message | capture(" \\((?<pr>#[0-9]+)\\)$").pr) as $pr |
122+
"- `\(.commit.committer.date)` – \(env.PR_PREFIX)\($pr)"' \
125123
> "$tmp/$login"
126-
activityCount=$(wc -l <"$tmp/$login")
124+
mergeCount=$(wc -l <"$tmp/$login")
127125

128126
if [[ "$prState" == open ]]; then
129127
# If there is an open PR already
@@ -133,7 +131,7 @@ for login in *; do
133131
log "$login has a retirement PR due, unmarking PR as draft and commenting with next steps"
134132
effect gh pr ready --repo "$ORG/$MEMBER_REPO" "$prNumber"
135133
{
136-
if (( activityCount > 0 )); then
134+
if (( mergeCount > 0 )); then
137135
echo "One month has passed, and @$login has been active again:"
138136
cat "$tmp/$login"
139137
echo ""
@@ -158,7 +156,7 @@ for login in *; do
158156
else
159157
log "$login has a retirement PR pending"
160158
fi
161-
elif (( activityCount <= 0 )); then
159+
elif (( mergeCount <= 0 )); then
162160
log "$login has become inactive, opening a PR"
163161
# If there is no PR yet, but they have become inactive
164162
(
@@ -192,7 +190,7 @@ for login in *; do
192190
-f "labels[]=retirement" >/dev/null
193191
)
194192
else
195-
log "$login is active with $activityCount activities"
193+
log "$login is active with $mergeCount merges"
196194
fi
197195
log ""
198196
done

0 commit comments

Comments
 (0)