Skip to content

Commit 6b85560

Browse files
committed
Move PRs to new API
1 parent a694ffe commit 6b85560

File tree

1 file changed

+15
-44
lines changed

1 file changed

+15
-44
lines changed

lib/Github/Api/PullRequest.php

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,32 @@
1212
class PullRequest extends Api
1313
{
1414
/**
15-
* Get a listing of a project's pull requests by the username, repo, and optionnally state.
15+
* Get a listing of a project's pull requests by the username, repo, and optionally state.
16+
* @link http://developer.github.com/v3/pulls/
1617
*
17-
* @link http://develop.github.com/p/pulls.html
1818
* @param string $username the username
1919
* @param string $repo the repo
2020
* @param string $state the state of the fetched pull requests.
2121
* The API seems to automatically default to 'open'
2222
* @return array array of pull requests for the project
2323
*/
24-
public function listPullRequests($username, $repo, $state = '')
24+
public function listPullRequests($username, $repo, $state = 'open')
2525
{
26-
$response = $this->get('pulls/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state));
27-
28-
return $response['pulls'];
26+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls?state='.urlencode($state));
2927
}
3028

3129
/**
3230
* Show all details of a pull request, including the discussions.
31+
* @link http://developer.github.com/v3/pulls/
3332
*
34-
* @link http://develop.github.com/p/pulls.html
3533
* @param string $username the username
3634
* @param string $repo the repo
37-
* @param string $pullRequestId the ID of the pull request for which details are retrieved
35+
* @param string $id the ID of the pull request for which details are retrieved
3836
* @return array array of pull requests for the project
3937
*/
40-
public function show($username, $repo, $pullRequestId)
38+
public function show($username, $repo, $id)
4139
{
42-
$response = $this->get('pulls/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($pullRequestId));
43-
44-
return $response['pulls'];
40+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls/'.urlencode($id));
4541
}
4642

4743
/**
@@ -56,40 +52,15 @@ public function show($username, $repo, $pullRequestId)
5652
* specify the username first: "my-user:some-branch".
5753
* @param string $title The String title of the Pull Request. Used in pair with $body.
5854
* @param string $body The String body of the Pull Request. Used in pair with $title.
59-
* @param int $issueId If a pull-request is related to an issue, place issue ID here. The $title-$body pair and this are mutually exclusive.
6055
* @return array array of pull requests for the project
6156
*/
62-
public function create($username, $repo, $base, $head, $title = null, $body = null, $issueId = null)
57+
public function create($username, $repo, $base, $head, $title, $body = null)
6358
{
64-
$postParameters = array(
65-
'pull[base]' => $base,
66-
'pull[head]' => $head
67-
);
68-
69-
if ( $title !== null and $body !== null ) {
70-
$postParameters = array_merge( $postParameters,
71-
array(
72-
'pull[title]' => $title,
73-
'pull[body]' => $body
74-
)
75-
);
76-
} elseif ( $issueId !== null ) {
77-
$postParameters = array_merge( $postParameters,
78-
array(
79-
'pull[issue]' => $issueId
80-
)
81-
);
82-
} else {
83-
// @FIXME : Exception required here.
84-
return null;
85-
}
86-
87-
$response = $this->post('pulls/'.urlencode($username).'/'.urlencode($repo),
88-
$postParameters
89-
);
90-
91-
// @FIXME : Exception to be thrown when $response['error'] exists.
92-
// Content of error can be : "{"error":["A pull request already exists for <username>:<branch>."]}"
93-
return $response['pull'];
59+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', array(
60+
'head' => $head,
61+
'base' => $base,
62+
'title' => $title,
63+
'body' => $body,
64+
));
9465
}
9566
}

0 commit comments

Comments
 (0)