diff --git a/github/Consts.py b/github/Consts.py index 3532cc9f..1a8abb13 100644 --- a/github/Consts.py +++ b/github/Consts.py @@ -117,3 +117,6 @@ updateBranchPreview = "application/vnd.github.lydian-preview+json" # https://developer.github.com/changes/2016-05-23-timeline-preview-api/ issueTimelineEventsPreview = "application/vnd.github.mockingbird-preview" + +# https://developer.github.com/changes/2019-02-14-draft-pull-requests/ +draftPullRequestPreview = "application/vnd.github.shadow-cat-preview+json" diff --git a/github/Repository.py b/github/Repository.py index 082324b1..a87dc7a1 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -1301,6 +1301,7 @@ class Repository(github.GithubObject.CompletableGithubObject): :param issue: :class:`github.Issue.Issue` :param base: string :param head: string + :param draft: bool :param maintainer_can_modify: bool :rtype: :class:`github.PullRequest.PullRequest` """ @@ -1310,7 +1311,13 @@ class Repository(github.GithubObject.CompletableGithubObject): return self.__create_pull_2(*args, **kwds) def __create_pull_1( - self, title, body, base, head, maintainer_can_modify=github.GithubObject.NotSet + self, + title, + body, + base, + head, + maintainer_can_modify=github.GithubObject.NotSet, + draft=False, ): assert isinstance(title, str), title assert isinstance(body, str), body @@ -1319,6 +1326,7 @@ class Repository(github.GithubObject.CompletableGithubObject): assert maintainer_can_modify is github.GithubObject.NotSet or isinstance( maintainer_can_modify, bool ), maintainer_can_modify + assert isinstance(draft, bool), draft if maintainer_can_modify is not github.GithubObject.NotSet: return self.__create_pull( title=title, @@ -1326,9 +1334,12 @@ class Repository(github.GithubObject.CompletableGithubObject): base=base, head=head, maintainer_can_modify=maintainer_can_modify, + draft=draft, ) else: - return self.__create_pull(title=title, body=body, base=base, head=head) + return self.__create_pull( + title=title, body=body, base=base, head=head, draft=draft + ) def __create_pull_2(self, issue, base, head): assert isinstance(issue, github.Issue.Issue), issue @@ -1338,8 +1349,10 @@ class Repository(github.GithubObject.CompletableGithubObject): def __create_pull(self, **kwds): post_parameters = kwds + import_header = {"Accept": Consts.draftPullRequestPreview} + headers, data = self._requester.requestJsonAndCheck( - "POST", self.url + "/pulls", input=post_parameters + "POST", self.url + "/pulls", input=post_parameters, headers=import_header ) return github.PullRequest.PullRequest( self._requester, headers, data, completed=True diff --git a/tests/ReplayData/Repository.testCreatePull.txt b/tests/ReplayData/Repository.testCreatePull.txt index e3662faa..a07b5214 100644 --- a/tests/ReplayData/Repository.testCreatePull.txt +++ b/tests/ReplayData/Repository.testCreatePull.txt @@ -3,8 +3,8 @@ POST api.github.com None /repos/jacquev6/PyGithub/pulls -{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} -{"body": "Body of the pull request", "head": "BeaverSoftware:master", "base": "topic/RewriteWithGeneratedCode", "maintainer_can_modify": true, "title": "Pull request created by PyGithub"} +{'Accept': 'application/vnd.github.shadow-cat-preview+json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'} +{"body": "Body of the pull request", "head": "BeaverSoftware:master", "base": "topic/RewriteWithGeneratedCode", "maintainer_can_modify": true, "draft": false, "title": "Pull request created by PyGithub"} 201 [('status', '201 Created'), ('x-ratelimit-remaining', '4963'), ('content-length', '4486'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"1e069be7c3e3eb8b12afb1e1f5343dc9"'), ('date', 'Sun, 27 May 2012 09:25:37 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/pulls/31')] {"merged":false,"patch_url":"https://github.com/jacquev6/PyGithub/pull/31.patch","mergeable":null,"head":{"ref":"master","label":"BeaverSoftware:master","repo":{"clone_url":"https://github.com/BeaverSoftware/PyGithub.git","has_downloads":true,"watchers":1,"updated_at":"2012-05-27T09:09:17Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/PyGithub","mirror_url":null,"has_wiki":false,"has_issues":false,"fork":true,"forks":0,"size":176,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/PyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:BeaverSoftware/PyGithub.git","pushed_at":"2012-05-27T09:09:17Z","created_at":"2012-05-27T08:50:04Z","id":4460787,"git_url":"git://github.com/BeaverSoftware/PyGithub.git","html_url":"https://github.com/BeaverSoftware/PyGithub","full_name":"BeaverSoftware/PyGithub"},"user":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"sha":"8a4f306d4b223682dd19410d4a9150636ebe4206"},"updated_at":"2012-05-27T09:25:36Z","issue_url":"https://github.com/jacquev6/PyGithub/issues/31","body":"Body of the pull request","url":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31","comments":0,"base":{"ref":"topic/RewriteWithGeneratedCode","label":"jacquev6:topic/RewriteWithGeneratedCode","repo":{"clone_url":"https://github.com/jacquev6/PyGithub.git","has_downloads":true,"watchers":15,"updated_at":"2012-05-27T08:50:04Z","homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/jacquev6/PyGithub","mirror_url":null,"has_wiki":false,"has_issues":true,"fork":false,"forks":3,"size":308,"private":false,"open_issues":16,"svn_url":"https://github.com/jacquev6/PyGithub","owner":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"name":"PyGithub","language":"Python","description":"Python library implementing the full Github API v3","ssh_url":"git@github.com:jacquev6/PyGithub.git","pushed_at":"2012-05-27T07:29:24Z","created_at":"2012-02-25T12:53:47Z","id":3544490,"git_url":"git://github.com/jacquev6/PyGithub.git","html_url":"https://github.com/jacquev6/PyGithub","full_name":"jacquev6/PyGithub"},"user":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"sha":"ed866fc43833802ab553e5ff8581c81bb00dd433"},"number":31,"merged_by":null,"closed_at":null,"title":"Pull request created by PyGithub","deletions":384,"merged_at":null,"diff_url":"https://github.com/jacquev6/PyGithub/pull/31.diff","additions":511,"_links":{"self":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31"},"comments":{"href":"https://api.github.com/repos/jacquev6/PyGithub/issues/31/comments"},"issue":{"href":"https://api.github.com/repos/jacquev6/PyGithub/issues/31"},"html":{"href":"https://github.com/jacquev6/PyGithub/pull/31"},"review_comments":{"href":"https://api.github.com/repos/jacquev6/PyGithub/pulls/31/comments"}},"created_at":"2012-05-27T09:25:36Z","user":{"url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"state":"open","id":1436215,"review_comments":0,"commits":3,"changed_files":45,"html_url":"https://github.com/jacquev6/PyGithub/pull/31"} diff --git a/tests/ReplayData/Repository.testCreatePullFromIssue.txt b/tests/ReplayData/Repository.testCreatePullFromIssue.txt index de7d6bae..a5a3d705 100644 --- a/tests/ReplayData/Repository.testCreatePullFromIssue.txt +++ b/tests/ReplayData/Repository.testCreatePullFromIssue.txt @@ -14,7 +14,7 @@ POST api.github.com None /repos/jacquev6/PyGithub/pulls -{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +{'Accept': 'application/vnd.github.shadow-cat-preview+json', 'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} {"head": "BeaverSoftware:master", "base": "topic/RewriteWithGeneratedCode", "issue": 32} 201 [('status', '201 Created'), ('x-ratelimit-remaining', '4933'), ('content-length', '4501'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"2b035f5260fe63dd611156fea3049af0"'), ('date', 'Sun, 27 May 2012 10:58:42 GMT'), ('content-type', 'application/json; charset=utf-8'), ('location', 'https://api.github.com/repos/jacquev6/PyGithub/pulls/32')]