Remove software carpentries logo
[rnaseq-cwl-training.git] / bin / repo_check.py
old mode 100755 (executable)
new mode 100644 (file)
index fd04ce9..9bf5c59
@@ -1,17 +1,15 @@
-#!/usr/bin/env python
-
 """
 Check repository settings.
 """
 
-from __future__ import print_function
+
 import sys
 import os
 from subprocess import Popen, PIPE
 import re
-from optparse import OptionParser
+from argparse import ArgumentParser
 
-from util import Reporter, load_yaml, require
+from util import Reporter, require
 
 # Import this way to produce a more useful error message.
 try:
@@ -22,7 +20,7 @@ except ImportError:
 
 
 # Pattern to match Git command-line output for remotes => (user name, project name).
-P_GIT_REMOTE = re.compile(r'upstream\s+[^:]+:([^/]+)/([^.]+)\.git\s+\(fetch\)')
+P_GIT_REMOTE = re.compile(r'upstream\s+(?:https://|git@)github.com[:/]([^/]+)/([^.]+)(\.git)?\s+\(fetch\)')
 
 # Repository URL format string.
 F_REPO_URL = 'https://github.com/{0}/{1}/'
@@ -35,15 +33,26 @@ F_API_URL = 'https://api.github.com/repos/{0}/{1}/labels'
 
 # Expected labels and colors.
 EXPECTED = {
-    'bug' : 'bd2c00',
-    'discussion' : 'fc8dc1',
-    'enhancement' : '9cd6dc',
-    'help-wanted' : 'f4fd9c',
-    'instructor-training' : '6e5494',
-    'newcomer-friendly' : 'eec275',
-    'question' : '808040',
-    'template-and-tools' : '2b3990',
-    'work-in-progress' : '7ae78e'
+    'help wanted': 'dcecc7',
+    'status:in progress': '9bcc65',
+    'status:changes requested': '679f38',
+    'status:wait': 'fff2df',
+    'status:refer to cac': 'ffdfb2',
+    'status:need more info': 'ee6c00',
+    'status:blocked': 'e55100',
+    'status:out of scope': 'eeeeee',
+    'status:duplicate': 'bdbdbd',
+    'type:typo text': 'f8bad0',
+    'type:bug': 'eb3f79',
+    'type:formatting': 'ac1357',
+    'type:template and tools': '7985cb',
+    'type:instructor guide': '00887a',
+    'type:discussion': 'b2e5fc',
+    'type:enhancement': '7fdeea',
+    'type:clarification': '00acc0',
+    'type:teaching example': 'ced8dc',
+    'good first issue': 'ffeb3a',
+    'high priority': 'd22e2e'
 }
 
 
@@ -54,7 +63,7 @@ def main():
 
     args = parse_args()
     reporter = Reporter()
-    repo_url = get_repo_url(args.source_dir, args.repo_url)
+    repo_url = get_repo_url(args.repo_url)
     check_labels(reporter, repo_url)
     reporter.report()
 
@@ -64,24 +73,24 @@ def parse_args():
     Parse command-line arguments.
     """
 
-    parser = OptionParser()
-    parser.add_option('-r', '--repo',
-                      default=None,
-                      dest='repo_url',
-                      help='repository URL')
-    parser.add_option('-s', '--source',
-                      default=os.curdir,
-                      dest='source_dir',
-                      help='source directory')
-
-    args, extras = parser.parse_args()
+    parser = ArgumentParser(description="""Check repository settings.""")
+    parser.add_argument('-r', '--repo',
+                        default=None,
+                        dest='repo_url',
+                        help='repository URL')
+    parser.add_argument('-s', '--source',
+                        default=os.curdir,
+                        dest='source_dir',
+                        help='source directory')
+
+    args, extras = parser.parse_known_args()
     require(not extras,
             'Unexpected trailing command-line arguments "{0}"'.format(extras))
 
     return args
 
 
-def get_repo_url(source_dir, repo_url):
+def get_repo_url(repo_url):
     """
     Figure out which repository to query.
     """
@@ -92,7 +101,8 @@ def get_repo_url(source_dir, repo_url):
 
     # Guess.
     cmd = 'git remote -v'
-    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, close_fds=True, universal_newlines=True)
+    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
+              close_fds=True, universal_newlines=True, encoding='utf-8')
     stdout_data, stderr_data = p.communicate()
     stdout_data = stdout_data.split('\n')
     matches = [P_GIT_REMOTE.match(line) for line in stdout_data]
@@ -101,10 +111,12 @@ def get_repo_url(source_dir, repo_url):
             'Unexpected output from git remote command: "{0}"'.format(matches))
 
     username = matches[0].group(1)
-    require(username, 'empty username in git remote output {0}'.format(matches[0]))
+    require(
+        username, 'empty username in git remote output {0}'.format(matches[0]))
 
     project_name = matches[0].group(2)
-    require(username, 'empty project name in git remote output {0}'.format(matches[0]))
+    require(
+        username, 'empty project name in git remote output {0}'.format(matches[0]))
 
     url = F_REPO_URL.format(username, project_name)
     return url
@@ -131,7 +143,7 @@ def check_labels(reporter, repo_url):
 
     overlap = set(EXPECTED.keys()).intersection(set(actual.keys()))
     for name in sorted(overlap):
-        reporter.check(EXPECTED[name] == actual[name],
+        reporter.check(EXPECTED[name].lower() == actual[name].lower(),
                        None,
                        'Color mis-match for label {0} in {1}: expected {2}, found {3}',
                        name, repo_url, EXPECTED[name], actual[name])
@@ -143,13 +155,15 @@ def get_labels(repo_url):
     """
 
     m = P_REPO_URL.match(repo_url)
-    require(m, 'repository URL {0} does not match expected pattern'.format(repo_url))
+    require(
+        m, 'repository URL {0} does not match expected pattern'.format(repo_url))
 
     username = m.group(1)
     require(username, 'empty username in repository URL {0}'.format(repo_url))
 
     project_name = m.group(2)
-    require(username, 'empty project name in repository URL {0}'.format(repo_url))
+    require(
+        username, 'empty project name in repository URL {0}'.format(repo_url))
 
     url = F_API_URL.format(username, project_name)
     r = requests.get(url)