Assume github.com URLs are git protocol if not specified.

This commit is contained in:
Michael DeHaan 2014-08-21 17:14:55 -04:00
parent e7c0b95074
commit bcb44276fe
2 changed files with 61 additions and 5 deletions

View file

@ -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

View file

@ -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)