Skip to content

Commit

Permalink
Add and handle the maintainer_can_modify attribute in PullRequest (#1465
Browse files Browse the repository at this point in the history
)
  • Loading branch information
FlorentClarret committed Apr 26, 2020
1 parent 5cf9950 commit e0997b4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
20 changes: 20 additions & 0 deletions github/PullRequest.py
Expand Up @@ -365,6 +365,14 @@ def user(self):
self._completeIfNotSet(self._user)
return self._user.value

@property
def maintainer_can_modify(self):
"""
:type: bool
"""
self._completeIfNotSet(self._maintainer_can_modify)
return self._maintainer_can_modify.value

def as_issue(self):
"""
:calls: `GET /repos/:owner/:repo/issues/:number <http://developer.github.com/v3/issues>`_
Expand Down Expand Up @@ -542,19 +550,24 @@ def edit(
body=github.GithubObject.NotSet,
state=github.GithubObject.NotSet,
base=github.GithubObject.NotSet,
maintainer_can_modify=github.GithubObject.NotSet,
):
"""
:calls: `PATCH /repos/:owner/:repo/pulls/:number <http://developer.github.com/v3/pulls>`_
:param title: string
:param body: string
:param state: string
:param base: string
:param maintainer_can_modify: bool
:rtype: None
"""
assert title is github.GithubObject.NotSet or isinstance(title, str), title
assert body is github.GithubObject.NotSet or isinstance(body, str), body
assert state is github.GithubObject.NotSet or isinstance(state, str), state
assert base is github.GithubObject.NotSet or isinstance(base, str), base
assert maintainer_can_modify is github.GithubObject.NotSet or isinstance(
maintainer_can_modify, bool
), maintainer_can_modify
post_parameters = dict()
if title is not github.GithubObject.NotSet:
post_parameters["title"] = title
Expand All @@ -564,6 +577,8 @@ def edit(
post_parameters["state"] = state
if base is not github.GithubObject.NotSet:
post_parameters["base"] = base
if maintainer_can_modify is not github.GithubObject.NotSet:
post_parameters["maintainer_can_modify"] = maintainer_can_modify
headers, data = self._requester.requestJsonAndCheck(
"PATCH", self.url, input=post_parameters
)
Expand Down Expand Up @@ -943,6 +958,7 @@ def _initAttributes(self):
self._id = github.GithubObject.NotSet
self._issue_url = github.GithubObject.NotSet
self._labels = github.GithubObject.NotSet
self._maintainer_can_modify = github.GithubObject.NotSet
self._merge_commit_sha = github.GithubObject.NotSet
self._mergeable = github.GithubObject.NotSet
self._mergeable_state = github.GithubObject.NotSet
Expand Down Expand Up @@ -1021,6 +1037,10 @@ def _useAttributes(self, attributes):
self._labels = self._makeListOfClassesAttribute(
github.Label.Label, attributes["labels"]
)
if "maintainer_can_modify" in attributes: # pragma no branch
self._maintainer_can_modify = self._makeBoolAttribute(
attributes["maintainer_can_modify"]
)
if "merge_commit_sha" in attributes: # pragma no branch
self._merge_commit_sha = self._makeStringAttribute(
attributes["merge_commit_sha"]
Expand Down
20 changes: 16 additions & 4 deletions tests/PullRequest.py
Expand Up @@ -48,6 +48,9 @@ def setUp(self):
self.pullIssue256Conflict = marco_repo.get_pull(3)
self.pullIssue256Uncached = marco_repo.get_pull(4)

flo_repo = self.g.get_repo("FlorentClarret/PyGithub")
self.pullMaintainerCanModify = flo_repo.get_pull(2)

def testAttributesIssue256(self):
self.assertEqual(
self.pullIssue256Closed.closed_at,
Expand Down Expand Up @@ -134,6 +137,7 @@ def testAttributes(self):
)
self.assertEqual(self.pull.user.login, "jacquev6")
self.assertEqual(self.pull.draft, None)
self.assertEqual(self.pull.maintainer_can_modify, None)

# test __repr__() based on this attributes
self.assertEqual(
Expand Down Expand Up @@ -196,10 +200,18 @@ def testEditWithoutArguments(self):
self.pull.edit()

def testEditWithAllArguments(self):
self.pull.edit("Title edited by PyGithub", "Body edited by PyGithub", "open")
self.assertEqual(self.pull.title, "Title edited by PyGithub")
self.assertEqual(self.pull.body, "Body edited by PyGithub")
self.assertEqual(self.pull.state, "open")
self.pullMaintainerCanModify.edit(
"Title edited by PyGithub",
"Body edited by PyGithub",
"open",
"master",
True,
)
self.assertEqual(self.pullMaintainerCanModify.title, "Title edited by PyGithub")
self.assertEqual(self.pullMaintainerCanModify.body, "Body edited by PyGithub")
self.assertEqual(self.pullMaintainerCanModify.state, "open")
self.assertEqual(self.pullMaintainerCanModify.base.ref, "master")
self.assertTrue(self.pullMaintainerCanModify.maintainer_can_modify)

def testGetCommits(self):
self.assertListKeyEqual(
Expand Down

0 comments on commit e0997b4

Please sign in to comment.