This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MergeRequest.php
106 lines (84 loc) · 2.45 KB
/
MergeRequest.php
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
/*
* This file is part of fgrosse/gitlab-api.
*
* Copyright © Friedrich Große <friedrich.grosse@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Gitlab\Entity;
use Gitlab\Client\ArrayParsable;
class MergeRequest implements ArrayParsable
{
/** @var int */
public $id;
/** @var int */
public $iid;
/** @var string */
public $targetBranch;
/** @var string */
public $sourceBranch;
/** @var string */
public $project;
/** @var int */
public $projectId;
/** @var string */
public $title;
/** @var string */
public $state;
/** @var int */
public $upVotes;
/** @var int */
public $downVotes;
/** @var string */
public $description;
/** @var User */
public $author;
/** @var User|null */
public $assignee;
/**
* Parse a MergeRequest from an array using the format that is returned by gitlab.
* @param array $data
* @return MergeRequest
*/
public static function fromArray(array $data)
{
$mergeRequest = new self();
$mergeRequest->id = $data['id'];
$mergeRequest->iid = $data['iid'];
$mergeRequest->targetBranch = $data['target_branch'];
$mergeRequest->sourceBranch = $data['source_branch'];
$mergeRequest->projectId = $data['project_id'];
$mergeRequest->title = $data['title'];
$mergeRequest->description = $data['description'];
$mergeRequest->state = $data['state'];
$mergeRequest->upVotes = $data['upvotes'];
$mergeRequest->downVotes = $data['downvotes'];
$mergeRequest->author = User::fromArray($data['author']);
if (isset($data['assignee'])) {
$mergeRequest->assignee = User::fromArray($data['assignee']);
}
return $mergeRequest;
}
/**
* MergeRequest constructor.
* @param string $project
* @param string $title
* @param int|null $id
*/
public function __construct($project = '', $title = '', $id = null)
{
$this->project = $project;
$this->title = $title;
$this->id = $id;
}
public function __toString()
{
return sprintf('Merge request: %s (%s)', $this->title, $this->getCrossProjectReference());
}
public function getCrossProjectReference()
{
return sprintf('%s!%d', $this->project, $this->id);
}
}