Add support for getting / replacing topics (#634) (#832)

* 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:
Will Yardley
2018-07-06 11:09:10 +08:00
committed by Wan Liuyang
parent 68af7250f9
commit c6802b515f
4 changed files with 69 additions and 0 deletions
+39
View File
@@ -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