Skip to content

Commit 005189c

Browse files
ktoth2acrobat
authored andcommitted
Add support for draft PRs (#820)
* Add support for draft PRs #807 * Use acceptHeadervalue from the AcceptHeaderTrait * Fix test for PullRequest * Use strict equivalence in PullRequest * Remove unused headers var in PullRequest
1 parent 8894c1b commit 005189c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

doc/pull_requests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The ``$pullRequest`` array contains the same elements as every entry in the resu
5454

5555
A pull request can either be created by supplying both the Title & Body, OR an Issue ID.
5656
Details regarding the content of parameters 3 and 4 of the ``create``.
57+
You can create a draft pull request by adding a parameter with key `draft` and value `true`.
5758

5859
#### Populated with Title and Body
5960

lib/Github/Api/PullRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ public function create($username, $repository, array $params)
156156
throw new MissingArgumentException(['issue', 'body']);
157157
}
158158

159+
if (isset($params['draft']) && $params['draft'] === true) {
160+
//This feature is in preview mode, so set the correct accept-header
161+
$this->acceptHeaderValue = 'application/vnd.github.shadow-cat-preview+json';
162+
}
163+
159164
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls', $params);
160165
}
161166

test/Github/Tests/Api/PullRequestTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,27 @@ public function shouldCreatePullRequestUsingIssueId()
260260
$api->create('ezsystems', 'ezpublish', $data);
261261
}
262262

263+
/**
264+
* @test
265+
*/
266+
public function shouldCreateDraftPullRequest()
267+
{
268+
$data = [
269+
'base' => 'master',
270+
'head' => 'virtualtestbranch',
271+
'title' => 'TITLE: Testing draft pull-request creation from PHP Github API',
272+
'body' => 'BODY: Testing draft pull-request creation from PHP Github API',
273+
'draft' => 'true',
274+
];
275+
276+
$api = $this->getApiMock();
277+
$api->expects($this->once())
278+
->method('post')
279+
->with('/repos/ezsystems/ezpublish/pulls', $data);
280+
281+
$api->create('ezsystems', 'ezpublish', $data);
282+
}
283+
263284
/**
264285
* @test
265286
*/

0 commit comments

Comments
 (0)