Skip to content

Commit

Permalink
Add opendev.org https and git fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Beisner committed Oct 4, 2019
1 parent cd8792b commit 60d8387
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions charmtools/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ def fetch(self, dir_):
return rename(dir_)


class OpendevFetcher(Fetcher):
MATCH = re.compile(r"""
^(https:\/\/(www\.)?opendev\.com\/|[email protected]:)
(?P<repo>[^@]*)(@(?P<revision>.*))?$
""", re.VERBOSE)

def fetch(self, dir_):
dir_ = tempfile.mkdtemp(dir=dir_)
url = 'https://opendev.org/' + self.repo
git('clone {} {}'.format(url, dir_))
if self.revision:
git('checkout {}'.format(self.revision), cwd=dir_)
return rename(dir_)


class GitFetcher(Fetcher):
"""Generic git fetcher.
Expand Down Expand Up @@ -358,6 +373,7 @@ def check_output(cmd, **kw):
BzrFetcher,
BzrMergeProposalFetcher,
GithubFetcher,
OpendevFetcher,
BitbucketFetcher,
LocalFetcher,
CharmstoreDownloader,
Expand Down
36 changes: 36 additions & 0 deletions tests/test_fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
BzrFetcher,
BzrMergeProposalFetcher,
GithubFetcher,
OpendevFetcher,
GitFetcher,
BitbucketFetcher,
LocalFetcher,
Expand Down Expand Up @@ -132,6 +133,41 @@ def test_can_fetch(self):
self.assertEqual(test, {})


class OpendevFetcherTest(unittest.TestCase):
def test_can_fetch(self):
f = OpendevFetcher.can_fetch

good_tests = [
f('https://opendev.com/charms/foo'),
f('https://www.opendev.com/charms/foo'),
f('[email protected]:charms/foo'),
]

bad_tests = [
f('http://www.opendev.com/charms/foo'),
f('http://opendev.com/charms/foo'),
f('gh:charms/foo'),
f('github:charms/foo'),
f('http://github.com/charms/foo'),
f('https://github.com/charms/foo'),
f('http://www.github.com/charms/foo'),
f('https://www.github.com/charms/foo'),
f('[email protected]:charms/foo'),
f('lp:~openstack-charmers/charms/bionic/foo'),
f('lp:~openstack-charmers/charms/bionic/foo/+merge/12345'),
f('bb:charms/foo'),
f('local:~/src/charms/bionic/foo'),
f('cs:bionic/foo'),
f('bundle:openstack-base/single'),
]

for test in good_tests:
self.assertEqual(test['repo'], 'charms/foo')

for test in bad_tests:
self.assertEqual(test, {})


class GitFetcherTest(unittest.TestCase):
def test_can_fetch(self):
f = GitFetcher.can_fetch
Expand Down

0 comments on commit 60d8387

Please sign in to comment.