Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow rewriting repo and owner #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/00.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow rewriting repo and owner
21 changes: 21 additions & 0 deletions giturlparse/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def valid(self):
##
# Alias properties
##
def _update_url(self):
protocol = getattr(self, "protocol", None)
if protocol:
self.url = self.format(protocol)
self._parsed["url"] = self.format(protocol)

@property
def host(self):
return self.domain
Expand All @@ -50,6 +56,21 @@ def resource(self):
def name(self):
return self.repo

@name.setter
def name(self, new_name):
self.repo = new_name
self._parsed["repo"] = new_name
self._update_url()

@property
def owner(self):
return self._parsed["owner"]

@owner.setter
def owner(self, new_owner):
self._parsed["owner"] = new_owner
self._update_url()

@property
def user(self):
if hasattr(self, "_user"):
Expand Down
24 changes: 24 additions & 0 deletions giturlparse/tests/test_rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@
)


REWRITE_COMPONENTS = {
"name": {
"source": "[email protected]:Org/Repo.git",
"value": "New-repo",
"expected": "[email protected]:Org/New-repo.git",
},
"owner": {
"source": "[email protected]:Org/Repo.git",
"value": "New-Org",
"expected": "[email protected]:New-Org/Repo.git",
},
}


class UrlRewriteTestCase(unittest.TestCase):
def _test_rewrite(self, source, protocol, expected):
parsed = parse(source)
Expand All @@ -81,6 +95,16 @@ def test_rewrites(self):
for data in REWRITE_URLS:
self._test_rewrite(*data)

def _test_rewrite_components(self, field, data):
parsed = parse(data["source"])
setattr(parsed, field, data["value"])
self.assertTrue(parsed.valid, "Invalid Url: %s" % data["source"])
return self.assertEqual(parsed.url, data["expected"])

def test_rewrite_components(self):
for field, data in REWRITE_COMPONENTS.items():
self._test_rewrite_components(field, data)


# Test Suite
suite = unittest.TestLoader().loadTestsFromTestCase(UrlRewriteTestCase)