Skip to content

Commit 9d29719

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 a80f8a8 commit 9d29719

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

scripts/retire.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,18 @@ for login in *; do
101101
continue
102102
fi
103103

104-
trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/activity \
105-
-f time_period=year \
106-
-f actor="$login" \
104+
trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/commits \
105+
-f since="$(date --date='1 year ago' --iso-8601=seconds)Z" \
106+
-f author="$login" \
107+
-f committer=web-flow \
107108
-f per_page=100 \
108109
--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-
))"' \
110+
# PR merge commits have two parents. We also check it’s an
111+
# authentic GitHub commit, because… why not?
112+
select((.parents | length) == 2 and .commit.verification.verified) |
113+
.sha' \
118114
> "$tmp/$login"
119-
activityCount=$(wc -l <"$tmp/$login")
115+
mergeCount=$(wc -l <"$tmp/$login")
120116

121117
if [[ "$prState" == open ]]; then
122118
# If there is an open PR already
@@ -126,9 +122,13 @@ for login in *; do
126122
log "$login has a retirement PR due, unmarking PR as draft and commenting with next steps"
127123
effect gh pr ready --repo "$ORG/$MEMBER_REPO" "$prNumber"
128124
{
129-
if (( activityCount > 0 )); then
125+
if (( mergeCount > 0 )); then
130126
echo "One month has passed, and @$login has been active again:"
131-
cat "$tmp/$login"
127+
while read -r sha; do
128+
gh api "/repos/$ORG/$ACTIVITY_REPO/commits/$sha/pulls" --jq '.[] |
129+
select(.merge_commit_sha == "'"$sha"'") |
130+
"- `\(.merged_at)` – \(.html_url)"'
131+
done < "$tmp/$login"
132132
echo ""
133133
echo "If still appropriate, this PR may be merged and implemented by:"
134134
else
@@ -151,7 +151,7 @@ for login in *; do
151151
else
152152
log "$login has a retirement PR pending"
153153
fi
154-
elif (( activityCount <= 0 )); then
154+
elif (( mergeCount <= 0 )); then
155155
log "$login has become inactive, opening a PR"
156156
# If there is no PR yet, but they have become inactive
157157
(
@@ -185,7 +185,7 @@ for login in *; do
185185
-f "labels[]=retirement" >/dev/null
186186
)
187187
else
188-
log "$login is active with $activityCount activities"
188+
log "$login is active with $mergeCount merges"
189189
fi
190190
log ""
191191
done

0 commit comments

Comments
 (0)