Skip to content

Commit bf5a6d8

Browse files
committed
Adds support for both size and empty
Signed-off-by: Guyzmo <[email protected]>
1 parent 6ae13ca commit bf5a6d8

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

gogs_client/entities.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ def json_get(parsed_json, key):
1515

1616
class GogsEntity(object):
1717
def __init__(self, json):
18-
self.json = json
18+
self._json = json
1919

20+
@property
21+
def json(self):
22+
return self._json
2023

2124
class GogsUser(GogsEntity):
2225
"""
@@ -30,7 +33,6 @@ def __init__(self, user_id, username, full_name, email, avatar_url, json={}):
3033
self._full_name = full_name
3134
self._email = email
3235
self._avatar_url = avatar_url
33-
self._json = json
3436

3537
@staticmethod
3638
def from_json(parsed_json):
@@ -94,14 +96,16 @@ class GogsRepo(GogsEntity):
9496
"""
9597

9698
def __init__(self, repo_id, owner, full_name, private, fork, default_branch,
97-
urls, permissions, json={}):
99+
empty, size, urls, permissions, json={}):
98100
super(GogsRepo, self).__init__(json=json)
99101
self._repo_id = repo_id
100102
self._owner = owner
101103
self._full_name = full_name
102104
self._private = private
103105
self._fork = fork
104106
self._default_branch = default_branch
107+
self._empty = empty
108+
self._size = size
105109
self._urls = urls
106110
self._permissions = permissions
107111

@@ -113,11 +117,14 @@ def from_json(parsed_json):
113117
private = json_get(parsed_json, "private")
114118
fork = json_get(parsed_json, "fork")
115119
default_branch = json_get(parsed_json, "default_branch")
120+
empty = parsed_json.get("empty", None)
121+
size = parsed_json.get("size", None)
116122
urls = GogsRepo.Urls(json_get(parsed_json, "html_url"), json_get(parsed_json, "clone_url"),
117123
json_get(parsed_json, "ssh_url"))
118124
permissions = GogsRepo.Permissions.from_json(json_get(parsed_json, "permissions"))
119125
return GogsRepo(repo_id=repo_id, owner=owner, full_name=full_name, private=private, fork=fork,
120-
default_branch=default_branch, urls=urls, permissions=permissions, json=parsed_json)
126+
default_branch=default_branch, empty=empty, size=size, urls=urls,
127+
permissions=permissions, json=parsed_json)
121128

122129
@property # named repo_id to avoid conflict with built-in id
123130
def repo_id(self):
@@ -169,10 +176,28 @@ def default_branch(self):
169176
"""
170177
The name of the default branch
171178
172-
:rtype: bool
179+
:rtype: str
173180
"""
174181
return self._default_branch
175182

183+
@property
184+
def empty(self):
185+
"""
186+
Whether the repository is empty
187+
188+
:rtype: bool
189+
"""
190+
return self._empty
191+
192+
@property
193+
def size(self):
194+
"""
195+
Size of the repository in kilobytes
196+
197+
:rtype: int
198+
"""
199+
return self._size
200+
176201
@property
177202
def urls(self):
178203
"""

tests/interface_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def setUp(self):
2727
"private": false,
2828
"fork": false,
2929
"default_branch": "master",
30+
"empty": false,
31+
"size": 42,
3032
"html_url": "http://localhost:3000/unknwon/Hello-World",
3133
"clone_url": "http://localhost:3000/unknwon/hello-world.git",
3234
"ssh_url": "jiahuachen@localhost:unknwon/hello-world.git",
@@ -49,6 +51,8 @@ def setUp(self):
4951
"private": false,
5052
"fork": false,
5153
"default_branch": "master",
54+
"empty": false,
55+
"size": 42,
5256
"html_url": "http://localhost:3000/unknwon/Hello-World",
5357
"clone_url": "http://localhost:3000/unknwon/hello-world.git",
5458
"ssh_url": "jiahuachen@localhost:unknwon/hello-world.git",
@@ -70,6 +74,8 @@ def setUp(self):
7074
"private": false,
7175
"fork": false,
7276
"default_branch": "master",
77+
"empty": false,
78+
"size": 42,
7379
"html_url": "http://localhost:3000/unknwon/Hello-World-Again",
7480
"clone_url": "http://localhost:3000/unknwon/hello-world-again.git",
7581
"ssh_url": "jiahuachen@localhost:unknwon/hello-world-again.git",
@@ -581,6 +587,9 @@ def assert_repos_equal(self, repo, expected):
581587
self.assertEqual(repo.full_name, expected.full_name)
582588
self.assertEqual(repo.private, expected.private)
583589
self.assertEqual(repo.fork, expected.fork)
590+
self.assertEqual(repo.default_branch, expected.default_branch)
591+
self.assertEqual(repo.size, expected.size)
592+
self.assertEqual(repo.empty, expected.empty)
584593
self.assertEqual(repo.urls.html_url, expected.urls.html_url)
585594
self.assertEqual(repo.urls.clone_url, expected.urls.clone_url)
586595
self.assertEqual(repo.urls.ssh_url, expected.urls.ssh_url)

0 commit comments

Comments
 (0)