Skip to content

Commit ad9a681

Browse files
committed
Merge pull request GitLabPHP#36 from arturf/master
Update for merge request api
2 parents 2210a0c + 83a6933 commit ad9a681

File tree

3 files changed

+88
-60
lines changed

3 files changed

+88
-60
lines changed

lib/Gitlab/Api/MergeRequests.php

Lines changed: 83 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,83 @@
1-
<?php
2-
3-
namespace Gitlab\Api;
4-
5-
class MergeRequests extends AbstractApi
6-
{
7-
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
8-
{
9-
return $this->get('projects/'.urlencode($project_id).'/merge_requests', array(
10-
'page' => $page,
11-
'per_page' => $per_page
12-
));
13-
}
14-
15-
public function show($project_id, $mr_id)
16-
{
17-
return $this->get('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id));
18-
}
19-
20-
public function create($project_id, $source, $target, $title, $assignee = null, $target_project_id = null, $description = null)
21-
{
22-
if ($target_project_id && ! is_numeric($target_project_id)) {
23-
throw new \InvalidArgumentException('target_project_id should be numeric, the project name is not allowed');
24-
}
25-
26-
return $this->post('projects/'.urlencode($project_id).'/merge_requests', array(
27-
'source_branch' => $source,
28-
'target_branch' => $target,
29-
'title' => $title,
30-
'assignee_id' => $assignee,
31-
'target_project_id' => $target_project_id,
32-
'description' => $description
33-
));
34-
}
35-
36-
public function update($project_id, $mr_id, array $params)
37-
{
38-
return $this->put('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id), $params);
39-
}
40-
41-
public function merge($project_id, $mr_id, array $params)
42-
{
43-
return $this->put('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/merge', $params);
44-
}
45-
46-
public function showComments($project_id, $mr_id)
47-
{
48-
return $this->get('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/comments');
49-
}
50-
51-
public function addComment($project_id, $mr_id, $note)
52-
{
53-
return $this->post('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/comments', array(
54-
'note' => $note
55-
));
56-
}
57-
}
1+
<?php
2+
3+
namespace Gitlab\Api;
4+
5+
class MergeRequests extends AbstractApi
6+
{
7+
const STATE_ALL = 'all';
8+
const STATE_MERGED = 'merged';
9+
const STATE_OPENED = 'opened';
10+
const STATE_CLOSED = 'closed';
11+
12+
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
13+
{
14+
return $this->getMrList($project_id, $page, $per_page, self::STATE_ALL);
15+
}
16+
17+
public function merged($project_id, $page = 1, $per_page = self::PER_PAGE)
18+
{
19+
return $this->getMrList($project_id, $page, $per_page, self::STATE_MERGED);
20+
}
21+
22+
public function opened($project_id, $page = 1, $per_page = self::PER_PAGE)
23+
{
24+
return $this->getMrList($project_id, $page, $per_page, self::STATE_OPENED);
25+
}
26+
27+
public function closed($project_id, $page = 1, $per_page = self::PER_PAGE)
28+
{
29+
return $this->getMrList($project_id, $page, $per_page, self::STATE_CLOSED);
30+
}
31+
32+
public function show($project_id, $mr_id)
33+
{
34+
return $this->get('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id));
35+
}
36+
37+
public function create($project_id, $source, $target, $title, $assignee = null, $target_project_id = null, $description = null)
38+
{
39+
if ($target_project_id && ! is_numeric($target_project_id)) {
40+
throw new \InvalidArgumentException('target_project_id should be numeric, the project name is not allowed');
41+
}
42+
43+
return $this->post('projects/'.urlencode($project_id).'/merge_requests', array(
44+
'source_branch' => $source,
45+
'target_branch' => $target,
46+
'title' => $title,
47+
'assignee_id' => $assignee,
48+
'target_project_id' => $target_project_id,
49+
'description' => $description
50+
));
51+
}
52+
53+
public function update($project_id, $mr_id, array $params)
54+
{
55+
return $this->put('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id), $params);
56+
}
57+
58+
public function merge($project_id, $mr_id, array $params)
59+
{
60+
return $this->put('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/merge', $params);
61+
}
62+
63+
public function showComments($project_id, $mr_id)
64+
{
65+
return $this->get('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/comments');
66+
}
67+
68+
public function addComment($project_id, $mr_id, $note)
69+
{
70+
return $this->post('projects/'.urlencode($project_id).'/merge_request/'.urlencode($mr_id).'/comments', array(
71+
'note' => $note
72+
));
73+
}
74+
75+
protected function getMrList($project_id, $page, $per_page, $state = self::STATE_ALL)
76+
{
77+
return $this->get('projects/'.urlencode($project_id).'/merge_requests', array(
78+
'page' => $page,
79+
'per_page' => $per_page,
80+
'state' => $state
81+
));
82+
}
83+
}

lib/Gitlab/Model/MergeRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MergeRequest extends AbstractModel
2222
'source_project_id',
2323
'target_project_id',
2424
'upvotes',
25-
'downvotes'
25+
'downvotes',
26+
'labels'
2627
);
2728

2829
public static function fromArray(Client $client, Project $project, array $data)

lib/Gitlab/Model/Project.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Gitlab\Model;
44

5+
use Gitlab\Api\MergeRequests;
56
use Gitlab\Client;
67
use Gitlab\Api\AbstractApi as Api;
78

@@ -311,9 +312,9 @@ public function events()
311312
return $events;
312313
}
313314

314-
public function mergeRequests($page = 1, $per_page = Api::PER_PAGE)
315+
public function mergeRequests($page = 1, $per_page = Api::PER_PAGE, $state = MergeRequests::STATE_ALL)
315316
{
316-
$data = $this->api('mr')->all($this->id, $page, $per_page);
317+
$data = $this->api('mr')->$state($this->id, $page, $per_page);
317318

318319
$mrs = array();
319320
foreach ($data as $mr) {

0 commit comments

Comments
 (0)