12
12
class PullRequest extends Api
13
13
{
14
14
/**
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/
16
17
*
17
- * @link http://develop.github.com/p/pulls.html
18
18
* @param string $username the username
19
19
* @param string $repo the repo
20
20
* @param string $state the state of the fetched pull requests.
21
21
* The API seems to automatically default to 'open'
22
22
* @return array array of pull requests for the project
23
23
*/
24
- public function listPullRequests ($ username , $ repo , $ state = '' )
24
+ public function listPullRequests ($ username , $ repo , $ state = 'open ' )
25
25
{
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 ));
29
27
}
30
28
31
29
/**
32
30
* Show all details of a pull request, including the discussions.
31
+ * @link http://developer.github.com/v3/pulls/
33
32
*
34
- * @link http://develop.github.com/p/pulls.html
35
33
* @param string $username the username
36
34
* @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
38
36
* @return array array of pull requests for the project
39
37
*/
40
- public function show ($ username , $ repo , $ pullRequestId )
38
+ public function show ($ username , $ repo , $ id )
41
39
{
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 ));
45
41
}
46
42
47
43
/**
@@ -56,40 +52,15 @@ public function show($username, $repo, $pullRequestId)
56
52
* specify the username first: "my-user:some-branch".
57
53
* @param string $title The String title of the Pull Request. Used in pair with $body.
58
54
* @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.
60
55
* @return array array of pull requests for the project
61
56
*/
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 )
63
58
{
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
+ ));
94
65
}
95
66
}
0 commit comments