-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opendev.org https and git fetcher
- Loading branch information
Ryan Beisner
committed
Oct 4, 2019
1 parent
cd8792b
commit 60d8387
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -358,6 +373,7 @@ def check_output(cmd, **kw): | |
BzrFetcher, | ||
BzrMergeProposalFetcher, | ||
GithubFetcher, | ||
OpendevFetcher, | ||
BitbucketFetcher, | ||
LocalFetcher, | ||
CharmstoreDownloader, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
BzrFetcher, | ||
BzrMergeProposalFetcher, | ||
GithubFetcher, | ||
OpendevFetcher, | ||
GitFetcher, | ||
BitbucketFetcher, | ||
LocalFetcher, | ||
|
@@ -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 | ||
|