|
1
|
|
|
<?php |
|
2
|
|
|
class DNCommit extends ViewableData { |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @var Gitonomy\Git\Commit |
|
6
|
|
|
*/ |
|
7
|
|
|
protected $commit = null; |
|
8
|
|
|
|
|
9
|
|
|
protected $name = null; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
protected $references = null; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $ownerBranchName = null; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $buildname; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var DNProject |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $project; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var DNData |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $data; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $subjectMessage; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $bodyMessage; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
private static $casting = array( |
|
|
|
|
|
|
48
|
|
|
'Name' => 'Text', |
|
49
|
|
|
'SubjectMessage' => 'Text', |
|
50
|
|
|
'Message' => 'Text', |
|
51
|
|
|
'BodyMessage' => 'Text', |
|
52
|
|
|
'Fullname' => 'Text', |
|
53
|
|
|
'Filename' => 'Text', |
|
54
|
|
|
'References' => 'Text', |
|
55
|
|
|
'ownerBranchName' => 'Text' |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param Gitonomy\Git\Commit $commit |
|
60
|
|
|
* @param DNProject $project |
|
61
|
|
|
* @param DNData $data |
|
62
|
|
|
* @param string|null $ownerBranchName |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct(Gitonomy\Git\Commit $commit, DNProject $project, DNData $data, $ownerBranchName = null) { |
|
65
|
|
|
$this->commit = $commit; |
|
66
|
|
|
$this->buildname = $commit->getHash(); |
|
67
|
|
|
$this->project = $project; |
|
68
|
|
|
$this->data = $data; |
|
69
|
|
|
$this->ownerBranchName = $ownerBranchName; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Return the hash of the commit, used to name this commit. |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function Name() { |
|
77
|
|
|
if($this->name == null) { |
|
78
|
|
|
$this->name = $this->commit->getFixedShortHash(8); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return htmlentities($this->name); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Return the full SHA of the commit. |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function SHA() { |
|
89
|
|
|
return htmlentities($this->commit->getHash()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Return the first line of the commit message. |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function SubjectMessage() { |
|
97
|
|
|
if($this->subjectMessage == null) { |
|
98
|
|
|
$this->subjectMessage = $this->commit->getSubjectMessage(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return htmlentities($this->subjectMessage); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function BodyMessage() { |
|
105
|
|
|
if($this->bodyMessage == null) { |
|
106
|
|
|
$this->bodyMessage = $this->commit->getBodyMessage(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return htmlentities($this->bodyMessage); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return ArrayList |
|
114
|
|
|
*/ |
|
115
|
|
|
public function References() { |
|
116
|
|
|
if($this->references !== null) { |
|
117
|
|
|
return $this->references; |
|
118
|
|
|
} |
|
119
|
|
|
$this->references = new ArrayList(); |
|
120
|
|
|
|
|
121
|
|
|
// Add tags |
|
122
|
|
|
foreach($this->commit->resolveReferences() as $reference) { |
|
123
|
|
|
if($reference instanceof \Gitonomy\Git\Reference\Tag) { |
|
124
|
|
|
$this->references->push(new ArrayData(array( |
|
125
|
|
|
'Name' => $reference->getName(), |
|
126
|
|
|
'Type' => 'Tag', |
|
127
|
|
|
))); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $this->references; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return string |
|
136
|
|
|
*/ |
|
137
|
|
|
public function FullName() { |
|
138
|
|
|
return htmlentities($this->commit->getHash()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return string |
|
143
|
|
|
*/ |
|
144
|
|
|
public function Filename() { |
|
145
|
|
|
return htmlentities($this->commit->getHash()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return ArrayList |
|
150
|
|
|
*/ |
|
151
|
|
|
public function CurrentlyDeployedTo() { |
|
152
|
|
|
$environments = $this->project->Environments(); |
|
153
|
|
|
$envList = new ArrayList(); |
|
154
|
|
|
foreach($environments as $environment) { |
|
155
|
|
|
$deployments = DNDeployment::get() |
|
156
|
|
|
->filter('State', 'Completed') |
|
157
|
|
|
->filter('EnvironmentID', $environment->ID) |
|
158
|
|
|
->sort('LastEdited DESC'); |
|
159
|
|
|
if(!$deployments->count()) { |
|
160
|
|
|
continue; |
|
161
|
|
|
} |
|
162
|
|
|
$latest = $deployments->first(); |
|
163
|
|
|
if($latest->SHA === $this->commit->getHash()) { |
|
164
|
|
|
$envList->push($environment); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
return $envList; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param string $environmentName |
|
172
|
|
|
* @return boolean True if this release has ever been deployed to the given environment |
|
173
|
|
|
*/ |
|
174
|
|
|
public function EverDeployedTo($environmentName) { |
|
175
|
|
|
$environments = $this->project->Environments()->filter('Name', $environmentName); |
|
176
|
|
|
if(!$environments->count()) { |
|
177
|
|
|
return false; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$environment = $environments->first(); |
|
181
|
|
|
|
|
182
|
|
|
$deployments = DNDeployment::get() |
|
183
|
|
|
->filter('State', 'Completed') |
|
184
|
|
|
->filter('EnvironmentID', $environment->ID); |
|
185
|
|
|
|
|
186
|
|
|
if($deployments->count()) { |
|
187
|
|
|
return true; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
return false; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return SS_Datetime |
|
195
|
|
|
*/ |
|
196
|
|
|
public function Created() { |
|
197
|
|
|
$created = $this->commit->getCommitterDate(); |
|
198
|
|
|
|
|
199
|
|
|
$created->setTimezone(new DateTimeZone(date_default_timezone_get())); |
|
200
|
|
|
|
|
201
|
|
|
$d = SS_Datetime::create(); |
|
202
|
|
|
$d->setValue($created->format('Y-m-d H:i:s')); |
|
203
|
|
|
|
|
204
|
|
|
return $d; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
} |
|
208
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.