diff --git a/scripts/README.md b/scripts/README.md index c476b32..6e3b118 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -10,7 +10,7 @@ whose identifiers will be used here. - [infinisil-test-org](https://github.com/infinisil-test-org): A GitHub organisation you're part of - Repositories: - - [infinisil-test-org/empty](https://github.com/infinisil-test-org/empty): An empty one with no activity on it + - [infinisil-test-org/empty](https://github.com/infinisil-test-org/empty): A repository with only one commit, not attributed to your GitHub user - [infinisil-test-org/active](https://github.com/infinisil-test-org/active): One where you have some activity - [infinisil-test-org/nixpkgs-committers](https://github.com/infinisil-test-org/nixpkgs-committers): A fork of the upstream repo @@ -22,7 +22,7 @@ whose identifiers will be used here. Once you have the above setup (or got @infinisil to add yourself to his), you have to prepare the following: - Add some activity of yours to the `active` repo. - To cover all code branches it's recommended to create, push to and delete a branch. + 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. You can do this from the web interface. - Get the GitHub CLI available (`pkgs.github-cli`) and authenticate it using `gh auth login` - A local Git clone of this repository with the `origin` remote set to the test repository: diff --git a/scripts/common.sh b/scripts/common.sh index 1cd2c42..0d91611 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -1,5 +1,7 @@ set -euo pipefail +export TZ=UTC + log() { echo "$@" >&2 } diff --git a/scripts/retire.sh b/scripts/retire.sh index 88b3f01..cf144b5 100755 --- a/scripts/retire.sh +++ b/scripts/retire.sh @@ -59,9 +59,16 @@ cd "$DIR" for login in *; do # Figure out when this person received the commit bit - # Get the unix epoch of the first commit that touched this file + # Get the unix epoch of the last commit that added this file # --first-parent is important to get the time of when the main branch was changed - fileCommitEpoch=$(git log --reverse --first-parent --format=%cd --date=unix -- "$login" | head -1) + fileCommitEpoch=$(git log \ + --first-parent \ + --no-follow \ + --diff-filter=A \ + --max-count=1 \ + --format=%cd \ + --date=unix \ + -- "$login") if (( fileCommitEpoch < createdOnReceptionEpoch )); then # If it was created before creation actually matched the reception date # This branch can be removed after 2026-04-23 @@ -101,22 +108,20 @@ for login in *; do continue fi - trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/activity \ - -f time_period=year \ - -f actor="$login" \ + PR_PREFIX="$ORG/$ACTIVITY_REPO" \ + trace gh api -X GET /repos/"$ORG"/"$ACTIVITY_REPO"/commits \ + -f since="$(date --date='1 year ago' --iso-8601=seconds)" \ + -f author="$login" \ + -f committer=web-flow \ -f per_page=100 \ --jq '.[] | - "- \(.timestamp) [\(.activity_type) on \(.ref | ltrimstr("refs/heads/"))](https://github.com/'"$ORG/$ACTIVITY_REPO"'/\( - if .activity_type == "branch_creation" then - "commit/\(.after)" - elif .activity_type == "branch_deletion" then - "commit/\(.before)" - else - "compare/\(.before)...\(.after)" - end - ))"' \ + # PR merge commits have two parents. We also check it’s an + # authentic GitHub commit, because… why not? + select((.parents | length) == 2 and .commit.verification.verified) | + (.commit.message | capture(" \\((?#[0-9]+)\\)$").pr) as $pr | + "- `\(.commit.committer.date)` – \(env.PR_PREFIX)\($pr)"' \ > "$tmp/$login" - activityCount=$(wc -l <"$tmp/$login") + mergeCount=$(wc -l <"$tmp/$login") if [[ "$prState" == open ]]; then # If there is an open PR already @@ -126,7 +131,7 @@ for login in *; do log "$login has a retirement PR due, unmarking PR as draft and commenting with next steps" effect gh pr ready --repo "$ORG/$MEMBER_REPO" "$prNumber" { - if (( activityCount > 0 )); then + if (( mergeCount > 0 )); then echo "One month has passed, and @$login has been active again:" cat "$tmp/$login" echo "" @@ -151,7 +156,7 @@ for login in *; do else log "$login has a retirement PR pending" fi - elif (( activityCount <= 0 )); then + elif (( mergeCount <= 0 )); then log "$login has become inactive, opening a PR" # If there is no PR yet, but they have become inactive ( @@ -185,7 +190,7 @@ for login in *; do -f "labels[]=retirement" >/dev/null ) else - log "$login is active with $activityCount activities" + log "$login is active with $mergeCount merges" fi log "" done