|
1 | | -<?php |
2 | | - |
3 | | -namespace Gitlab\Model; |
4 | | - |
5 | | -use Gitlab\Client; |
6 | | - |
7 | | -class MergeRequest extends AbstractModel |
8 | | -{ |
9 | | - protected static $_properties = array( |
10 | | - 'id', |
11 | | - 'iid', |
12 | | - 'target_branch', |
13 | | - 'source_branch', |
14 | | - 'project_id', |
15 | | - 'title', |
16 | | - 'closed', |
17 | | - 'merged', |
18 | | - 'author', |
19 | | - 'assignee', |
20 | | - 'project', |
21 | | - 'state', |
22 | | - 'source_project_id', |
23 | | - 'target_project_id', |
24 | | - 'upvotes', |
25 | | - 'downvotes' |
26 | | - ); |
27 | | - |
28 | | - public static function fromArray(Client $client, Project $project, array $data) |
29 | | - { |
30 | | - $mr = new MergeRequest($project, $data['id'], $client); |
31 | | - |
32 | | - if (isset($data['author'])) { |
33 | | - $data['author'] = User::fromArray($client, $data['author']); |
34 | | - } |
35 | | - |
36 | | - if (isset($data['assignee'])) { |
37 | | - $data['assignee'] = User::fromArray($client, $data['assignee']); |
38 | | - } |
39 | | - |
40 | | - return $mr->hydrate($data); |
41 | | - } |
42 | | - |
43 | | - public function __construct(Project $project, $id = null, Client $client = null) |
44 | | - { |
45 | | - $this->setClient($client); |
46 | | - |
47 | | - $this->project = $project; |
48 | | - $this->id = $id; |
49 | | - } |
50 | | - |
51 | | - public function show() |
52 | | - { |
53 | | - $data = $this->api('mr')->show($this->project->id, $this->id); |
54 | | - |
55 | | - return MergeRequest::fromArray($this->getClient(), $this->project, $data); |
56 | | - } |
57 | | - |
58 | | - public function update(array $params) |
59 | | - { |
60 | | - $data = $this->api('mr')->update($this->project->id, $this->id, $params); |
61 | | - |
62 | | - return MergeRequest::fromArray($this->getClient(), $this->project, $data); |
63 | | - } |
64 | | - |
65 | | - public function close($comment = null) |
66 | | - { |
67 | | - if ($comment) { |
68 | | - $this->addComment($comment); |
69 | | - } |
70 | | - |
71 | | - return $this->update(array( |
72 | | - 'state_event' => 'close' |
73 | | - )); |
74 | | - } |
75 | | - |
76 | | - public function reopen() |
77 | | - { |
78 | | - return $this->update(array( |
79 | | - 'state_event' => 'reopen' |
80 | | - )); |
81 | | - } |
82 | | - |
83 | | - public function merged() |
84 | | - { |
85 | | - return $this->update(array( |
86 | | - 'state_event' => 'merge' |
87 | | - )); |
88 | | - } |
89 | | - |
90 | | - public function addComment($note) |
91 | | - { |
92 | | - $data = $this->api('mr')->addComment($this->project->id, $this->id, $note); |
93 | | - |
94 | | - return Note::fromArray($this->getClient(), $this, $data); |
95 | | - } |
96 | | - |
97 | | - public function isClosed() |
98 | | - { |
99 | | - if (in_array($this->state, array('closed', 'merged'))) { |
100 | | - return true; |
101 | | - } |
102 | | - |
103 | | - return false; |
104 | | - } |
105 | | - |
106 | | -} |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Gitlab\Model; |
| 4 | + |
| 5 | +use Gitlab\Client; |
| 6 | + |
| 7 | +class MergeRequest extends AbstractModel |
| 8 | +{ |
| 9 | + protected static $_properties = array( |
| 10 | + 'id', |
| 11 | + 'iid', |
| 12 | + 'target_branch', |
| 13 | + 'source_branch', |
| 14 | + 'project_id', |
| 15 | + 'title', |
| 16 | + 'closed', |
| 17 | + 'merged', |
| 18 | + 'author', |
| 19 | + 'assignee', |
| 20 | + 'project', |
| 21 | + 'state', |
| 22 | + 'source_project_id', |
| 23 | + 'target_project_id', |
| 24 | + 'upvotes', |
| 25 | + 'downvotes', |
| 26 | + 'labels' |
| 27 | + ); |
| 28 | + |
| 29 | + public static function fromArray(Client $client, Project $project, array $data) |
| 30 | + { |
| 31 | + $mr = new static($project, $data['id'], $client); |
| 32 | + |
| 33 | + if (isset($data['author'])) { |
| 34 | + $data['author'] = User::fromArray($client, $data['author']); |
| 35 | + } |
| 36 | + |
| 37 | + if (isset($data['assignee'])) { |
| 38 | + $data['assignee'] = User::fromArray($client, $data['assignee']); |
| 39 | + } |
| 40 | + |
| 41 | + return $mr->hydrate($data); |
| 42 | + } |
| 43 | + |
| 44 | + public function __construct(Project $project, $id = null, Client $client = null) |
| 45 | + { |
| 46 | + $this->setClient($client); |
| 47 | + |
| 48 | + $this->project = $project; |
| 49 | + $this->id = $id; |
| 50 | + } |
| 51 | + |
| 52 | + public function show() |
| 53 | + { |
| 54 | + $data = $this->api('mr')->show($this->project->id, $this->id); |
| 55 | + |
| 56 | + return static::fromArray($this->getClient(), $this->project, $data); |
| 57 | + } |
| 58 | + |
| 59 | + public function update(array $params) |
| 60 | + { |
| 61 | + $data = $this->api('mr')->update($this->project->id, $this->id, $params); |
| 62 | + |
| 63 | + return static::fromArray($this->getClient(), $this->project, $data); |
| 64 | + } |
| 65 | + |
| 66 | + public function close($comment = null) |
| 67 | + { |
| 68 | + if ($comment) { |
| 69 | + $this->addComment($comment); |
| 70 | + } |
| 71 | + |
| 72 | + return $this->update(array( |
| 73 | + 'state_event' => 'close' |
| 74 | + )); |
| 75 | + } |
| 76 | + |
| 77 | + public function reopen() |
| 78 | + { |
| 79 | + return $this->update(array( |
| 80 | + 'state_event' => 'reopen' |
| 81 | + )); |
| 82 | + } |
| 83 | + |
| 84 | + public function merge($message = null) |
| 85 | + { |
| 86 | + $data = $this->api('mr')->merge($this->project->id, $this->id, array('merge_commit_message' => $message)); |
| 87 | + |
| 88 | + return static::fromArray($this->getClient(), $this->project, $data); |
| 89 | + } |
| 90 | + |
| 91 | + public function merged() |
| 92 | + { |
| 93 | + return $this->update(array( |
| 94 | + 'state_event' => 'merge' |
| 95 | + )); |
| 96 | + } |
| 97 | + |
| 98 | + public function addComment($note) |
| 99 | + { |
| 100 | + $data = $this->api('mr')->addComment($this->project->id, $this->id, $note); |
| 101 | + |
| 102 | + return Note::fromArray($this->getClient(), $this, $data); |
| 103 | + } |
| 104 | + |
| 105 | + public function showComments() |
| 106 | + { |
| 107 | + $notes = array(); |
| 108 | + $data = $this->api('mr')->showComments($this->project->id, $this->id); |
| 109 | + |
| 110 | + foreach ($data as $note) { |
| 111 | + $notes[] = Note::fromArray($this->getClient(), $this, $note); |
| 112 | + } |
| 113 | + |
| 114 | + return $notes; |
| 115 | + } |
| 116 | + |
| 117 | + public function isClosed() |
| 118 | + { |
| 119 | + if (in_array($this->state, array('closed', 'merged'))) { |
| 120 | + return true; |
| 121 | + } |
| 122 | + |
| 123 | + return false; |
| 124 | + } |
| 125 | + |
| 126 | +} |
0 commit comments