@cryptotaxi247 / kubo / commits / e5aa2e726

mkreleaselog: calculate contributors

Steven Allen committed May 29, 2019 at 17:35 UTC e5aa2e72655c779a57dacb7255b48c5dd127d374
1 file changed +62 -4
bin/mkreleaselog
+62 -4
@@ -9,10 +9,50 @@ alias jq="jq --unbuffered"
9 [[ -n "${REPO_FILTER+x}" ]] || REPO_FILTER="github.com/(ipfs|libp2p|ipld)"
10 [[ -n "${IGNORED_FILES+x}" ]] || IGNORED_FILES='^\(\.gx\|package.json\|\.travis.yml\|go.mod\|go.sum\)$'
11
12 +NL=$'\n'
13 +
14 msg() {
15 echo "$*" >&2
16 }
17
18 +statlog() {
19 + rpath="$GOPATH/src/$1"
20 + start="${2:-}"
21 + end="${3:-HEAD}"
22 + git -C "$rpath" log --shortstat --no-merges --pretty="tformat:%H%n%aN%n%aE" "$start..$end" | while
23 + read hash
24 + read name
25 + read email
26 + read _ # empty line
27 + read changes
28 + do
29 + changed=0
30 + insertions=0
31 + deletions=0
32 + while read count event; do
33 + if [[ "$event" =~ ^file ]]; then
34 + changed=$count
35 + elif [[ "$event" =~ ^insertion ]]; then
36 + insertions=$count
37 + elif [[ "$event" =~ ^deletion ]]; then
38 + deletions=$count
39 + else
40 + echo "unknown event $event" >&2
41 + exit 1
42 + fi
43 + done<<<"${changes//,/$NL}"
44 +
45 + jq -n \
46 + --arg "hash" "$hash" \
47 + --arg "name" "$name" \
48 + --arg "email" "$email" \
49 + --argjson "changed" "$changed" \
50 + --argjson "insertions" "$insertions" \
51 + --argjson "deletions" "$deletions" \
52 + '{Commit: $hash, Author: $name, Email: $email, Files: $changed, Insertions: $insertions, Deletions: $deletions}'
53 + done
54 +}
55 +
56 # Returns a stream of deps changed between $1 and $2.
57 dep_changes() {
58 {
@@ -46,7 +86,7 @@ release_log() {
86 grep -v "${IGNORED_FILES}" >/dev/null || continue
87
88 local desc="$(git -C "$dir" show --summary --format='tformat:%b' "$commit" | head -1)"
49 - printf "- %s ([%s#%s](https://%s/pull/%s))\n" "$desc" "$ghname" "$prnum" "$repo" "$prnum"
89 + printf -- "- %s ([%s#%s](https://%s/pull/%s))\n" "$desc" "$ghname" "$prnum" "$repo" "$prnum"
90 done
91 }
92
@@ -75,6 +115,11 @@ ensure() {
115 git -C "$rpath" rev-parse --verify "$commit" >/dev/null || return 1
116 }
117
118 +statsummary() {
119 + jq -s 'group_by(.Author)[] | {Author: .[0].Author, Commits: (. | length), Insertions: (map(.Insertions) | add), Deletions: (map(.Deletions) | add), Files: (map(.Files) | add)}' |
120 + jq '. + {Lines: (.Deletions + .Insertions)}'
121 +}
122 +
123 recursive_release_log() {
124 local start="${1:-$(git tag -l | sort -V | grep -v -- '-rc' | grep 'v'| tail -n1)}"
125 local end="${2:-$(git rev-parse HEAD)}"
@@ -95,24 +140,37 @@ recursive_release_log() {
140
141 rm -f go.mod go.sum
142
98 - printf "Generating Changelog for %s %s..%s\n" "$package" "$start" "$end" >&2
143 + printf -- "Generating Changelog for %s %s..%s\n" "$package" "$start" "$end" >&2
144
100 - printf "- %s:\n" "$package"
145 + printf -- "- %s:\n" "$package"
146 release_log "$package" "$start" "$end" | indent
147
148
149 + statlog "$package" "$start" "$end" > statlog.json
150 +
151 dep_changes old_deps.json new_deps.json |
152 jq --arg filter "$REPO_FILTER" 'select(.Path | match($filter))' |
153 # Compute changelogs
154 jq -r '"\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
155 while read repo new new_ref old old_ref; do
156 ensure "$repo" "$new_ref"
157 + statlog "$repo" "$old_ref" "$new_ref" >> statlog.json
158 local changelog="$(release_log "$repo" "$old_ref" "$new_ref")"
159 if [[ -n "$changelog" ]]; then
112 - printf "- %s (%s -> %s):\n" "$repo" "$old" "$new"
160 + printf -- "- %s (%s -> %s):\n" "$repo" "$old" "$new"
161 echo "$changelog" | indent
162 fi
163 done
164 +
165 + echo
166 + echo "Contributors"
167 + echo
168 +
169 + echo "| Contributor | Commits | Lines ± | Files Changed |"
170 + echo "|-------------|---------|---------|---------------|"
171 + statsummary <statlog.json |
172 + jq -s 'sort_by(.Lines) | reverse | .[]' |
173 + jq -r '"| \(.Author) | \(.Commits) | +\(.Insertions)/-\(.Deletions) | \(.Files) |"'
174 )
175 }
176