|
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 int $page |
16 |
| - * @param int $per_page |
17 |
| - * @param string $order_by |
18 |
| - * @param string $sort |
19 |
| - * @return mixed |
20 |
| - */ |
21 |
| - public function all($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) |
22 |
| - { |
23 |
| - return $this->getList($project_id, self::STATE_ALL, $page, $per_page, $order_by, $sort); |
24 |
| - } |
25 |
| - |
26 | 13 | /**
|
27 |
| - * @param int $project_id |
28 |
| - * @param int $page |
29 |
| - * @param int $per_page |
30 |
| - * @param string $order_by |
31 |
| - * @param string $sort |
32 |
| - * @return mixed |
33 |
| - */ |
34 |
| - public function merged($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) |
35 |
| - { |
36 |
| - return $this->getList($project_id, self::STATE_MERGED, $page, $per_page, $order_by, $sort); |
37 |
| - } |
38 |
| - |
39 |
| - /** |
40 |
| - * @param int $project_id |
41 |
| - * @param int $page |
42 |
| - * @param int $per_page |
43 |
| - * @param string $order_by |
44 |
| - * @param string $sort |
45 |
| - * @return mixed |
46 |
| - */ |
47 |
| - public function opened($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) |
48 |
| - { |
49 |
| - return $this->getList($project_id, self::STATE_OPENED, $page, $per_page, $order_by, $sort); |
50 |
| - } |
51 |
| - |
52 |
| - /** |
53 |
| - * @param int $project_id |
54 |
| - * @param int $page |
55 |
| - * @param int $per_page |
56 |
| - * @param string $order_by |
57 |
| - * @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 | + * |
58 | 34 | * @return mixed
|
59 | 35 | */
|
60 |
| - public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) |
61 |
| - { |
62 |
| - 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)); |
63 | 69 | }
|
64 | 70 |
|
65 | 71 | /**
|
@@ -123,13 +129,14 @@ public function merge($project_id, $mr_id, $message = null)
|
123 | 129 | }
|
124 | 130 |
|
125 | 131 | /**
|
126 |
| - * @param int $project_id |
127 |
| - * @param int $mr_id |
| 132 | + * @param int $project_id |
| 133 | + * @param int $mr_id |
| 134 | + * |
128 | 135 | * @return mixed
|
129 | 136 | */
|
130 |
| - 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) |
131 | 138 | {
|
132 |
| - 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')); |
133 | 140 | }
|
134 | 141 |
|
135 | 142 | /**
|
@@ -178,16 +185,6 @@ public function changes($project_id, $mr_id)
|
178 | 185 | return $this->get($this->getProjectPath($project_id, 'merge_requests/'.$this->encodePath($mr_id).'/changes'));
|
179 | 186 | }
|
180 | 187 |
|
181 |
| - /** |
182 |
| - * @param $project_id |
183 |
| - * @param $mr_iid |
184 |
| - * @return mixed |
185 |
| - */ |
186 |
| - public function getByIid($project_id, $mr_iid) |
187 |
| - { |
188 |
| - return $this->get($this->getProjectPath($project_id, 'merge_requests'), array('iid' => $mr_iid)); |
189 |
| - } |
190 |
| - |
191 | 188 | /**
|
192 | 189 | * @param int $project_id
|
193 | 190 | * @param int $mr_id
|
|
0 commit comments