mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 11:51:10 +00:00
Update the RepositoryKey class (#530)
# The problems I attempt to solve - `RepositoryKey.created_at` is available on the Github API, but not in PyGithub - `RepositoryKey.edit()` is not supported anymore by the Github API, see https://developer.github.com/v3/repos/keys/#edit-a-deploy-key # How I went about solving the problem I added myself a new deploy key to one of my repositories, and recorded the existing tests using my account. I could not keep the existing test data as the specified key does not exist anymore, I added a comment for the next contributor to help him figure out how to record new tests.
This commit is contained in:
committed by
Wan Liuyang
parent
d85082858e
commit
5e8c683261
+11
-21
@@ -52,6 +52,14 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject):
|
||||
def __customUrl(self):
|
||||
return self.__repoUrl + "/keys/" + str(self.id)
|
||||
|
||||
@property
|
||||
def created_at(self):
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._created_at)
|
||||
return self._created_at.value
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
@@ -110,28 +118,8 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject):
|
||||
self.__customUrl
|
||||
)
|
||||
|
||||
def edit(self, title=github.GithubObject.NotSet, key=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `PATCH /repos/:owner/:repo/keys/:id <http://developer.github.com/v3/repos/keys>`_
|
||||
:param title: string
|
||||
:param key: string
|
||||
:rtype: None
|
||||
"""
|
||||
assert title is github.GithubObject.NotSet or isinstance(title, (str, unicode)), title
|
||||
assert key is github.GithubObject.NotSet or isinstance(key, (str, unicode)), key
|
||||
post_parameters = dict()
|
||||
if title is not github.GithubObject.NotSet:
|
||||
post_parameters["title"] = title
|
||||
if key is not github.GithubObject.NotSet:
|
||||
post_parameters["key"] = key
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"PATCH",
|
||||
self.__customUrl,
|
||||
input=post_parameters
|
||||
)
|
||||
self._useAttributes(data)
|
||||
|
||||
def _initAttributes(self):
|
||||
self._created_at = github.GithubObject.NotSet
|
||||
self._id = github.GithubObject.NotSet
|
||||
self._key = github.GithubObject.NotSet
|
||||
self._title = github.GithubObject.NotSet
|
||||
@@ -140,6 +128,8 @@ class RepositoryKey(github.GithubObject.CompletableGithubObject):
|
||||
self._read_only = github.GithubObject.NotSet
|
||||
|
||||
def _useAttributes(self, attributes):
|
||||
if "created_at" in attributes: # pragma no branch
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "id" in attributes: # pragma no branch
|
||||
self._id = self._makeIntAttribute(attributes["id"])
|
||||
if "key" in attributes: # pragma no branch
|
||||
|
||||
Reference in New Issue
Block a user