mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
* Add support for getting and replacing topics on a repository #634 * Add / fix tests, accept list vs dict for replace_topics (#634)
This commit is contained in:
committed by
Wan Liuyang
parent
68af7250f9
commit
c6802b515f
@@ -670,6 +670,14 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
self._completeIfNotSet(self._teams_url)
|
||||
return self._teams_url.value
|
||||
|
||||
@property
|
||||
def topics(self):
|
||||
"""
|
||||
:type: list of strings
|
||||
"""
|
||||
self._completeIfNotSet(self._topics)
|
||||
return self._topics.value
|
||||
|
||||
@property
|
||||
def trees_url(self):
|
||||
"""
|
||||
@@ -2304,6 +2312,18 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
None
|
||||
)
|
||||
|
||||
def get_topics(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/topics <https://developer.github.com/v3/repos/#list-all-topics-for-a-repository>`_
|
||||
:rtype: list of strings
|
||||
"""
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.url + "/topics",
|
||||
headers={'Accept': 'application/vnd.github.mercy-preview+json'}
|
||||
)
|
||||
return data['names']
|
||||
|
||||
def get_watchers(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/watchers <http://developer.github.com/v3/activity/starring>`_
|
||||
@@ -2426,6 +2446,22 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
input=post_parameters
|
||||
)
|
||||
|
||||
def replace_topics(self, topics):
|
||||
"""
|
||||
:calls: `PUT /repos/:owner/:repo/topics <http://developer.github.com/v3/repos>`_
|
||||
:param topics: list of strings
|
||||
:rtype: None
|
||||
"""
|
||||
post_parameters = {
|
||||
'names': topics
|
||||
}
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PUT",
|
||||
self.url + "/topics",
|
||||
headers={'Accept': 'application/vnd.github.mercy-preview+json'},
|
||||
input=post_parameters
|
||||
)
|
||||
|
||||
def remove_from_collaborators(self, collaborator):
|
||||
"""
|
||||
:calls: `DELETE /repos/:owner/:repo/collaborators/:user <http://developer.github.com/v3/repos/collaborators>`_
|
||||
@@ -2564,6 +2600,7 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
self._svn_url = github.GithubObject.NotSet
|
||||
self._tags_url = github.GithubObject.NotSet
|
||||
self._teams_url = github.GithubObject.NotSet
|
||||
self._topics = github.GithubObject.NotSet
|
||||
self._trees_url = github.GithubObject.NotSet
|
||||
self._updated_at = github.GithubObject.NotSet
|
||||
self._url = github.GithubObject.NotSet
|
||||
@@ -2709,6 +2746,8 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
self._teams_url = self._makeStringAttribute(attributes["teams_url"])
|
||||
if "trees_url" in attributes: # pragma no branch
|
||||
self._trees_url = self._makeStringAttribute(attributes["trees_url"])
|
||||
if "topics" in attributes: # pragma no branch
|
||||
self._topics = self._makeListOfStringsAttribute(attributes["topics"])
|
||||
if "updated_at" in attributes: # pragma no branch
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "url" in attributes: # pragma no branch
|
||||
|
||||
Reference in New Issue
Block a user