Skip to content

Commit ffbd61f

Browse files
ryan-beisnertimClicks
authored andcommitted
Add opendev.org https and git fetcher (juju#553)
Related to juju#552 https://bugs.launchpad.net/charm-barbican/+bug/1846263
1 parent a0fd37c commit ffbd61f

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

charmtools/fetchers.py

+16
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ def fetch(self, dir_):
195195
return rename(dir_)
196196

197197

198+
class OpendevFetcher(Fetcher):
199+
MATCH = re.compile(r"""
200+
^(https:\/\/(www\.)?opendev\.org\/|git@opendev.org:)
201+
(?P<repo>[^@]*)(@(?P<revision>.*))?$
202+
""", re.VERBOSE)
203+
204+
def fetch(self, dir_):
205+
dir_ = tempfile.mkdtemp(dir=dir_)
206+
url = 'https://opendev.org/' + self.repo
207+
git('clone {} {}'.format(url, dir_))
208+
if self.revision:
209+
git('checkout {}'.format(self.revision), cwd=dir_)
210+
return rename(dir_)
211+
212+
198213
class GitFetcher(Fetcher):
199214
"""Generic git fetcher.
200215
@@ -358,6 +373,7 @@ def check_output(cmd, **kw):
358373
BzrFetcher,
359374
BzrMergeProposalFetcher,
360375
GithubFetcher,
376+
OpendevFetcher,
361377
BitbucketFetcher,
362378
LocalFetcher,
363379
CharmstoreDownloader,

tests/test_fetchers.py

+77
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
BzrFetcher,
88
BzrMergeProposalFetcher,
99
GithubFetcher,
10+
OpendevFetcher,
1011
GitFetcher,
1112
BitbucketFetcher,
1213
LocalFetcher,
@@ -132,6 +133,82 @@ def test_can_fetch(self):
132133
self.assertEqual(test, {})
133134

134135

136+
class OpendevFetcherGenericTest(unittest.TestCase):
137+
def test_can_fetch(self):
138+
f = OpendevFetcher.can_fetch
139+
140+
good_tests = [
141+
f('https://opendev.org/charms/foo'),
142+
f('https://www.opendev.org/charms/foo'),
143+
f('git@opendev.org:charms/foo'),
144+
]
145+
146+
bad_tests = [
147+
f('http://www.opendev.org/charms/foo'),
148+
f('http://opendev.org/charms/foo'),
149+
f('https://opendev.com/charms/foo'),
150+
f('https://www.opendev.com/charms/foo'),
151+
f('git@opendev.com:charms/foo'),
152+
f('gh:charms/foo'),
153+
f('github:charms/foo'),
154+
f('http://github.com/charms/foo'),
155+
f('https://github.com/charms/foo'),
156+
f('http://www.github.com/charms/foo'),
157+
f('https://www.github.com/charms/foo'),
158+
f('git@github.com:charms/foo'),
159+
f('lp:~openstack-charmers/charms/bionic/foo'),
160+
f('lp:~openstack-charmers/charms/bionic/foo/+merge/12345'),
161+
f('bb:charms/foo'),
162+
f('local:~/src/charms/bionic/foo'),
163+
f('cs:bionic/foo'),
164+
f('bundle:openstack-base/single'),
165+
]
166+
167+
for test in good_tests:
168+
self.assertEqual(test['repo'], 'charms/foo')
169+
170+
for test in bad_tests:
171+
self.assertEqual(test, {})
172+
173+
174+
class OpendevFetcherSpecificTest(unittest.TestCase):
175+
def test_can_fetch(self):
176+
f = OpendevFetcher.can_fetch
177+
178+
good_tests = [
179+
f('https://opendev.org/x/charm-interface-barbican-hsm'),
180+
f('https://www.opendev.org/x/charm-interface-barbican-hsm'),
181+
f('git@opendev.org:x/charm-interface-barbican-hsm'),
182+
]
183+
184+
bad_tests = [
185+
f('http://opendev.org/x/charm-interface-barbican-hsm'),
186+
f('http://www.opendev.org/x/charm-interface-barbican-hsm'),
187+
f('https://opendev.com/x/charm-interface-barbican-hsm'),
188+
f('https://www.opendev.com/x/charm-interface-barbican-hsm'),
189+
f('git@opendev.com:x/charm-interface-barbican-hsm'),
190+
f('gh:x/charm-interface-barbican-hsm'),
191+
f('github:x/charm-interface-barbican-hsm'),
192+
f('http://github.com/x/charm-interface-barbican-hsm'),
193+
f('https://github.com/x/charm-interface-barbican-hsm'),
194+
f('http://www.github.com/x/charm-interface-barbican-hsm'),
195+
f('https://www.github.com/x/charm-interface-barbican-hsm'),
196+
f('git@github.com:x/charm-interface-barbican-hsm'),
197+
f('lp:~openstack-charmers/x/charm-interface-barbican-hsm'),
198+
f('lp:~openstack-charmers/x/charm-interface-barbican-hsm/+merge/12345'),
199+
f('bb:x/charm-interface-barbican-hsm'),
200+
f('local:~/src/charms/bionic/x/charm-interface-barbican-hsm'),
201+
f('cs:bionic/x/charm-interface-barbican-hsm'),
202+
f('bundle:openstack-base/x/charm-interface-barbican-hsm'),
203+
]
204+
205+
for test in good_tests:
206+
self.assertEqual(test['repo'], 'x/charm-interface-barbican-hsm')
207+
208+
for test in bad_tests:
209+
self.assertEqual(test, {})
210+
211+
135212
class GitFetcherTest(unittest.TestCase):
136213
def test_can_fetch(self):
137214
f = GitFetcher.can_fetch

0 commit comments

Comments
 (0)