|
#!/usr/bin/env python3 |
|
# encoding: utf-8 |
|
"""Create a markdown list of authors for a particular repository. |
|
|
|
python create_authors_list.py -u djhoese -r satpy |
|
|
|
Requires the pygithub package. |
|
|
|
""" |
|
import getpass |
|
import logging |
|
import os |
|
import sys |
|
from datetime import datetime |
|
|
|
from github import Github |
|
|
|
LOG = logging.getLogger(__name__) |
|
EXCLUDE_REPOS = ['aggdraw'] |
|
|
|
def get_all_pytroll_contributors(user, repos=None): |
|
if repos is None: |
|
repos = [] |
|
g = Github(user, getpass.getpass('GitHub Password: ')) |
|
pytroll_org = g.get_organization('pytroll') |
|
LOG.info("Getting all PyTroll repositories...") |
|
pytroll_repos = [x for x in pytroll_org.get_repos() |
|
if (not repos and x.name not in EXCLUDE_REPOS) or x.name in repos] |
|
LOG.info("Getting all PyTroll contributors...") |
|
all_pytroll_contributors = [ |
|
u for r in pytroll_repos for u in r.get_contributors()] |
|
set_pytroll_contributors = {u.login: u for u in all_pytroll_contributors} |
|
return set_pytroll_contributors |
|
|
|
|
|
def main(): |
|
import argparse |
|
parser = argparse.ArgumentParser( |
|
description="Create a list of repository authors") |
|
parser.add_argument('-o', '--output', default='authors_{:%Y%m%d_%H%M%S}.md', |
|
help='Output filename to save the image to') |
|
parser.add_argument('-u', '--github-user', required=True, |
|
help='github username') |
|
parser.add_argument('-r', '--repos', required=True, nargs='+', |
|
help='repository to get authors for') |
|
args = parser.parse_args() |
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
LOG.info("Getting PyTroll contributors...") |
|
contributors = get_all_pytroll_contributors(args.github_user, args.repos) |
|
LOG.info("Getting all PyTroll contributor info...") |
|
all_user_info = [] |
|
for user in contributors.values(): |
|
all_user_info.append((user.login, user.name, user.html_url)) |
|
# sort by name |
|
all_user_info = sorted(all_user_info, key=lambda x: (x[1] and x[1].split(' ')[-1]) or x[0]) |
|
|
|
now = datetime.utcnow() |
|
output = args.output.format(now) |
|
LOG.info("Writing output file: {}".format(output)) |
|
with open(output, 'w') as out_file: |
|
for user_id, user_name, user_url in all_user_info: |
|
out_file.write("- [{} ({})]({})\n".format(user_name or user_id, user_id, user_url)) |
|
|
|
if __name__ == "__main__": |
|
sys.exit(main()) |