Repository navigation
Expand file tree
/
Copy pathMergeRequest.php
More file actions
106 lines (84 loc) · 2.42 KB
/
Copy pathMergeRequest.php
File metadata and controls
106 lines (84 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace Gitlab\Model;
use Gitlab\Client;
class MergeRequest extends AbstractModel
{
protected static $_properties = array(
'id',
'iid',
'target_branch',
'source_branch',
'project_id',
'title',
'closed',
'merged',
'author',
'assignee',
'project',
'state',
'source_project_id',
'target_project_id',
'upvotes',
'downvotes'
);
public static function fromArray(Client $client, Project $project, array $data)
{
$mr = new MergeRequest($project, $data['id'], $client);
if (isset($data['author'])) {
$data['author'] = User::fromArray($client, $data['author']);
}
if (isset($data['assignee'])) {
$data['assignee'] = User::fromArray($client, $data['assignee']);
}
return $mr->hydrate($data);
}
public function __construct(Project $project, $id = null, Client $client = null)
{
$this->setClient($client);
$this->project = $project;
$this->id = $id;
}
public function show()
{
$data = $this->api('mr')->show($this->project->id, $this->id);
return MergeRequest::fromArray($this->getClient(), $this->project, $data);
}
public function update(array $params)
{
$data = $this->api('mr')->update($this->project->id, $this->id, $params);
return MergeRequest::fromArray($this->getClient(), $this->project, $data);
}
public function close($comment = null)
{
if ($comment) {
$this->addComment($comment);
}
return $this->update(array(
'state_event' => 'close'
));
}
public function reopen()
{
return $this->update(array(
'state_event' => 'reopen'
));
}
public function merged()
{
return $this->update(array(
'state_event' => 'merge'
));
}
public function addComment($note)
{
$data = $this->api('mr')->addComment($this->project->id, $this->id, $note);
return Note::fromArray($this->getClient(), $this, $data);
}
public function isClosed()
{
if (in_array($this->state, array('closed', 'merged'))) {
return true;
}
return false;
}
}