forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild.php
More file actions
363 lines (325 loc) · 9.3 KB
/
Build.php
File metadata and controls
363 lines (325 loc) · 9.3 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
/**
* @property int $id
* @property int $siteid
* @property int $projectid
* @property int $parentid
* @property int $subprojectid
* @property string $stamp
* @property string $name
* @property string $type
* @property string $generator
* @property Carbon $starttime
* @property Carbon $endtime
* @property Carbon $submittime
* @property string $command
* @property int $configureerrors
* @property int $configurewarnings
* @property int $configureduration
* @property int $builderrors
* @property int $buildwarnings
* @property int $buildduration
* @property int $testnotrun
* @property int $testfailed
* @property int $testpassed
* @property int $testtimestatusfailed
* @property int $testduration
* @property bool $notified
* @property bool $done
* @property string $uuid
* @property string $changeid
* @property string $osname
* @property string $osplatform
* @property string $osrelease
* @property string $osversion
* @property string $compilername
* @property string $compilerversion
*
* @method static Builder<Build> betweenDates(?Carbon $starttime, ?Carbon $endtime)
*
* @mixin Builder<Build>
*/
class Build extends Model
{
public const TYPE_ERROR = 0;
public const TYPE_WARN = 1;
protected $table = 'build';
public $timestamps = false;
protected $fillable = [
'siteid',
'projectid',
'parentid',
'subprojectid',
'stamp',
'name',
'type',
'generator',
'starttime',
'endtime',
'submittime',
'command',
'configureerrors',
'configurewarnings',
'configureduration',
'builderrors',
'buildwarnings',
'buildduration',
'testnotrun',
'testfailed',
'testpassed',
'testtimestatusfailed',
'testduration',
'notified',
'done',
'uuid',
'changeid',
'osname',
'osplatform',
'osrelease',
'osversion',
'compilername',
'compilerversion',
];
protected $casts = [
'id' => 'integer',
'siteid' => 'integer',
'projectid' => 'integer',
'parentid' => 'integer',
'subprojectid' => 'integer',
'starttime' => 'datetime',
'endtime' => 'datetime',
'submittime' => 'datetime',
'configureerrors' => 'integer',
'configurewarnings' => 'integer',
'configureduration' => 'integer',
'builderrors' => 'integer',
'buildwarnings' => 'integer',
'buildduration' => 'integer',
'testnotrun' => 'integer',
'testfailed' => 'integer',
'testpassed' => 'integer',
'testduration' => 'integer',
'notified' => 'boolean',
'done' => 'boolean',
];
/**
* @return BelongsToMany<Note, $this>
*/
public function notes(): BelongsToMany
{
return $this->belongsToMany(Note::class, 'build2note', 'buildid', 'noteid')
->withPivot('time');
}
/**
* @return BelongsTo<Project, $this>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'projectid');
}
/**
* @return BelongsTo<SubProject, $this>
*/
public function subProject(): BelongsTo
{
return $this->belongsTo(SubProject::class, 'subprojectid');
}
/**
* Adds a betweenDates() query builder filter method...
*
* @param Builder<self> $query
*/
public function scopeBetweenDates(Builder $query, ?Carbon $starttime, ?Carbon $endtime): void
{
if ($starttime !== null) {
$query->where('starttime', '>', $starttime);
}
if ($endtime !== null) {
$query->where('endtime', '<=', $endtime);
}
}
/**
* @return HasMany<Test, $this>
*/
public function tests(): HasMany
{
return $this->hasMany(Test::class, 'buildid');
}
/**
* @return HasOneThrough<Configure, BuildConfigure, $this>
*/
public function configure(): HasOneThrough
{
return $this->hasOneThrough(Configure::class, BuildConfigure::class, 'buildid', 'id', 'id', 'configureid');
}
/**
* @return BelongsTo<Site, $this>
*/
public function site(): BelongsTo
{
return $this->belongsTo(Site::class, 'siteid', 'id');
}
/**
* @return HasMany<BasicBuildAlert, $this>
*/
public function basicAlerts(): HasMany
{
return $this->hasMany(BasicBuildAlert::class, 'buildid');
}
/**
* @return HasMany<BasicBuildAlert, $this>
*/
public function basicErrors(): HasMany
{
return $this->basicAlerts()
->where('type', self::TYPE_ERROR);
}
/**
* @return HasMany<BasicBuildAlert, $this>
*/
public function basicWarnings(): HasMany
{
return $this->basicAlerts()
->where('type', self::TYPE_WARN);
}
/**
* @return HasMany<RichBuildAlert, $this>
*/
public function richAlerts(): HasMany
{
return $this->hasMany(RichBuildAlert::class, 'buildid');
}
/**
* @return HasMany<Comment, $this>
*/
public function comments(): HasMany
{
return $this->hasMany(Comment::class, 'buildid');
}
/**
* @return BelongsToMany<BuildGroup, $this>
*/
public function buildGroups(): BelongsToMany
{
return $this->belongsToMany(BuildGroup::class, 'build2group', 'groupid', 'buildid');
}
/**
* @deprecated 07/27/2025 Use this relation only to edit the underlying coverage table. Use coverage() instead.
*
* @return HasMany<Coverage, $this>
*/
public function coverageResults(): HasMany
{
return $this->hasMany(Coverage::class, 'buildid');
}
/**
* @return HasMany<CoverageView, $this>
*/
public function coverage(): HasMany
{
return $this->hasMany(CoverageView::class, 'buildid');
}
/**
* @return BelongsToMany<Label, $this>
*/
public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class, 'label2build', 'buildid', 'labelid');
}
/**
* @return BelongsToMany<UploadFile, $this>
*/
public function uploadedFiles(): BelongsToMany
{
return $this->belongsToMany(UploadFile::class, 'build2uploadfile', 'buildid', 'fileid');
}
/**
* @return HasMany<BuildCommand, $this>
*/
public function commands(): HasMany
{
return $this->hasMany(BuildCommand::class, 'buildid');
}
/**
* @return HasMany<Target, $this>
*/
public function targets(): HasMany
{
return $this->hasMany(Target::class, 'buildid');
}
/**
* @return HasMany<Build, $this>
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parentid');
}
/**
* @return HasOne<self, $this>
*/
public function parent(): HasOne
{
return $this->hasOne(self::class, 'id', 'parentid');
}
/**
* @return HasOne<PendingSubmissions, $this>
*/
public function pendingSubmissions(): HasOne
{
return $this->hasOne(PendingSubmissions::class, 'buildid');
}
/**
* TODO: Perhaps rename this function in the future to make it less similar to Laravel's update()?
*
* @return BelongsToMany<BuildUpdate, $this>
*/
public function updates(): BelongsToMany
{
return $this->belongsToMany(BuildUpdate::class, 'build2update', 'buildid', 'updateid');
}
/**
* @return HasMany<DynamicAnalysis, $this>
*/
public function dynamicAnalyses(): HasMany
{
return $this->hasMany(DynamicAnalysis::class, 'buildid');
}
/**
* @return HasMany<BuildEmail, $this>
*/
public function emails(): HasMany
{
return $this->hasMany(BuildEmail::class, 'buildid');
}
public function percentCoverageForPath(string $path): ?float
{
$path = Str::ltrim($path, './');
$coverage_query = $this->coverage()
// Nested to ensure order of operations works properly with all filtering combinations.
->where(function ($query) use ($path): void {
// Paths can be prefixed a variety of different ways...
$query->where('fullpath', 'LIKE', $path . '%')
->orWhere('fullpath', 'LIKE', '/' . $path . '%')
->orWhere('fullpath', 'LIKE', './' . $path . '%');
});
// It's unfortunate that we have to make two separate queries for this.
// Laravel does not provide a safe way to sum two separate columns in the same query.
$loctested = $coverage_query->sum('loctested');
$locuntested = $coverage_query->sum('locuntested');
$total_lines = $loctested + $locuntested;
if ($total_lines === 0) {
return null;
}
return ($loctested / $total_lines) * 100;
}
}