@@ -9,10 +9,50 @@ alias jq="jq --unbuffered"
9
9
[[ -n " ${REPO_FILTER+x} " ]] || REPO_FILTER=" github.com/(ipfs|libp2p|ipld)"
10
10
[[ -n " ${IGNORED_FILES+x} " ]] || IGNORED_FILES=' ^\(\.gx\|package.json\|\.travis.yml\|go.mod\|go.sum\)$'
11
11
12
+ NL=$' \n '
13
+
12
14
msg () {
13
15
echo " $* " >&2
14
16
}
15
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
+
16
56
# Returns a stream of deps changed between $1 and $2.
17
57
dep_changes () {
18
58
{
@@ -46,7 +86,7 @@ release_log() {
46
86
grep -v " ${IGNORED_FILES} " > /dev/null || continue
47
87
48
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 "
50
90
done
51
91
}
52
92
@@ -75,6 +115,11 @@ ensure() {
75
115
git -C " $rpath " rev-parse --verify " $commit " > /dev/null || return 1
76
116
}
77
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
+
78
123
recursive_release_log () {
79
124
local start=" ${1:- $(git tag -l | sort -V | grep -v -- ' -rc' | grep ' v' | tail -n1)} "
80
125
local end=" ${2:- $(git rev-parse HEAD)} "
@@ -95,24 +140,37 @@ recursive_release_log() {
95
140
96
141
rm -f go.mod go.sum
97
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
99
144
100
- printf " - %s:\n" " $package "
145
+ printf -- " - %s:\n" " $package "
101
146
release_log " $package " " $start " " $end " | indent
102
147
103
148
149
+ statlog " $package " " $start " " $end " > statlog.json
150
+
104
151
dep_changes old_deps.json new_deps.json |
105
152
jq --arg filter " $REPO_FILTER " ' select(.Path | match($filter))' |
106
153
# Compute changelogs
107
154
jq -r ' "\(.Path) \(.New.Version) \(.New.Ref) \(.Old.Version) \(.Old.Ref // "")"' |
108
155
while read repo new new_ref old old_ref; do
109
156
ensure " $repo " " $new_ref "
157
+ statlog " $repo " " $old_ref " " $new_ref " >> statlog.json
110
158
local changelog=" $( release_log " $repo " " $old_ref " " $new_ref " ) "
111
159
if [[ -n " $changelog " ]]; then
112
- printf " - %s (%s -> %s):\n" " $repo " " $old " " $new "
160
+ printf -- " - %s (%s -> %s):\n" " $repo " " $old " " $new "
113
161
echo " $changelog " | indent
114
162
fi
115
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) |"'
116
174
)
117
175
}
118
176
0 commit comments