Skip to content

Commit

Permalink
Adds parent property of repo endpoint (#12)
Browse files Browse the repository at this point in the history
* Adds parent_id property of repo endpoint

Signed-off-by: Guyzmo <[email protected]>

* Adds parent_id property of repo endpoint

Signed-off-by: Guyzmo <[email protected]>

* Adds parent_id property of repo endpoint

Signed-off-by: Guyzmo <[email protected]>

* Adds parent property of repo endpoint

Signed-off-by: Guyzmo <[email protected]>
  • Loading branch information
guyzmo authored and ethantkoenig committed May 8, 2017
1 parent e56c6bc commit aea8d9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gogs_client/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ class GogsRepo(GogsEntity):
An immutable representation of a Gogs repository
"""

def __init__(self, repo_id, owner, full_name, private, fork, default_branch,
def __init__(self, repo_id, owner, full_name, private, fork, parent, default_branch,
empty, size, urls, permissions, json={}):
super(GogsRepo, self).__init__(json=json)
self._repo_id = repo_id
self._owner = owner
self._full_name = full_name
self._private = private
self._fork = fork
self._parent = parent
self._default_branch = default_branch
self._empty = empty
self._size = size
Expand All @@ -116,15 +117,18 @@ def from_json(parsed_json):
full_name = json_get(parsed_json, "full_name")
private = json_get(parsed_json, "private")
fork = json_get(parsed_json, "fork")
parent = parsed_json.get("parent", None)
if parent:
parent = GogsRepo.from_json(parent)
default_branch = json_get(parsed_json, "default_branch")
empty = parsed_json.get("empty", None)
size = parsed_json.get("size", None)
urls = GogsRepo.Urls(json_get(parsed_json, "html_url"), json_get(parsed_json, "clone_url"),
json_get(parsed_json, "ssh_url"))
permissions = GogsRepo.Permissions.from_json(json_get(parsed_json, "permissions"))
return GogsRepo(repo_id=repo_id, owner=owner, full_name=full_name, private=private, fork=fork,
default_branch=default_branch, empty=empty, size=size, urls=urls,
permissions=permissions, json=parsed_json)
parent=parent, default_branch=default_branch, empty=empty, size=size,
urls=urls, permissions=permissions, json=parsed_json)

@property # named repo_id to avoid conflict with built-in id
def repo_id(self):
Expand Down Expand Up @@ -171,6 +175,15 @@ def fork(self):
"""
return self._fork

@property
def parent(self):
"""
Gets the repository's parent, when a fork
:rtype: GogsRepo
"""
return self._parent

@property
def default_branch(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUp(self):
"full_name": "unknwon/Hello-World",
"private": false,
"fork": false,
"parent": null,
"default_branch": "master",
"empty": false,
"size": 42,
Expand All @@ -50,6 +51,7 @@ def setUp(self):
"full_name": "unknwon/Hello-World",
"private": false,
"fork": false,
"parent": null,
"default_branch": "master",
"empty": false,
"size": 42,
Expand All @@ -73,6 +75,7 @@ def setUp(self):
"full_name": "unknwon/Hello-World-Again",
"private": false,
"fork": false,
"parent": null,
"default_branch": "master",
"empty": false,
"size": 42,
Expand Down Expand Up @@ -587,6 +590,7 @@ def assert_repos_equal(self, repo, expected):
self.assertEqual(repo.full_name, expected.full_name)
self.assertEqual(repo.private, expected.private)
self.assertEqual(repo.fork, expected.fork)
self.assertEqual(repo.parent, expected.parent)
self.assertEqual(repo.default_branch, expected.default_branch)
self.assertEqual(repo.size, expected.size)
self.assertEqual(repo.empty, expected.empty)
Expand Down

0 comments on commit aea8d9d

Please sign in to comment.