Debian Codegraph @

.claude/skills/cut-release/scripts/contributors.sh

raw
1 #!/usr/bin/env bash
2 # Resolve "New Contributors" and "Contributors" lists for a bpftop release.
3 #
4 # Usage: contributors.sh <prev-tag>
5 # Example: contributors.sh v0.8.0
6 #
7 # Output: two markdown sections, ready to paste into the release notes:
8 # ## New Contributors
9 # ## Contributors
10 #
11 # Conventions encoded:
12 # - Source of truth is PR history per GitHub login (not commit author names).
13 # - Bots (logins ending in [bot]) are excluded from both lists.
14 # - The maintainer (jfernandez) is included in Contributors.
15 # - Contributors are sorted alphabetically by display name, case-insensitive.
16
17 set -euo pipefail
18
19 if [[ $# -lt 1 ]]; then
20 echo "usage: $0 <prev-tag>" >&2
21 exit 2
22 fi
23
24 PREV_TAG="$1"
25 REPO="jfernandez/bpftop"
26
27 # ISO date of the previous tag (use commit date — annotated-tag dates are tag creation, not commit).
28 PREV_DATE=$(git log -1 --format=%cI "${PREV_TAG}")
29
30 # All PRs merged after the previous tag, JSON.
31 PRS_JSON=$(gh pr list \
32 --state merged --base main \
33 --search "merged:>=${PREV_DATE}" \
34 --json number,author,mergedAt \
35 --limit 100)
36
37 # Unique non-bot author logins, sorted.
38 # `gh pr list` reports bots as either "name[bot]" or "app/name" — exclude both.
39 LOGINS=$(echo "${PRS_JSON}" | jq -r '
40 .[] | .author.login
41 | select(endswith("[bot]") | not)
42 | select(startswith("app/") | not)
43 ' | sort -u)
44
45 if [[ -z "${LOGINS}" ]]; then
46 echo "## New Contributors"
47 echo "_(none)_"
48 echo
49 echo "## Contributors"
50 echo "_(none)_"
51 exit 0
52 fi
53
54 # First-timers: a login whose earliest-ever merged PR in this repo falls within this window.
55 declare -A IN_WINDOW
56 while read -r number; do
57 IN_WINDOW["${number}"]=1
58 done < <(echo "${PRS_JSON}" | jq -r '.[].number')
59
60 NEW_CONTRIBUTORS=()
61 declare -A FIRST_PR_IN_WINDOW
62 while read -r login; do
63 [[ -z "${login}" ]] && continue
64 first_pr=$(gh pr list --author "${login}" --state merged \
65 --json number,mergedAt --limit 100 \
66 | jq -r 'sort_by(.mergedAt) | .[0].number // empty')
67 if [[ -n "${first_pr}" && -n "${IN_WINDOW[${first_pr}]:-}" ]]; then
68 NEW_CONTRIBUTORS+=("${login}")
69 FIRST_PR_IN_WINDOW["${login}"]="${first_pr}"
70 fi
71 done <<< "${LOGINS}"
72
73 # Display names — fall back to login if `name` is empty.
74 declare -A DISPLAY_NAME
75 while read -r login; do
76 [[ -z "${login}" ]] && continue
77 name=$(gh api "users/${login}" --jq '.name // ""')
78 if [[ -z "${name}" ]]; then
79 name="${login}"
80 fi
81 DISPLAY_NAME["${login}"]="${name}"
82 done <<< "${LOGINS}"
83
84 # Emit New Contributors.
85 echo "## New Contributors"
86 if [[ ${#NEW_CONTRIBUTORS[@]} -eq 0 ]]; then
87 echo "_(none)_"
88 else
89 for login in "${NEW_CONTRIBUTORS[@]}"; do
90 pr="${FIRST_PR_IN_WINDOW[${login}]}"
91 echo "* @${login} made their first contribution in https://github.com/${REPO}/pull/${pr}"
92 done
93 fi
94 echo
95
96 # Emit Contributors — sorted alphabetically by display name, case-insensitive.
97 echo "## Contributors"
98 {
99 while read -r login; do
100 [[ -z "${login}" ]] && continue
101 printf '%s\t%s\n' "${DISPLAY_NAME[${login}]}" "${login}"
102 done <<< "${LOGINS}"
103 } | sort -f | awk -F'\t' '{ printf "* %s @%s\n", $1, $2 }'