1
- #! env bash
1
+ #! /bin/bash
2
+ #
3
+ # This script builds a nice list of contributors (full name, github login, email).
4
+ # If you want to change your appearance in generated file, feel free to send a PR!
5
+ #
6
+
7
+ set -euo pipefail
2
8
3
9
function find_login() {
4
- local github_login=" $( curl -s " https://api.github.com/search/users?q=$1 " \
10
+ local github_login=" $( curl -s --get " https://api.github.com/search/users" \
11
+ --data-urlencode " q=$1 " \
5
12
| jq -r ' .items[0].login' 2> /dev/null) "
6
13
7
14
if [[ " ${github_login} " != " " ]] && [[ " ${github_login} " != " null" ]]
@@ -10,6 +17,8 @@ function find_login() {
10
17
fi
11
18
}
12
19
20
+ # If the user has full name in their public github profile, use it.
21
+ # Otherwise we'll fallback to whatever we have in git.
13
22
function find_name() {
14
23
local github_name=" $( curl -s " https://api.github.com/users/$1 " \
15
24
| jq -r .name 2> /dev/null \
@@ -21,7 +30,20 @@ function find_name() {
21
30
fi
22
31
}
23
32
33
+ # Github preserves git committer email if PR was merged using rebase-merge, but
34
+ # spoils it if it was merged using squash-merge, which is annoying! If the
35
+ # user originally provided a real email in their public git commits, we'll use
36
+ # it, otherwise we'll fall back to whatever we have in git after merging PR.
24
37
function find_email() {
38
+ local reflog_email=" $( git reflog --pretty=format:" %an <%ae>" | sort -u | \
39
+ grep -vF users.noreply.github.com | grep -F " $1 " | sed -re ' s,.*<(.*)>,\1,' ) "
40
+
41
+ if [[ " ${reflog_email} " != " " ]]
42
+ then
43
+ echo " ${reflog_email} "
44
+ return
45
+ fi
46
+
25
47
local github_email=" $( curl -s " https://api.github.com/users/$1 /events/public" \
26
48
| jq -r \
27
49
' ((.[].payload.commits | select(. != null))[].author | select(.name == "' $1 ' ")).email' \
@@ -34,16 +56,9 @@ function find_email() {
34
56
then
35
57
echo " ${github_email} "
36
58
fi
37
-
38
- local reflog_email=" $( git reflog --pretty=format:" %an <%ae>" | sort -u | \
39
- grep -vF users.noreply.github.com | grep -F " $1 " | sed -re ' s,.*<(.*)>,\1,' ) "
40
-
41
- if [[ " ${reflog_email} " != " " ]]
42
- then
43
- echo " ${reflog_email} "
44
- fi
45
59
}
46
60
61
+ # Add contributor if not already added.
47
62
function add_if_new() {
48
63
local file=" $1 "
49
64
@@ -68,43 +83,59 @@ function add_if_new() {
68
83
fi
69
84
fi
70
85
71
- local print_name=" $( find_name " ${github_login} " ) "
72
- if [ -z " ${print_name} " ]
86
+ if grep -qiF " /${github_login} /" " ${file} "
87
+ then
88
+ return
89
+ fi
90
+
91
+ local full_name=" $( find_name " ${github_login} " ) "
92
+ if [ -z " ${full_name} " ]
73
93
then
74
- print_name =" ${commit_name} "
94
+ full_name =" ${commit_name} "
75
95
fi
76
- print_name =" $( echo " ${print_name } " | sed -re ' s/\S+/\u&/g' ) "
96
+ full_name =" $( echo " ${full_name } " | sed -re ' s/\S+/\u&/g' ) "
77
97
78
- local print_addr =" "
98
+ local address =" "
79
99
if echo " ${commit_email} " | grep -q users.noreply.github.com
80
100
then
81
101
if [[ ! -z " ${github_login} " ]]
82
102
then
83
- print_addr =" $( find_email " ${github_login} " ) "
103
+ address =" $( find_email " ${github_login} " ) "
84
104
fi
85
105
else
86
- print_addr =" ${commit_email} "
106
+ address =" ${commit_email} "
87
107
fi
88
- if [[ -z " ${print_addr } " && ! -z " ${github_login} " ]]
108
+ if [[ -z " ${address } " && ! -z " ${github_login} " ]]
89
109
then
90
- print_addr =" https://github.com/${github_login} "
110
+ address =" https://github.com/${github_login} "
91
111
fi
92
112
93
- if [ -z " ${print_addr} " ]
113
+ local result=" ${full_name} "
114
+ if [ ! -z " ${github_login} " ]
94
115
then
95
- echo " Adding ${print_name} " 1>&2
96
- echo " * ${print_name} "
97
- else
98
- echo " Adding ${print_name} ( ${print_addr} ) " 1>&2
99
- echo " * ${print_name } (${print_addr } )"
116
+ result= " ${result} \` ${github_login} \` "
117
+ fi
118
+ if [ ! -z " ${address} " ]
119
+ then
120
+ result= " ${result } (${address } )"
100
121
fi
122
+
123
+ echo " adding ${result} " 1>&2
124
+ echo " * ${result} "
101
125
}
102
126
127
+ # Find all new contributors and append to the file.
103
128
function add_contributors() {
104
129
out_file=" $1 "
105
- repo_dir=" $2 "
130
+ repo_dir=" $( pwd ) "
106
131
107
- git log --encoding=utf-8 --full-history --reverse " --format=format:%at,%an,%ae" \
132
+ if [ ! -d " ${repo_dir} " ]
133
+ then
134
+ return
135
+ fi
136
+
137
+ GIT_DIR=" ${repo_dir} " /.git \
138
+ git log --encoding=utf-8 --full-history --reverse " --format=format:%at,%an,%ae" \
108
139
| sort -u -t, -k3,3 \
109
140
| sort -t, -k1n \
110
141
| while read line
@@ -116,20 +147,13 @@ function add_contributors() {
116
147
done
117
148
}
118
149
119
- function update_authors() {
120
- file=" AUTHORS.md"
121
- temp=" $( mktemp) "
122
-
123
- cat " ${file} " > " ${temp} "
124
-
125
- add_contributors " ${temp} " " $( pwd) "
126
-
127
- cat " $temp " > " ${file} "
128
- rm " ${temp} "
129
- }
150
+ result_file=" AUTHORS.md"
151
+ temp_file=" $( mktemp) "
130
152
131
- cd " $( dirname " $0 " ) /.."
153
+ cat " ${result_file} " > " ${temp_file} "
154
+ add_contributors " ${temp_file} "
132
155
133
- update_authors " ${sphinx} "
156
+ cat " ${temp_file} " > " ${result_file} "
157
+ rm " ${temp_file} "
134
158
135
- echo " Updated AUTHORS.md "
159
+ echo " updated ${result_file} "
0 commit comments