Skip to content

Commit 2b352fb

Browse files
jacqueriesfdye
authored andcommitted
Add missing properties to Repository (#842)
Closes #784 Closes #785 First commit fixes a small bug that I observed while trying to record some new test fixtures: the stringification of the headers is not correctly printed as a list of tuples, but as an `iteritems` object, so I forced the list evaluation. Second commit adds the missing properties `allow_merge_commit`, `allow_rebase_merge`, `allow_squash_merge`, and `has_projects` to the `Repository` class. Note however that I ran into some trouble while modifying the `edit` method of the `Repository` class to make use of the new properties, specifically while writing tests, so I will fix the `edit` method in a future PR.
1 parent 1a90f5d commit 2b352fb

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

github/Repository.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Copyright 2016 Dustin Spicuzza <dustin@virtualroadside.com> #
3030
# Copyright 2016 Enix Yu <enix223@163.com> #
3131
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
32-
# Copyright 2016 Per Øyvind Karlsen <proyvind@moondrake.org> #
32+
# Copyright 2016 Per Øyvind Karlsen <proyvind@moondrake.org> #
3333
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
3434
# Copyright 2016 Sylvus <Sylvus@users.noreply.github.com> #
3535
# Copyright 2016 fukatani <nannyakannya@gmail.com> #
@@ -41,7 +41,7 @@
4141
# Copyright 2017 Jannis Gebauer <ja.geb@me.com> #
4242
# Copyright 2017 Jason White <jasonwhite@users.noreply.github.com> #
4343
# Copyright 2017 Jimmy Zelinskie <jimmy.zelinskie+git@gmail.com> #
44-
# Copyright 2017 Nhomar Hernández [Vauxoo] <nhomar@vauxoo.com> #
44+
# Copyright 2017 Nhomar Hernández [Vauxoo] <nhomar@vauxoo.com> #
4545
# Copyright 2017 Simon <spam@esemi.ru> #
4646
# Copyright 2018 Andrew Smith <espadav8@gmail.com> #
4747
# Copyright 2018 Brian Torres-Gil <btorres-gil@paloaltonetworks.com> #
@@ -52,6 +52,7 @@
5252
# Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com> #
5353
# Copyright 2018 Wan Liuyang <tsfdye@gmail.com> #
5454
# Copyright 2018 sfdye <tsfdye@gmail.com> #
55+
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
5556
# #
5657
# This file is part of PyGithub. #
5758
# http://pygithub.readthedocs.io/ #
@@ -126,6 +127,30 @@ class Repository(github.GithubObject.CompletableGithubObject):
126127
def __repr__(self):
127128
return self.get__repr__({"full_name": self._full_name.value})
128129

130+
@property
131+
def allow_merge_commit(self):
132+
"""
133+
:type: bool
134+
"""
135+
self._completeIfNotSet(self._allow_merge_commit)
136+
return self._allow_merge_commit.value
137+
138+
@property
139+
def allow_rebase_merge(self):
140+
"""
141+
:type: bool
142+
"""
143+
self._completeIfNotSet(self._allow_rebase_merge)
144+
return self._allow_rebase_merge.value
145+
146+
@property
147+
def allow_squash_merge(self):
148+
"""
149+
:type: bool
150+
"""
151+
self._completeIfNotSet(self._allow_squash_merge)
152+
return self._allow_squash_merge.value
153+
129154
@property
130155
def archived(self):
131156
"""
@@ -350,6 +375,14 @@ def has_issues(self):
350375
self._completeIfNotSet(self._has_issues)
351376
return self._has_issues.value
352377

378+
@property
379+
def has_projects(self):
380+
"""
381+
:type: bool
382+
"""
383+
self._completeIfNotSet(self._has_projects)
384+
return self._has_projects.value
385+
353386
@property
354387
def has_wiki(self):
355388
"""
@@ -2536,6 +2569,9 @@ def get_release_asset(self, id):
25362569
return github.GitReleaseAsset.GitReleaseAsset(self._requester, resp_headers, data, completed=True)
25372570

25382571
def _initAttributes(self):
2572+
self._allow_merge_commit = github.GithubObject.NotSet
2573+
self._allow_rebase_merge = github.GithubObject.NotSet
2574+
self._allow_squash_merge = github.GithubObject.NotSet
25392575
self._archived = github.GithubObject.NotSet
25402576
self._archive_url = github.GithubObject.NotSet
25412577
self._assignees_url = github.GithubObject.NotSet
@@ -2564,6 +2600,7 @@ def _initAttributes(self):
25642600
self._git_url = github.GithubObject.NotSet
25652601
self._has_downloads = github.GithubObject.NotSet
25662602
self._has_issues = github.GithubObject.NotSet
2603+
self._has_projects = github.GithubObject.NotSet
25672604
self._has_wiki = github.GithubObject.NotSet
25682605
self._homepage = github.GithubObject.NotSet
25692606
self._hooks_url = github.GithubObject.NotSet
@@ -2612,6 +2649,12 @@ def _initAttributes(self):
26122649
self._watchers_count = github.GithubObject.NotSet
26132650

26142651
def _useAttributes(self, attributes):
2652+
if "allow_merge_commit" in attributes: # pragma no branch
2653+
self._allow_merge_commit = self._makeBoolAttribute(attributes["allow_merge_commit"])
2654+
if "allow_rebase_merge" in attributes: # pragma no branch
2655+
self._allow_rebase_merge = self._makeBoolAttribute(attributes["allow_rebase_merge"])
2656+
if "allow_squash_merge" in attributes: # pragma no branch
2657+
self._allow_squash_merge = self._makeBoolAttribute(attributes["allow_squash_merge"])
26152658
if "archived" in attributes: # pragma no branch
26162659
self._archived = self._makeBoolAttribute(attributes["archived"])
26172660
if "archive_url" in attributes: # pragma no branch
@@ -2668,6 +2711,8 @@ def _useAttributes(self, attributes):
26682711
self._has_downloads = self._makeBoolAttribute(attributes["has_downloads"])
26692712
if "has_issues" in attributes: # pragma no branch
26702713
self._has_issues = self._makeBoolAttribute(attributes["has_issues"])
2714+
if "has_projects" in attributes: # pragma no branch
2715+
self._has_projects = self._makeBoolAttribute(attributes["has_projects"])
26712716
if "has_wiki" in attributes: # pragma no branch
26722717
self._has_wiki = self._makeBoolAttribute(attributes["has_wiki"])
26732718
if "homepage" in attributes: # pragma no branch

github/tests/AuthenticatedUser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
# Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net> #
99
# Copyright 2016 Jannis Gebauer <ja.geb@me.com> #
1010
# Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com> #
11-
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
11+
# Copyright 2017 Balázs Rostás <rostas.balazs@gmail.com> #
1212
# Copyright 2017 Jannis Gebauer <ja.geb@me.com> #
1313
# Copyright 2018 sfdye <tsfdye@gmail.com> #
14+
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
1415
# #
1516
# This file is part of PyGithub. #
1617
# http://pygithub.readthedocs.io/ #
@@ -140,7 +141,8 @@ def testCreateRepository(self):
140141

141142
def testCreateRepositoryWithAllArguments(self):
142143
repo = self.user.create_repo(name="TestPyGithub", description="Repo created by PyGithub", homepage="http://foobar.com",
143-
private=False, has_issues=False, has_wiki=False, has_downloads=False)
144+
private=False, has_issues=False, has_projects=False, has_wiki=False, has_downloads=False,
145+
allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True)
144146
self.assertEqual(repo.url, "https://api.github.com/repos/jacquev6/TestPyGithub")
145147

