Guest User

Untitled

a guest
Oct 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # encoding: utf-8
  3. """Create a markdown list of authors for a particular repository.
  4.  
  5. python create_authors_list.py -u djhoese -r satpy
  6.  
  7. Requires the pygithub package.
  8.  
  9. """
  10. import getpass
  11. import logging
  12. import os
  13. import sys
  14. from datetime import datetime
  15.  
  16. from github import Github
  17.  
  18. LOG = logging.getLogger(__name__)
  19. EXCLUDE_REPOS = ['aggdraw']
  20.  
  21. def get_all_pytroll_contributors(user, repos=None):
  22. if repos is None:
  23. repos = []
  24. g = Github(user, getpass.getpass('GitHub Password: '))
  25. pytroll_org = g.get_organization('pytroll')
  26. LOG.info("Getting all PyTroll repositories...")
  27. pytroll_repos = [x for x in pytroll_org.get_repos()
  28. if (not repos and x.name not in EXCLUDE_REPOS) or x.name in repos]
  29. LOG.info("Getting all PyTroll contributors...")
  30. all_pytroll_contributors = [
  31. u for r in pytroll_repos for u in r.get_contributors()]
  32. set_pytroll_contributors = {u.login: u for u in all_pytroll_contributors}
  33. return set_pytroll_contributors
  34.  
  35.  
  36. def main():
  37. import argparse
  38. parser = argparse.ArgumentParser(
  39. description="Create a list of repository authors")
  40. parser.add_argument('-o', '--output', default='authors_{:%Y%m%d_%H%M%S}.md',
  41. help='Output filename to save the image to')
  42. parser.add_argument('-u', '--github-user', required=True,
  43. help='github username')
  44. parser.add_argument('-r', '--repos', required=True, nargs='+',
  45. help='repository to get authors for')
  46. args = parser.parse_args()
  47.  
  48. logging.basicConfig(level=logging.INFO)
  49.  
  50. LOG.info("Getting PyTroll contributors...")
  51. contributors = get_all_pytroll_contributors(args.github_user, args.repos)
  52. LOG.info("Getting all PyTroll contributor info...")
  53. all_user_info = []
  54. for user in contributors.values():
  55. all_user_info.append((user.login, user.name, user.html_url))
  56. # sort by name
  57. all_user_info = sorted(all_user_info, key=lambda x: (x[1] and x[1].split(' ')[-1]) or x[0])
  58.  
  59. now = datetime.utcnow()
  60. output = args.output.format(now)
  61. LOG.info("Writing output file: {}".format(output))
  62. with open(output, 'w') as out_file:
  63. for user_id, user_name, user_url in all_user_info:
  64. out_file.write("- [{} ({})]({})\n".format(user_name or user_id, user_id, user_url))
  65.  
  66. if __name__ == "__main__":
  67. sys.exit(main())
Add Comment
Please, Sign In to add comment