Skip to content

Commit 08d2d0d

Browse files
committed
elections/tools: Handle unknown logins better
We have some users (maybe as they have changed email, or don't have a public email on github), that we can't find gh logins for, so we've just used the email, but this could result in us double counting emails in the electorate list, so instead provide a mapping of these problematic emails to the correct github username and add warning messages to let users know to keep these up-to-date. Signed-off-by: stevenhorsman <[email protected]>
1 parent fe5b293 commit 08d2d0d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

elections/tools/generate_electorate.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ def find_authors_by_project(start_time, end_time):
108108
'tests',
109109
]
110110

111+
# Let's build a list of the users we can't get the logins for so
112+
# we can prompt the runner to update the following map
113+
unknown_logins = {}
114+
115+
# Some committers have emails that don't map to their
116+
# userid properly, so maintain a map of these so the data is consistent
117+
email_id_map = {
118+
"[email protected]":"lifupan",
119+
"[email protected]": "Ankita13-code",
120+
"[email protected]": "ChengyuZhu6",
121+
"[email protected]": "lima-emanuel",
122+
"[email protected]": "l8huang",
123+
"[email protected]": "Bickor",
124+
"[email protected]": "huoqifeng",
125+
"[email protected]": "niteeshkd",
126+
"[email protected]": "gpyrros",
127+
"[email protected]": "cmaf",
128+
"[email protected]": "amshinde",
129+
}
111130

112131
author_cache = {}
113132
for repo in org.repositories():
@@ -129,12 +148,17 @@ def find_authors_by_project(start_time, end_time):
129148
if commit.author is None:
130149
if commit.commit.author is None:
131150
print('Skipping %s in %s as it has no author. Did this merge via GitHub?' %
132-
(commit, repo))
151+
(commit, repo))
133152
continue
134153

135154
author_id = commit.commit.author.get('email')
136-
print('%s in %s as has no author. Using email (%s) as the author id' %
137-
(commit, repo, author_id))
155+
if author_id in email_id_map:
156+
author_id = email_id_map[author_id]
157+
else:
158+
if not author_id in unknown_logins:
159+
unknown_logins[author_id] = commit.html_url
160+
print('%s in %s as has no author. Using email (%s) as the author id' %
161+
(commit, repo, author_id))
138162
else:
139163
author_id = commit.author.login
140164

@@ -171,6 +195,12 @@ def find_authors_by_project(start_time, end_time):
171195
author.name = match.group('name')
172196
authors.add(author)
173197
projects.append({str(repo): authors})
198+
199+
if len(unknown_logins) > 0:
200+
print("Warning: failed to match some emails. Please follow the commit link and add the email -> id " \
201+
"map to `email_id_map` in generate_electorate.py:")
202+
for email, commit_html in unknown_logins.items():
203+
print("Email", email, "who committed", commit_html)
174204
return projects
175205

176206
def main():

0 commit comments

Comments
 (0)