146148
def testCreateRepositoryWithAutoInit(self):

github/tests/Framework.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Copyright 2017 Hugo <hugovk@users.noreply.github.com> #
1414
# Copyright 2017 Simon <spam@esemi.ru> #
1515
# Copyright 2018 sfdye <tsfdye@gmail.com> #
16+
# Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com> #
1617
# #
1718
# This file is part of PyGithub. #
1819
# http://pygithub.readthedocs.io/ #
@@ -115,7 +116,7 @@ def getresponse(self):
115116
output = res.read()
116117

117118
self.__writeLine(str(status))
118-
self.__writeLine(str(headers))
119+
self.__writeLine(str(list(headers)))
119120
if atLeastPython3: # In Py3, return from "read" is bytes
120121
self.__writeLine(output)
121122
else:

github/tests/Organization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def testCreateRepoWithMinimalArguments(self):
198198
def testCreateRepoWithAllArguments(self):
199199
team = self.org.get_team(141496)
200200
repo = self.org.create_repo(name="TestPyGithub2", description="Repo created by PyGithub", homepage="http://foobar.com",
201-
private=False, has_issues=False, has_wiki=False, has_downloads=False, team_id=team.id)
201+
private=False, has_issues=False, has_projects=False, has_wiki=False, has_downloads=False,
202+
team_id=team.id, allow_squash_merge=False, allow_merge_commit=False, allow_rebase_merge=True)
202203
self.assertEqual(repo.url, "https://api.github.com/repos/BeaverSoftware/TestPyGithub2")
203204

