1
1
<?php namespace Gitlab \Api ;
2
2
3
+ use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
4
+ use Symfony \Component \OptionsResolver \Exception \UndefinedOptionsException ;
5
+
3
6
class MergeRequests extends AbstractApi
4
7
{
5
8
const STATE_ALL = 'all ' ;
6
9
const STATE_MERGED = 'merged ' ;
7
10
const STATE_OPENED = 'opened ' ;
8
11
const STATE_CLOSED = 'closed ' ;
9
12
10
- const ORDER_BY = 'created_at ' ;
11
- const SORT = 'asc ' ;
12
-
13
- /**
14
- * @param int $project_id
15
- * @param string $state
16
- * @param int $page
17
- * @param int $per_page
18
- * @param string $order_by
19
- * @param string $sort
20
- * @param string $object
21
- * @return mixed
22
- */
23
- public function getList ($ project_id , $ state = self ::STATE_ALL , $ page = 1 , $ per_page = self ::PER_PAGE , $ order_by = self ::ORDER_BY , $ sort = self ::SORT , $ object = 'merge_requests ' )
24
- {
25
- return $ this ->get ($ this ->getProjectPath ($ project_id , $ object ), array (
26
- 'page ' => $ page ,
27
- 'per_page ' => $ per_page ,
28
- 'state ' => $ state ,
29
- 'order_by ' => $ order_by ,
30
- 'sort ' => $ sort
31
- ));
32
- }
33
-
34
13
/**
35
- * @param int $project_id
36
- * @param int $page
37
- * @param int $per_page
38
- * @param string $order_by
39
- * @param string $sort
40
- * @return mixed
41
- */
42
- public function all ($ project_id , $ page = 1 , $ per_page = self ::PER_PAGE , $ order_by = self ::ORDER_BY , $ sort = self ::SORT )
43
- {
44
- return $ this ->getList ($ project_id , self ::STATE_ALL , $ page , $ per_page , $ order_by , $ sort );
45
- }
46
-
47
- /**
48
- * @param int $project_id
49
- * @param int $page
50
- * @param int $per_page
51
- * @param string $order_by
52
- * @param string $sort
53
- * @return mixed
54
- */
55
- public function merged ($ project_id , $ page = 1 , $ per_page = self ::PER_PAGE , $ order_by = self ::ORDER_BY , $ sort = self ::SORT )
56
- {
57
- return $ this ->getList ($ project_id , self ::STATE_MERGED , $ page , $ per_page , $ order_by , $ sort );
58
- }
59
-
60
- /**
61
- * @param int $project_id
62
- * @param int $page
63
- * @param int $per_page
64
- * @param string $order_by
65
- * @param string $sort
66
- * @return mixed
67
- */
68
- public function opened ($ project_id , $ page = 1 , $ per_page = self ::PER_PAGE , $ order_by = self ::ORDER_BY , $ sort = self ::SORT )
69
- {
70
- return $ this ->getList ($ project_id , self ::STATE_OPENED , $ page , $ per_page , $ order_by , $ sort );
71
- }
72
-
73
- /**
74
- * @param int $project_id
75
- * @param int $page
76
- * @param int $per_page
77
- * @param string $order_by
78
- * @param string $sort
14
+ * @param int $project_id
15
+ * @param array $parameters {
16
+ *
17
+ * @var int[] $iids Return the request having the given iid.
18
+ * @var string $state Return all merge requests or just those that are opened, closed, or
19
+ * merged.
20
+ * @var string $order_by Return requests ordered by created_at or updated_at fields. Default
21
+ * is created_at.
22
+ * @var string $sort Return requests sorted in asc or desc order. Default is desc.
23
+ * @var string $milestone Return merge requests for a specific milestone.
24
+ * @var string $view If simple, returns the iid, URL, title, description, and basic state
25
+ * of merge request.
26
+ * @var string $labels Return merge requests matching a comma separated list of labels.
27
+ * @var \DateTimeInterface $created_after Return merge requests created after the given time (inclusive).
28
+ * @var \DateTimeInterface $created_before Return merge requests created before the given time (inclusive).
29
+ * }
30
+ *
31
+ * @throws UndefinedOptionsException If an option name is undefined.
32
+ * @throws InvalidOptionsException If an option doesn't fulfill the specified validation rules.
33
+ *
79
34
* @return mixed
80
35
*/
81
- public function closed ($ project_id , $ page = 1 , $ per_page = self ::PER_PAGE , $ order_by = self ::ORDER_BY , $ sort = self ::SORT )
82
- {
83
- return $ this ->getList ($ project_id , self ::STATE_CLOSED , $ page , $ per_page , $ order_by , $ sort );
36
+ public function all ($ project_id , array $ parameters = [])
37
+ {
38
+ $ resolver = $ this ->createOptionsResolver ();
39
+ $ datetimeNormalizer = function (\DateTimeInterface $ value ) {
40
+ return $ value ->format ('c ' );
41
+ };
42
+ $ resolver ->setDefined ('iids ' )
43
+ ->setAllowedTypes ('iids ' , 'array ' )
44
+ ->setAllowedValues ('iids ' , function (array $ value ) {
45
+ return count ($ value ) == count (array_filter ($ value , 'is_int ' ));
46
+ })
47
+ ;
48
+ $ resolver ->setDefined ('state ' )
49
+ ->setAllowedValues ('state ' , ['all ' , 'opened ' , 'merged ' , 'closed ' ])
50
+ ;
51
+ $ resolver ->setDefined ('order_by ' )
52
+ ->setAllowedValues ('order_by ' , ['created_at ' , 'updated_at ' ])
53
+ ;
54
+ $ resolver ->setDefined ('milestone ' );
55
+ $ resolver ->setDefined ('view ' )
56
+ ->setAllowedValues ('view ' , ['simple ' ])
57
+ ;
58
+ $ resolver ->setDefined ('labels ' );
59
+ $ resolver ->setDefined ('created_after ' )
60
+ ->setAllowedTypes ('created_after ' , \DateTimeInterface::class)
61
+ ->setNormalizer ('created_after ' , $ datetimeNormalizer )
62
+ ;
63
+ $ resolver ->setDefined ('created_before ' )
64
+ ->setAllowedTypes ('created_before ' , \DateTimeInterface::class)
65
+ ->setNormalizer ('created_before ' , $ datetimeNormalizer )
66
+ ;
67
+
68
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests ' ), $ resolver ->resolve ($ parameters ));
84
69
}
85
70
86
71
/**
@@ -90,7 +75,7 @@ public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $orde
90
75
*/
91
76
public function show ($ project_id , $ mr_id )
92
77
{
93
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id )));
78
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id )));
94
79
}
95
80
96
81
/**
@@ -123,7 +108,7 @@ public function create($project_id, $source, $target, $title, $assignee = null,
123
108
*/
124
109
public function update ($ project_id , $ mr_id , array $ params )
125
110
{
126
- return $ this ->put ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id )), $ params );
111
+ return $ this ->put ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id )), $ params );
127
112
}
128
113
129
114
/**
@@ -140,17 +125,18 @@ public function merge($project_id, $mr_id, $message = null)
140
125
$ params = array ('merge_commit_message ' => $ message );
141
126
}
142
127
143
- return $ this ->put ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id ).'/merge ' ), $ params );
128
+ return $ this ->put ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id ).'/merge ' ), $ params );
144
129
}
145
130
146
131
/**
147
- * @param int $project_id
148
- * @param int $mr_id
132
+ * @param int $project_id
133
+ * @param int $mr_id
134
+ *
149
135
* @return mixed
150
136
*/
151
- public function showNotes ($ project_id , $ mr_id, $ page = 1 , $ per_page = self :: PER_PAGE , $ order_by = self :: ORDER_BY , $ sort = ' desc ' )
137
+ public function showNotes ($ project_id , $ mr_id )
152
138
{
153
- return $ this ->getList ( $ project_id , null , $ page , $ per_page , $ order_by , $ sort , 'merge_requests/ ' .$ this ->encodePath ($ mr_id ).'/notes ' );
139
+ return $ this ->get ( $ this -> getProjectPath ( $ project_id , 'merge_requests/ ' .$ this ->encodePath ($ mr_id ).'/notes ' ) );
154
140
}
155
141
156
142
/**
@@ -173,7 +159,7 @@ public function addNote($project_id, $mr_id, $note)
173
159
*/
174
160
public function showComments ($ project_id , $ mr_id )
175
161
{
176
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id ).'/comments ' ));
162
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id ).'/comments ' ));
177
163
}
178
164
179
165
/**
@@ -184,7 +170,7 @@ public function showComments($project_id, $mr_id)
184
170
*/
185
171
public function addComment ($ project_id , $ mr_id , $ note )
186
172
{
187
- return $ this ->post ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id ).'/comments ' ), array (
173
+ return $ this ->post ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id ).'/comments ' ), array (
188
174
'note ' => $ note
189
175
));
190
176
}
@@ -196,17 +182,7 @@ public function addComment($project_id, $mr_id, $note)
196
182
*/
197
183
public function changes ($ project_id , $ mr_id )
198
184
{
199
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_request/ ' .$ this ->encodePath ($ mr_id ).'/changes ' ));
200
- }
201
-
202
- /**
203
- * @param $project_id
204
- * @param $mr_iid
205
- * @return mixed
206
- */
207
- public function getByIid ($ project_id , $ mr_iid )
208
- {
209
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests ' ), array ('iid ' => $ mr_iid ));
185
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests/ ' .$ this ->encodePath ($ mr_id ).'/changes ' ));
210
186
}
211
187
212
188
/**
@@ -216,7 +192,7 @@ public function getByIid($project_id, $mr_iid)
216
192
*/
217
193
public function commits ($ project_id , $ mr_id )
218
194
{
219
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id ).'/commits ' ));
195
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id ).'/commits ' ));
220
196
}
221
197
222
198
/**
@@ -226,7 +202,7 @@ public function commits($project_id, $mr_id)
226
202
*/
227
203
public function closesIssues ($ project_id , $ mr_id )
228
204
{
229
- return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_request / ' .$ this ->encodePath ($ mr_id ).'/closes_issues ' ));
205
+ return $ this ->get ($ this ->getProjectPath ($ project_id , 'merge_requests / ' .$ this ->encodePath ($ mr_id ).'/closes_issues ' ));
230
206
}
231
207
232
208
/**
0 commit comments