| 
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 | +}  | 
0 commit comments