Skip to content

Commit dbaac1b

Browse files
authored
scripts/retire.sh: use commits endpoint rather than activity (#73)
2 parents 4543841 + 9c08aaf commit dbaac1b

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
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/common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set -euo pipefail
22

3+
export TZ=UTC
4+
35
log() {
46
echo "$@" >&2
57
}

scripts/retire.sh

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ cd "$DIR"
5959
for login in *; do
6060

6161
# Figure out when this person received the commit bit
62-
# Get the unix epoch of the first commit that touched this file
62+
# Get the unix epoch of the last commit that added this file
6363
# --first-parent is important to get the time of when the main branch was changed
64-
fileCommitEpoch=$(git log --reverse --first-parent --format=%cd --date=unix -- "$login" | head -1)
64+
fileCommitEpoch=$(git log \
65+
--first-parent \
66+
--no-follow \
67+
--diff-filter=A \
68+
--max-count=1 \
69+
--format=%cd \
70+
--date=unix \
71+
-- "$login")
6572
if (( fileCommitEpoch < createdOnReceptionEpoch )); then
6673
# If it was created before creation actually matched the reception date
6774
# This branch can be removed after 2026-04-23
@@ -101,22 +108,20 @@ for login in *; do
101108
continue
102109
fi
103110

104-
trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/activity \
105-
-f time_period=year \
106-
-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 \
107116
-f per_page=100 \
108117
--jq '.[] |
109-
"- \(.timestamp) [\(.activity_type) on \(.ref | ltrimstr("refs/heads/"))](https://github.com/'"$ORG/$ACTIVITY_REPO"'/\(
110-
if .activity_type == "branch_creation" then
111-
"commit/\(.after)"
112-
elif .activity_type == "branch_deletion" then
113-
"commit/\(.before)"
114-
else
115-
"compare/\(.before)...\(.after)"
116-
end
117-
))"' \
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)"' \
118123
> "$tmp/$login"
119-
activityCount=$(wc -l <"$tmp/$login")
124+
mergeCount=$(wc -l <"$tmp/$login")
120125

121126
if [[ "$prState" == open ]]; then
122127
# If there is an open PR already
@@ -126,7 +131,7 @@ for login in *; do
126131
log "$login has a retirement PR due, unmarking PR as draft and commenting with next steps"
127132
effect gh pr ready --repo "$ORG/$MEMBER_REPO" "$prNumber"
128133
{
129-
if (( activityCount > 0 )); then
134+
if (( mergeCount > 0 )); then
130135
echo "One month has passed, and @$login has been active again:"
131136
cat "$tmp/$login"
132137
echo ""
@@ -151,7 +156,7 @@ for login in *; do
151156
else
152157
log "$login has a retirement PR pending"
153158
fi
154-
elif (( activityCount <= 0 )); then
159+
elif (( mergeCount <= 0 )); then
155160
log "$login has become inactive, opening a PR"
156161
# If there is no PR yet, but they have become inactive
157162
(
@@ -185,7 +190,7 @@ for login in *; do
185190
-f "labels[]=retirement" >/dev/null
186191
)
187192
else
188-
log "$login is active with $activityCount activities"
193+
log "$login is active with $mergeCount merges"
189194
fi
190195
log ""
191196
done

0 commit comments

Comments
 (0)