Skip to content

Commit eb0b9ce

Browse files
author
Matt Humphrey
committed
Added sorting fields to merge requests. #68
1 parent 5db3f1b commit eb0b9ce

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

lib/Gitlab/Api/MergeRequests.php

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,79 @@ class MergeRequests extends AbstractApi
77
const STATE_OPENED = 'opened';
88
const STATE_CLOSED = 'closed';
99

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 $state
18+
* @param string $order_by
19+
* @param string $sort
20+
* @return mixed
21+
*/
22+
public function getList($project_id, $page, $per_page, $state = self::STATE_ALL, $order_by = self::ORDER_BY, $sort = self::SORT)
23+
{
24+
return $this->get($this->getProjectPath($project_id, 'merge_requests'), array(
25+
'page' => $page,
26+
'per_page' => $per_page,
27+
'state' => $state,
28+
'order_by' => $order_by,
29+
'sort' => $sort
30+
));
31+
}
32+
1033
/**
1134
* @param int $project_id
1235
* @param int $page
1336
* @param int $per_page
37+
* @param string $order_by
38+
* @param string $sort
1439
* @return mixed
1540
*/
16-
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
41+
public function all($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
1742
{
18-
return $this->getMrList($project_id, $page, $per_page, self::STATE_ALL);
43+
return $this->getList($project_id, $page, $per_page, self::STATE_ALL, $order_by, $sort);
1944
}
2045

2146
/**
2247
* @param int $project_id
2348
* @param int $page
2449
* @param int $per_page
50+
* @param string $order_by
51+
* @param string $sort
2552
* @return mixed
2653
*/
27-
public function merged($project_id, $page = 1, $per_page = self::PER_PAGE)
54+
public function merged($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
2855
{
29-
return $this->getMrList($project_id, $page, $per_page, self::STATE_MERGED);
56+
return $this->getList($project_id, $page, $per_page, self::STATE_MERGED, $order_by, $sort);
3057
}
3158

3259
/**
3360
* @param int $project_id
3461
* @param int $page
3562
* @param int $per_page
63+
* @param string $order_by
64+
* @param string $sort
3665
* @return mixed
3766
*/
38-
public function opened($project_id, $page = 1, $per_page = self::PER_PAGE)
67+
public function opened($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
3968
{
40-
return $this->getMrList($project_id, $page, $per_page, self::STATE_OPENED);
69+
return $this->getList($project_id, $page, $per_page, self::STATE_OPENED, $order_by, $sort);
4170
}
4271

4372
/**
4473
* @param int $project_id
4574
* @param int $page
4675
* @param int $per_page
76+
* @param string $order_by
77+
* @param string $sort
4778
* @return mixed
4879
*/
49-
public function closed($project_id, $page = 1, $per_page = self::PER_PAGE)
80+
public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
5081
{
51-
return $this->getMrList($project_id, $page, $per_page, self::STATE_CLOSED);
82+
return $this->getList($project_id, $page, $per_page, self::STATE_CLOSED, $order_by, $sort);
5283
}
5384

5485
/**
@@ -141,20 +172,4 @@ public function changes($project_id, $mr_id)
141172
{
142173
return $this->get($this->getProjectPath($project_id, 'merge_request/'.urlencode($mr_id).'/changes'));
143174
}
144-
145-
/**
146-
* @param int $project_id
147-
* @param int $page
148-
* @param int $per_page
149-
* @param string $state
150-
* @return mixed
151-
*/
152-
protected function getMrList($project_id, $page, $per_page, $state = self::STATE_ALL)
153-
{
154-
return $this->get($this->getProjectPath($project_id, 'merge_requests'), array(
155-
'page' => $page,
156-
'per_page' => $per_page,
157-
'state' => $state
158-
));
159-
}
160175
}

0 commit comments

Comments
 (0)