Skip to content

Commit

Permalink
Add support for 'visibility' attribute preview for Repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanner Cecchetti committed Mar 11, 2021
1 parent aa24030 commit 75fff25
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 36 deletions.
3 changes: 3 additions & 0 deletions github/Consts.py
Expand Up @@ -125,3 +125,6 @@

# https://developer.github.com/changes/2018-10-16-deployments-environments-states-and-auto-inactive-updates/
deploymentStatusEnhancementsPreview = "application/vnd.github.flash-preview+json"

# https://developer.github.com/changes/2019-12-03-internal-visibility-changes/
repoVisibilityPreview = "application/vnd.github.nebula-preview+json"
18 changes: 15 additions & 3 deletions github/Organization.py
Expand Up @@ -463,6 +463,7 @@ def create_repo(
description=github.GithubObject.NotSet,
homepage=github.GithubObject.NotSet,
private=github.GithubObject.NotSet,
visibility=github.GithubObject.NotSet,
has_issues=github.GithubObject.NotSet,
has_wiki=github.GithubObject.NotSet,
has_downloads=github.GithubObject.NotSet,
Expand Down Expand Up @@ -506,6 +507,9 @@ def create_repo(
assert private is github.GithubObject.NotSet or isinstance(
private, bool
), private
assert visibility is github.GithubObject.NotSet or isinstance(
visibility, str
), visibility
assert has_issues is github.GithubObject.NotSet or isinstance(
has_issues, bool
), has_issues
Expand Down Expand Up @@ -551,6 +555,8 @@ def create_repo(
post_parameters["homepage"] = homepage
if private is not github.GithubObject.NotSet:
post_parameters["private"] = private
if visibility is not github.GithubObject.NotSet:
post_parameters["visibility"] = visibility
if has_issues is not github.GithubObject.NotSet:
post_parameters["has_issues"] = has_issues
if has_wiki is not github.GithubObject.NotSet:
Expand All @@ -576,7 +582,10 @@ def create_repo(
if delete_branch_on_merge is not github.GithubObject.NotSet:
post_parameters["delete_branch_on_merge"] = delete_branch_on_merge
headers, data = self._requester.requestJsonAndCheck(
"POST", f"{self.url}/repos", input=post_parameters
"POST",
f"{self.url}/repos",
input=post_parameters,
headers={"Accept": Consts.repoVisibilityPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
Expand Down Expand Up @@ -920,7 +929,9 @@ def get_repo(self, name):
"""
assert isinstance(name, str), name
headers, data = self._requester.requestJsonAndCheck(
"GET", f"/repos/{self.login}/{name}"
"GET",
f"/repos/{self.login}/{name}",
headers={"Accept": Consts.repoVisibilityPreview},
)
return github.Repository.Repository(
self._requester, headers, data, completed=True
Expand All @@ -934,7 +945,7 @@ def get_repos(
):
"""
:calls: `GET /orgs/:org/repos <http://developer.github.com/v3/repos>`_
:param type: string ('all', 'public', 'private', 'forks', 'sources', 'member')
:param type: string ('all', 'public', 'private', 'forks', 'sources', 'member', 'internal')
:param sort: string ('created', 'updated', 'pushed', 'full_name')
:param direction: string ('asc', desc')
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
Expand All @@ -957,6 +968,7 @@ def get_repos(
self._requester,
f"{self.url}/repos",
url_parameters,
headers={"Accept": Consts.repoVisibilityPreview},
)

def get_team(self, id):
Expand Down
11 changes: 11 additions & 0 deletions github/Repository.py
Expand Up @@ -787,6 +787,14 @@ def url(self):
self._completeIfNotSet(self._url)
return self._url.value

@property
def visibility(self):
"""
:type: string
"""
self._completeIfNotSet(self._visibility)
return self._visibility.value

@property
def watchers(self):
"""
Expand Down Expand Up @@ -3726,6 +3734,7 @@ def _initAttributes(self):
self._trees_url = github.GithubObject.NotSet
self._updated_at = github.GithubObject.NotSet
self._url = github.GithubObject.NotSet
self._visibility = github.GithubObject.NotSet
self._watchers = github.GithubObject.NotSet
self._watchers_count = github.GithubObject.NotSet

Expand Down Expand Up @@ -3932,6 +3941,8 @@ def _useAttributes(self, attributes):
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "visibility" in attributes: # pragma no branch
self._visibility = self._makeStringAttribute(attributes["visibility"])
if "watchers" in attributes: # pragma no branch
self._watchers = self._makeIntAttribute(attributes["watchers"])
if "watchers_count" in attributes: # pragma no branch
Expand Down
1 change: 1 addition & 0 deletions tests/Organization.py
Expand Up @@ -321,6 +321,7 @@ def testCreateRepoWithAllArguments(self):
description="Repo created by PyGithub",
homepage="http://foobar.com",
private=False,
visibility="public",
has_issues=False,
has_projects=False,
has_wiki=False,
Expand Down
Expand Up @@ -14,9 +14,9 @@ GET
api.github.com
None
/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id
{'User-Agent': 'PyGithub/Python'}
{'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '2291'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4bcc5321db433ac18171c121303c77d2"'), ('date', 'Tue, 29 May 2012 18:11:16 GMT'), ('content-type', 'application/json; charset=utf-8')]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","has_downloads":true,"watchers":2,"updated_at":"2012-02-16T21:51:15Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","html_url":"https://github.com/BeaverSoftware/FatherBeaver","has_wiki":true,"has_issues":true,"fork":false,"git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"FatherBeaver","language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","pushed_at":null,"created_at":"2012-02-09T19:32:21Z","id":3400397,"full_name":"BeaverSoftware/FatherBeaver"},{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-29T18:09:14Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","html_url":"https://github.com/BeaverSoftware/PyGithub","has_wiki":false,"has_issues":false,"fork":true,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","forks":0,"size":428,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-29T18:05:10Z","created_at":"2012-05-29T18:03:19Z","id":4485562,"full_name":"BeaverSoftware/PyGithub"}]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","has_downloads":true,"watchers":2,"updated_at":"2012-02-16T21:51:15Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","html_url":"https://github.com/BeaverSoftware/FatherBeaver","has_wiki":true,"has_issues":true,"fork":false,"git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","forks":1,"size":0,"private":false,"visibility":"public","open_issues":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"FatherBeaver","language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","pushed_at":null,"created_at":"2012-02-09T19:32:21Z","id":3400397,"full_name":"BeaverSoftware/FatherBeaver"},{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-29T18:09:14Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","html_url":"https://github.com/BeaverSoftware/PyGithub","has_wiki":false,"has_issues":false,"fork":true,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","forks":0,"size":428,"private":false,"visibility":"public","open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-29T18:05:10Z","created_at":"2012-05-29T18:03:19Z","id":4485562,"full_name":"BeaverSoftware/PyGithub"}]

Expand Up @@ -14,20 +14,20 @@ GET
api.github.com
None
/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id
{'User-Agent': 'PyGithub/Python'}
{'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '2291'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4bcc5321db433ac18171c121303c77d2"'), ('date', 'Tue, 29 May 2012 18:11:16 GMT'), ('content-type', 'application/json; charset=utf-8'), ('link', '<https://api.github.com/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id&page=2>; rel="next", <https://api.github.com/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id&page=2>; rel="last"')]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","has_downloads":true,"watchers":2,"updated_at":"2012-02-16T21:51:15Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","html_url":"https://github.com/BeaverSoftware/FatherBeaver","has_wiki":true,"has_issues":true,"fork":false,"git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","forks":1,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"FatherBeaver","language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","pushed_at":null,"created_at":"2012-02-09T19:32:21Z","id":3400397,"full_name":"BeaverSoftware/FatherBeaver"}]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","has_downloads":true,"watchers":2,"updated_at":"2012-02-16T21:51:15Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","html_url":"https://github.com/BeaverSoftware/FatherBeaver","has_wiki":true,"has_issues":true,"fork":false,"git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","forks":1,"size":0,"private":false,"visibility":"public","open_issues":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"FatherBeaver","language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","pushed_at":null,"created_at":"2012-02-09T19:32:21Z","id":3400397,"full_name":"BeaverSoftware/FatherBeaver"}]

https
GET
api.github.com
None
/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id&page=2
{'User-Agent': 'PyGithub/Python'}
{'User-Agent': 'PyGithub/Python', 'Accept': 'application/vnd.github.nebula-preview+json'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4987'), ('content-length', '2291'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"4bcc5321db433ac18171c121303c77d2"'), ('date', 'Tue, 29 May 2012 18:11:16 GMT'), ('content-type', 'application/json; charset=utf-8'), ('link', '<https://api.github.com/orgs/BeaverSoftware/repos?client_secret=client_secret&type=public&client_id=client_id&page=2>; rel="last"')]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-29T18:09:14Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","html_url":"https://github.com/BeaverSoftware/PyGithub","has_wiki":false,"has_issues":false,"fork":true,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","forks":0,"size":428,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-29T18:05:10Z","created_at":"2012-05-29T18:03:19Z","id":4485562,"full_name":"BeaverSoftware/PyGithub"}]
[{"mirror_url":null,"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-29T18:09:14Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","html_url":"https://github.com/BeaverSoftware/PyGithub","has_wiki":false,"has_issues":false,"fork":true,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","forks":0,"size":428,"private":false,"visibility":"public","open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-29T18:05:10Z","created_at":"2012-05-29T18:03:19Z","id":4485562,"full_name":"BeaverSoftware/PyGithub"}]

0 comments on commit 75fff25

Please sign in to comment.