Skip to content

Commit 0a0a1b4

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 4b66c6f commit 0a0a1b4

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
@@ -109,6 +109,25 @@ def find_authors_by_project(start_time, end_time):
109109
'tests',
110110
]
111111

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

113132
author_cache = {}
114133
for repo in org.repositories():
@@ -130,12 +149,17 @@ def find_authors_by_project(start_time, end_time):
130149
if commit.author is None:
131150
if commit.commit.author is None:
132151
print('Skipping %s in %s as it has no author. Did this merge via GitHub?' %
133-
(commit, repo))
152+
(commit, repo))
134153
continue
135154

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

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

177207
def main():

0 commit comments

Comments
 (0)