@@ -9,10 +9,50 @@ alias jq="jq --unbuffered"
99[[ -n " ${REPO_FILTER+x} " ]] || REPO_FILTER=" github.com/(ipfs|libp2p|ipld)"
1010[[ -n " ${IGNORED_FILES+x} " ]] || IGNORED_FILES=' ^\(\.gx\|package.json\|\.travis.yml\|go.mod\|go.sum\)$'
1111
12+ NL=$' \n '
13+
1214msg () {
1315 echo " $* " >&2
1416}
1517
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+
1656# Returns a stream of deps changed between $1 and $2.
1757dep_changes () {
1858 {
@@ -46,7 +86,7 @@ release_log() {
4686 grep -v " ${IGNORED_FILES} " > /dev/null || continue
4787
4888 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 "
5090 done
5191}
5292
@@ -75,6 +115,11 @@ ensure() {
75115 git -C " $rpath " rev-parse --verify " $commit " > /dev/null || return 1
76116}
77117
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+
78123recursive_release_log () {
79124 local start=" ${1:- $(git tag -l | sort -V | grep -v -- ' -rc' | grep ' v' | tail -n1)} "
80125 local end=" ${2:- $(git rev-parse HEAD)} "
@@ -95,24 +140,37 @@ recursive_release_log() {
95140
96141 rm -f go.mod go.sum
97142
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
99144
100- printf " - %s:\n" " $package "
145+ printf -- " - %s:\n" " $package "
101146 release_log " $package " " $start " " $end " | indent
102147
103148
149+ statlog " $package " " $start " " $end " > statlog.json
150+
104151 dep_changes old_deps.json new_deps.json |
105152 jq --arg filter " $REPO_FILTER " ' select(.Path | match($filter))' |
106153 # Compute changelogs
107154 jq -r ' "\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
108155 while read repo new new_ref old old_ref; do
109156 ensure " $repo " " $new_ref "
157+ statlog " $repo " " $old_ref " " $new_ref " >> statlog.json
110158 local changelog=" $( release_log " $repo " " $old_ref " " $new_ref " ) "
111159 if [[ -n " $changelog " ]]; then
112- printf " - %s (%s -> %s):\n" " $repo " " $old " " $new "
160+ printf -- " - %s (%s -> %s):\n" " $repo " " $old " " $new "
113161 echo " $changelog " | indent
114162 fi
115163 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) |"'
116174 )
117175}
118176
0 commit comments