From bcb44276fe898824ab49cf2890dc8ee8642cff1e Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 21 Aug 2014 17:14:55 -0400 Subject: [PATCH] Assume github.com URLs are git protocol if not specified. --- lib/ansible/utils/__init__.py | 14 +++++++++- test/units/TestUtils.py | 52 ++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 155dbd17a18..a618b5dc91a 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -378,12 +378,22 @@ def role_spec_parse(role_spec): # 'version': 'v1.0', # 'name': 'repo' # } - + role_spec = role_spec.strip() role_version = '' if role_spec == "" or role_spec.startswith("#"): return (None, None, None, None) + + # FIXME: coding guidelines want this as a list comprehension tokens = map(lambda s: s.strip(), role_spec.split(',')) + + # assume https://github.com URLs are git+https:// URLs and not + # tarballs + print "0=%s" % tokens[0] + if 'github.com/' in tokens[0] and not tokens[0].startswith("git+"): + print "DONE!" + tokens[0] = 'git+' + tokens[0] + if '+' in tokens[0]: (scm, role_url) = tokens[0].split('+') else: @@ -399,6 +409,8 @@ def role_spec_parse(role_spec): def role_yaml_parse(role): + if 'github.com' in role["src"] and 'http' in role["src"] and '+' not in role["src"]: + role["src"] = "git+" + role["src"] if '+' in role["src"]: (scm, src) = role["src"].split('+') role["scm"] = scm diff --git a/test/units/TestUtils.py b/test/units/TestUtils.py index f7409070406..dda9d5c676e 100644 --- a/test/units/TestUtils.py +++ b/test/units/TestUtils.py @@ -787,10 +787,54 @@ class TestUtils(unittest.TestCase): self.assertEqual(ansible.utils.repo_url_to_role_name(url), result) def test_role_spec_parse(self): - tests = [("git+http://git.example.com/repos/repo.git,v1.0", {'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'repo'}), - ("http://repo.example.com/download/tarfile.tar.gz", {'scm': None, 'src': 'http://repo.example.com/download/tarfile.tar.gz', 'version': '', 'name': 'tarfile'}), - ("http://repo.example.com/download/tarfile.tar.gz,,nicename", {'scm': None, 'src': 'http://repo.example.com/download/tarfile.tar.gz', 'version': '', 'name': 'nicename'}), - ("git+http://git.example.com/repos/repo.git,v1.0,awesome", {'scm': 'git', 'src': 'http://git.example.com/repos/repo.git', 'version': 'v1.0', 'name': 'awesome'})] + tests = [ + ( + "git+http://git.example.com/repos/repo.git,v1.0", + { + 'scm': 'git', + 'src': 'http://git.example.com/repos/repo.git', + 'version': 'v1.0', + 'name': 'repo' + } + ), + ( + "http://repo.example.com/download/tarfile.tar.gz", + { + 'scm': None, + 'src': 'http://repo.example.com/download/tarfile.tar.gz', + 'version': '', + 'name': 'tarfile' + } + ), + ( + "http://repo.example.com/download/tarfile.tar.gz,,nicename", + { + 'scm': None, + 'src': 'http://repo.example.com/download/tarfile.tar.gz', + 'version': '', + 'name': 'nicename' + } + ), + ( + "git+http://git.example.com/repos/repo.git,v1.0,awesome", + { + 'scm': 'git', + 'src': 'http://git.example.com/repos/repo.git', + 'version': 'v1.0', + 'name': 'awesome' + } + ), + ( + # test that http://github URLs are assumed git+http:// + "http://github.com/ansible/fakerole/fake", + { + 'scm' : 'git', + 'src' : 'http://github.com/ansible/fakerole/fake', + 'version' : '', + 'name' : 'fake' + } + ) + ] for (spec, result) in tests: self.assertEqual(ansible.utils.role_spec_parse(spec), result)