Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: add lock/unlock #1107

Merged
merged 4 commits into from May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions github/Issue.py
Expand Up @@ -247,6 +247,22 @@ def user(self):
self._completeIfNotSet(self._user)
return self._user.value

@property
def locked(self):
"""
:type: bool
"""
self._completeIfNotSet(self._locked)
return self._locked.value

@property
def active_lock_reason(self):
"""
:type: string
"""
self._completeIfNotSet(self._active_lock_reason)
return self._active_lock_reason.value

def as_pull_request(self):
"""
:calls: `GET /repos/:owner/:repo/pulls/:number <http://developer.github.com/v3/pulls>`_
Expand Down Expand Up @@ -358,6 +374,32 @@ def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet
)
self._useAttributes(data)

def lock(self, lock_reason):
"""
:calls: `PUT /repos/:owner/:repo/issues/:issue_number/lock <https://developer.github.com/v3/issues>`_
:param lock_reason: string
:rtype: None
"""
assert isinstance(lock_reason, (str, unicode)), lock_reason
put_parameters = dict()
put_parameters["lock_reason"] = lock_reason
headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/lock",
input=put_parameters,
headers={'Accept': Consts.mediaTypeLockReasonPreview}
)

def unlock(self):
"""
:calls: `DELETE /repos/:owner/:repo/issues/:issue_number/lock <https://developer.github.com/v3/issues>`_
:rtype: None
"""
headers, data = self._requester.requestJsonAndCheck(
"DELETE",
self.url + "/lock"
)

def get_comment(self, id):
"""
:calls: `GET /repos/:owner/:repo/issues/comments/:id <http://developer.github.com/v3/issues/comments>`_
Expand Down Expand Up @@ -521,6 +563,8 @@ def _initAttributes(self):
self._user = github.GithubObject.NotSet

def _useAttributes(self, attributes):
if "active_lock_reason" in attributes: # pragma no branch
self._active_lock_reason = self._makeStringAttribute(attributes["active_lock_reason"])
if "assignee" in attributes: # pragma no branch
self._assignee = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["assignee"])
if "assignees" in attributes: # pragma no branch
Expand Down Expand Up @@ -552,6 +596,8 @@ def _useAttributes(self, attributes):
self._labels = self._makeListOfClassesAttribute(github.Label.Label, attributes["labels"])
if "labels_url" in attributes: # pragma no branch
self._labels_url = self._makeStringAttribute(attributes["labels_url"])
if "locked" in attributes: # pragma no branch
self._locked = self._makeBoolAttribute(attributes["locked"])
if "milestone" in attributes: # pragma no branch
self._milestone = self._makeClassAttribute(github.Milestone.Milestone, attributes["milestone"])
if "number" in attributes: # pragma no branch
Expand Down
2 changes: 1 addition & 1 deletion tests/Framework.py
Expand Up @@ -128,7 +128,7 @@ def getresponse(self):
if atLeastPython3: # In Py3, return from "read" is bytes
self.__writeLine(output)
else:
self.__writeLine(str(output))
self.__writeLine(output.encode("utf-8"))

return FakeHttpResponse(status, headers, output)

Expand Down
6 changes: 6 additions & 0 deletions tests/Issue.py
Expand Up @@ -93,6 +93,12 @@ def testEditResetAssignee(self):
self.issue.edit(assignee=None)
self.assertEqual(self.issue.assignee, None)

def testLock(self):
self.issue.lock("resolved")

def testUnlock(self):
self.issue.unlock()

def testCreateComment(self):
comment = self.issue.create_comment("Comment created by PyGithub")
self.assertEqual(comment.id, 5808311)
Expand Down
11 changes: 11 additions & 0 deletions tests/ReplayData/Issue.testLock.txt
@@ -0,0 +1,11 @@
https
PUT
api.github.com
None
/repos/jacquev6/PyGithub/issues/28/lock
{'Content-Type': 'application/json', 'Accept': 'application/vnd.github.sailor-v-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"lock_reason": "resolved"}
204
[('Server', 'GitHub.com'), ('Date', 'Fri, 03 May 2019 09:42:52 GMT'), ('Content-Type', 'application/octet-stream'), ('Status', '204 No Content'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4993'), ('X-RateLimit-Reset', '1556880113'), ('X-OAuth-Scopes', 'admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion'), ('X-Accepted-OAuth-Scopes', 'public_repo, repo'), ('X-GitHub-Media-Type', 'github.sailor-v-preview; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, 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-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'C339:2746:A14FFE:15EFA60:5CCC0D1C')]


11 changes: 11 additions & 0 deletions tests/ReplayData/Issue.testUnlock.txt
@@ -0,0 +1,11 @@
https
DELETE
api.github.com
None
/repos/jacquev6/PyGithub/issues/28/lock
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
204
[('Server', 'GitHub.com'), ('Date', 'Fri, 03 May 2019 09:44:22 GMT'), ('Content-Type', 'application/octet-stream'), ('Status', '204 No Content'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4990'), ('X-RateLimit-Reset', '1556880113'), ('X-OAuth-Scopes', 'admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, write:discussion'), ('X-Accepted-OAuth-Scopes', 'public_repo, repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, 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-Media-Type'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', 'C373:6113:E26177:1C113F4:5CCC0D75')]