From dbc6f5abf07730b4e0035ffafe2198ab86acf4ce Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 7 Dec 2017 23:11:10 -0500 Subject: [PATCH] Add read_only attribute to Deploy Keys (#570) --- github/Repository.py | 7 +++++-- github/RepositoryKey.py | 11 +++++++++++ github/tests/ReplayData/Repository.testCreateKey.txt | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index 0407b706..d077e254 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -580,7 +580,7 @@ class Repository(github.GithubObject.CompletableGithubObject): """ self._completeIfNotSet(self._subscribers_url) return self._subscribers_url.value - + @property def subscribers_count(self): """ @@ -912,18 +912,21 @@ class Repository(github.GithubObject.CompletableGithubObject): ) return github.Issue.Issue(self._requester, headers, data, completed=True) - def create_key(self, title, key): + def create_key(self, title, key, read_only=False): """ :calls: `POST /repos/:owner/:repo/keys `_ :param title: string :param key: string + :param read_only: bool :rtype: :class:`github.RepositoryKey.RepositoryKey` """ assert isinstance(title, (str, unicode)), title assert isinstance(key, (str, unicode)), key + assert isinstance(read_only, bool), read_only post_parameters = { "title": title, "key": key, + "read_only": read_only, } headers, data = self._requester.requestJsonAndCheck( "POST", diff --git a/github/RepositoryKey.py b/github/RepositoryKey.py index 847b7f82..30fe7fc6 100644 --- a/github/RepositoryKey.py +++ b/github/RepositoryKey.py @@ -86,6 +86,14 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): self._completeIfNotSet(self._verified) return self._verified.value + @property + def read_only(self): + """ + :type: bool + """ + self._completeIfNotSet(self._read_only) + return self._read_only.value + def delete(self): """ :calls: `DELETE /repos/:owner/:repo/keys/:id `_ @@ -123,6 +131,7 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): self._title = github.GithubObject.NotSet self._url = github.GithubObject.NotSet self._verified = github.GithubObject.NotSet + self._read_only = github.GithubObject.NotSet def _useAttributes(self, attributes): if "id" in attributes: # pragma no branch @@ -135,3 +144,5 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject): self._url = self._makeStringAttribute(attributes["url"]) if "verified" in attributes: # pragma no branch self._verified = self._makeBoolAttribute(attributes["verified"]) + if "read_only" in attributes: # pragma no branch + self._read_only = self._makeBoolAttribute(attributes["read_only"]) diff --git a/github/tests/ReplayData/Repository.testCreateKey.txt b/github/tests/ReplayData/Repository.testCreateKey.txt index 87f8c7db..be563691 100644 --- a/github/tests/ReplayData/Repository.testCreateKey.txt +++ b/github/tests/ReplayData/Repository.testCreateKey.txt @@ -4,8 +4,8 @@ api.github.com None /repos/jacquev6/PyGithub/keys {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} -{"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE", "title": "Key added through PyGithub"} +{"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw== vincent@IDEE", "read_only": false, "title": "Key added through PyGithub"} 201 [('status', '201 Created'), ('x-ratelimit-remaining', '4955'), ('content-length', '505'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"0eb643b648f2ef29f38c2bcbce872e09"'), ('date', 'Sat, 26 May 2012 20:28:37 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/user/keys/2626761')] -{"url":"https://api.github.com/user/keys/2626761","key":"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw==","verified":true,"title":"Key added through PyGithub","id":2626761} +{"url":"https://api.github.com/user/keys/2626761","key":"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2Mm0RjTNAYFfSCtUpO54usdseroUSIYg5KX4JoseTpqyiB/hqewjYLAdUq/tNIQzrkoEJWSyZrQt0ma7/YCyMYuNGd3DU6q6ZAyBeY3E9RyCiKjO3aTL2VKQGFvBVVmGdxGVSCITRphAcsKc/PF35/fg9XP9S0anMXcEFtdfMHz41SSw+XtE+Vc+6cX9FuI5qUfLGbkv8L1v3g4uw9VXlzq4GfTA+1S7D6mcoGHopAIXFlVr+2RfDKdSURMcB22z41fljO1MW4+zUS/4FyUTpL991es5fcwKXYoiE+x06VJeJJ1Krwx+DZj45uweV6cHXt2JwJEI9fWB6WyBlDejWw==","verified":true,"read_only":false,"title":"Key added through PyGithub","id":2626761}