diff --git a/github/Repository.py b/github/Repository.py index 55ae5862..18c852ad 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -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 `_ + :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 `_ @@ -2426,6 +2446,22 @@ class Repository(github.GithubObject.CompletableGithubObject): input=post_parameters ) + def replace_topics(self, topics): + """ + :calls: `PUT /repos/:owner/:repo/topics `_ + :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 `_ @@ -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 diff --git a/github/tests/ReplayData/Repository.testGetTopics.txt b/github/tests/ReplayData/Repository.testGetTopics.txt new file mode 100644 index 00000000..ea6095df --- /dev/null +++ b/github/tests/ReplayData/Repository.testGetTopics.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/repos/jacquev6/PyGithub/topics +{'Authorization': 'Basic login_and_password_removed', 'Accept': 'application/vnd.github.mercy-preview+json', 'User-Agent': 'PyGithub/Python'} +None +200 +[('content-length', '30'), ('x-runtime-rack', '0.081855'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('etag', '"c34823528b2c41eadf247bcea3b7dabc"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('referrer-policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-github-media-type', 'github.mercy-preview; format=json'), ('access-control-expose-headers', 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', '4C20:5398:FE4A88:26DA323:5AD7F450'), ('date', 'Thu, 19 Apr 2018 01:43:45 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1524105758')] +{"names":["testing","github"]} + diff --git a/github/tests/ReplayData/Repository.testReplaceTopics.txt b/github/tests/ReplayData/Repository.testReplaceTopics.txt new file mode 100644 index 00000000..9689b81f --- /dev/null +++ b/github/tests/ReplayData/Repository.testReplaceTopics.txt @@ -0,0 +1,11 @@ +https +PUT +api.github.com +None +/repos/jacquev6/PyGithub/topics +{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'Accept': 'application/vnd.github.mercy-preview+json', 'User-Agent': 'PyGithub/Python'} +{"names": ["github", "testing"]} +200 +[('content-length', '30'), ('x-runtime-rack', '0.081855'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('etag', '"c34823528b2c41eadf247bcea3b7dabc"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('referrer-policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('status', '200 OK'), ('x-ratelimit-remaining', '4994'), ('x-github-media-type', 'github.mercy-preview; format=json'), ('access-control-expose-headers', 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', '4C20:5398:FE4A88:26DA323:5AD7F450'), ('date', 'Thu, 19 Apr 2018 01:43:45 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1524105758')] +{"names": ["testing","github"]} + diff --git a/github/tests/Repository.py b/github/tests/Repository.py index 80cdfc3f..910aa68f 100644 --- a/github/tests/Repository.py +++ b/github/tests/Repository.py @@ -82,6 +82,7 @@ class Repository(Framework.TestCase): self.assertEqual(self.repo.source, None) self.assertEqual(self.repo.ssh_url, "git@github.com:jacquev6/PyGithub.git") self.assertEqual(self.repo.svn_url, "https://github.com/jacquev6/PyGithub") + self.assertEqual(self.repo.topics, None) self.assertEqual(self.repo.updated_at, datetime.datetime(2012, 5, 27, 6, 55, 28)) self.assertEqual(self.repo.url, "https://api.github.com/repos/jacquev6/PyGithub") self.assertEqual(self.repo.watchers, 15) @@ -711,6 +712,13 @@ class Repository(Framework.TestCase): def testGetLicense(self): self.assertEqual(len(self.repo.get_license().content), 47646) + def testGetTopics(self): + topic_list = self.repo.get_topics() + topic = u'github' + self.assertIn(topic, topic_list) + + def testReplaceTopics(self): + self.repo.replace_topics(['github', 'testing']) class LazyRepository(Framework.TestCase):