Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script and voters list for Feb 2021 elections #359

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion election/github_emails.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/user/bin/env python3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

#!/usr/bin/env python3

"""get_emails.py queries GitHub for the email addresses to use for usernames.

Expand Down
51 changes: 51 additions & 0 deletions election/github_emails_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

"""get_emails_2.py Extracts github IDs from a CSV and matches them
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to replace the other script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run this first on the output of grafana, and then run the other script on the missing list produced by this script.
Reason being that the first script is more likely to give clean results, but also to have many miss.
I should have documented this better? Or maybe aggregated the two steps? I was a bit lazy :P

to emails through a JSON map.

The CVS input file can be obtained from devstats. Clink on the link:
https://tekton.devstats.cd.foundation/d/9/developer-activity-counts-by-repository-group-table?inspect=1&inspectTab=data&viewPanel=1&orgId=1&var-period_name=Last%20year&var-metric=contributions&var-repogroup_name=All&var-country_name=All
and use the download CSV button to download the CSV file.

The script takes the JSON map from https://github.com/cncf/devstats/blob/master/github_users.json,
which is one of the input files used by the CDF for devstats.

The output will be a mapping of the GitHub username to the all email addresses
contained in commits associated with this user in a csv file.

Usage:
python3 github_emails_2.py --file users.csv
"""
import argparse
import csv
import requests
from typing import List, Dict

import pandas as pd

EMAIL_MAP = "https://github.com/cncf/devstats/raw/master/github_users.json"

if __name__ == '__main__':
arg_parser = argparse.ArgumentParser(
description="Try to find email addresses for GitHub usernames")
arg_parser.add_argument("--file", type=str, required=True,
help="A file containing the GitHub usernames to query, separated by a newline")
arg_parser.add_argument("--csv", type=str, required=False,
help="csv file to write with results")
args = arg_parser.parse_args()

csvfile = args.csv or "found_emails.csv"
missingfile = "missing_emails.csv"

# load data
users = pd.read_csv(args.file)
emailmap = pd.read_json(EMAIL_MAP)
emailmap = emailmap[~emailmap['email'].str.endswith('users.noreply.github.com')]

# filter eligible users
eligible = users[users['value'] >= 15]
found = pd.merge(eligible, emailmap, left_on='name', right_on='login', how='left', indicator=True).query('_merge == "both"').drop(columns='_merge')
found['email'] = found['email'].str.replace('!', '@')
missing = pd.merge(eligible, emailmap, left_on='name', right_on='login', how='left', indicator=True).query('_merge == "left_only"').drop(columns='_merge')
found.to_csv(csvfile, columns=['name_x', 'email'], header=False, index=False)
missing.to_csv(missingfile, columns=['name_x'], header=False, index=False)