[llvm] Add script for mapping github logins to emails (PR #118834)

Carlo Cabrera via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 19:46:34 PST 2024


================
@@ -0,0 +1,197 @@
+#!/usr/bin/env python3
+
+import argparse
+import subprocess
+import json
+import sys
+import re
+import os
+import time
+
+from datetime import datetime
+from functools import cache
+
+contrib_database = {}
+contrib_database_path = os.path.join(os.getcwd(),'contributors.json')
+verbose = False
+start_time = datetime.now()
+
+def CreateArgParser():
+  parser = argparse.ArgumentParser(prog='contributor', description='LLVM GitHub Organization Scripts')
+  parser.add_argument('action', choices=['register', 'stats', 'print', 'query'], help='Action to perform')
+  parser.add_argument('extra_args', nargs='+', default=[])
+  parser.add_argument('--database', '-d', default=os.path.join(os.getcwd(),'contributors.json'), metavar='path', required=False, help='Path to contributor database')
+  parser.add_argument('--verbose', '-v', required=False, action='store_true', help='Enable verbose logging')
+  parser.add_argument('--filter', '-f', required=False, default='all', choices=['complete', 'noreply', 'missing', 'all'], help='Filter contributor database')
+  return parser
+
+ at cache
+def ParseArgs():
+  parser = CreateArgParser()
+  return parser.parse_args(sys.argv[1:])
+
+def ElapsedTime():
+  return str(datetime.now() - start_time)
+
+def Checkpoint(msg=''):
+  if not ParseArgs().verbose:
+    return
+  if len(msg) > 0:
+    print('%s - Time elapsed %s' % (msg, ElapsedTime()))
+  else:
+    print('Time elapsed: %s' % ElapsedTime())
+
+def InvokeAndDecode(cmd):
+  for Attempt in range(10):
+    try:
+      status = subprocess.check_output(cmd)
+      return json.loads(status)
+    except:
+      time.sleep(60)
+  return None
+
+def QueryOrgMembers():
+  members = []
+  page = 1
+  while True:
+    ghCommand = ['gh', 'api', '-H', 'Accept: application/vnd.github+json',
+               '-H', 'X-GitHub-Api-Version: 2022-11-28', '/orgs/llvm/members?per_page=100&page=%d' % page]
----------------
carlocab wrote:

Would using the `--paginate` flag help avoid having to handle pagination manually here?

Also, might be nice to extract all the common bits in `ghCommand` to a variable so that they don't have to be repeated twice below.

https://github.com/llvm/llvm-project/pull/118834


More information about the llvm-commits mailing list