204205
def testCreateRepositoryWithAutoInit(self):

github/tests/ReplayData/AuthenticatedUser.testCreateRepositoryWithAllArguments.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ api.github.com
44
None
55
/user/repos
66
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
7-
{"has_wiki": false, "name": "TestPyGithub", "has_downloads": false, "private": false, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub"}
7+
{"has_wiki": false, "name": "TestPyGithub", "has_downloads": false, "private": false, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true}
88
201
99
[('status', '201 Created'), ('x-ratelimit-remaining', '4979'), ('content-length', '1111'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1c6473a60481c33b28a926041f763fce"'), ('date', 'Sat, 26 May 2012 09:55:27 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/TestPyGithub')]
10-
{"clone_url":"https://github.com/jacquev6/TestPyGithub.git","has_downloads":false,"watchers":1,"git_url":"git://github.com/jacquev6/TestPyGithub.git","updated_at":"2012-05-26T09:55:27Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/jacquev6/TestPyGithub","has_wiki":false,"has_issues":false,"fork":false,"forks":1,"mirror_url":null,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/jacquev6/TestPyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"name":"TestPyGithub","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:jacquev6/TestPyGithub.git","pushed_at":"2012-05-26T09:55:27Z","created_at":"2012-05-26T09:55:27Z","id":4454027,"html_url":"https://github.com/jacquev6/TestPyGithub","full_name":"jacquev6/TestPyGithub"}
10+
{"clone_url":"https://github.com/jacquev6/TestPyGithub.git","has_downloads":false,"watchers":1,"git_url":"git://github.com/jacquev6/TestPyGithub.git","updated_at":"2012-05-26T09:55:27Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/jacquev6/TestPyGithub","has_wiki":false,"has_issues":false,"fork":false,"forks":1,"mirror_url":null,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/jacquev6/TestPyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"name":"TestPyGithub","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:jacquev6/TestPyGithub.git","pushed_at":"2012-05-26T09:55:27Z","created_at":"2012-05-26T09:55:27Z","id":4454027,"html_url":"https://github.com/jacquev6/TestPyGithub","full_name":"jacquev6/TestPyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true}
1111

github/tests/ReplayData/Organization.testCreateRepoWithAllArguments.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ api.github.com
1515
None
1616
/orgs/BeaverSoftware/repos
1717
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
18-
{"has_wiki": false, "name": "TestPyGithub2", "has_downloads": false, "private": false, "team_id": 141496, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub"}
18+
{"has_wiki": false, "name": "TestPyGithub2", "has_downloads": false, "private": false, "team_id": 141496, "has_issues": false, "homepage": "http://foobar.com", "description": "Repo created by PyGithub", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true}
1919
201
2020
[('status', '201 Created'), ('x-ratelimit-remaining', '4969'), ('content-length', '1501'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"feb513e01eaf8e89967068fe8ed44cc7"'), ('date', 'Sun, 27 May 2012 05:20:43 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/BeaverSoftware/TestPyGithub2')]
21-
{"organization":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"clone_url":"https://github.com/BeaverSoftware/TestPyGithub2.git","has_downloads":false,"watchers":1,"updated_at":"2012-05-27T05:20:42Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub2","mirror_url":null,"has_wiki":false,"has_issues":false,"fork":false,"forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub2","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"name":"TestPyGithub2","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub2.git","pushed_at":"2012-05-27T05:20:42Z","created_at":"2012-05-27T05:20:42Z","id":4460019,"git_url":"git://github.com/BeaverSoftware/TestPyGithub2.git","html_url":"https://github.com/BeaverSoftware/TestPyGithub2","full_name":"BeaverSoftware/TestPyGithub2"}
21+
{"organization":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"clone_url":"https://github.com/BeaverSoftware/TestPyGithub2.git","has_downloads":false,"watchers":1,"updated_at":"2012-05-27T05:20:42Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://foobar.com","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub2","mirror_url":null,"has_wiki":false,"has_issues":false,"fork":false,"forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub2","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","login":"BeaverSoftware","id":1424031},"name":"TestPyGithub2","language":null,"description":"Repo created by PyGithub","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub2.git","pushed_at":"2012-05-27T05:20:42Z","created_at":"2012-05-27T05:20:42Z","id":4460019,"git_url":"git://github.com/BeaverSoftware/TestPyGithub2.git","html_url":"https://github.com/BeaverSoftware/TestPyGithub2","full_name":"BeaverSoftware/TestPyGithub2", "has_projects": false, "allow_squash_merge": false, "allow_merge_commit": false, "allow_rebase_merge": true}
2222

0 commit comments

Comments
 (0)