forked from shopware/shopware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.danger.php
87 lines (79 loc) · 3.36 KB
/
.danger.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
<?php declare(strict_types=1);
use Danger\Config;
use Danger\Context;
use Danger\Platform\Github\Github;
use Danger\Platform\Gitlab\Gitlab;
use Danger\Rule\CommitRegexRule;
use Danger\Rule\ConditionRule;
use Danger\Rule\DisallowRepeatedCommitsRule;
use Danger\Rule\MaxCommitRule;
return (new Config())
->useThreadOnFails()
->useRule(new DisallowRepeatedCommitsRule)
->useRule(function (Context $context) {
$files = $context->platform->pullRequest->getFiles();
if ($files->matches('changelog/_unreleased/*.md')->count() === 0) {
$context->warning('The Pull Request doesn\'t contain any changelog file');
}
})
->useRule(function (Context $context) {
// The title is not important here as we import the pull requests and prefix them
if ($context->platform->pullRequest->projectIdentifier === 'shopware/platform') {
return;
}
if (!preg_match('/(?m)^(WIP:\s)?NEXT-\d*\s-\s\w/', $context->platform->pullRequest->title)) {
$context->failure(sprintf('The title `%s` does not match our requirements. Example: NEXT-00000 - My Title', $context->platform->pullRequest->title));
}
})
->useRule(new ConditionRule(
function (Context $context) {
return $context->platform instanceof Gitlab;
},
[
function (Context $context) {
$labels = $context->platform->pullRequest->labels;
if (in_array('E2E:skip', $labels, true) || in_array('unit:skip', $labels, true)) {
$context->notice('You skipped some tests. Reviewers be carefully with this');
}
},
function (Context $context) {
$files = $context->platform->pullRequest->getFiles();
$hasStoreApiModified = false;
/** @var Danger\Struct\File $file */
foreach ($files->getElements() as $file) {
if (str_contains($file->name, 'SalesChannel') && str_contains($file->name, 'Route.php') && !str_contains($file->name, '/Test/')) {
$hasStoreApiModified = true;
}
}
if ($hasStoreApiModified) {
$context->warning('Store-API Route has been modified. @Reviewers please review carefully!');
$context->platform->addLabels('Security-Audit Required');
}
}
]
))
->useRule(new ConditionRule(
function (Context $context) {
return $context->platform instanceof Github;
},
[
new MaxCommitRule()
]
))
->useRule(new ConditionRule(
function (Context $context) {
return $context->platform instanceof Github && $context->platform->pullRequest->projectIdentifier === 'shopwareBoostDay/platform';
},
[
new CommitRegexRule(
'/(?m)(?mi)^NEXT-\d*\s-\s[A-Z].*,\s*fixes\s*shopwareBoostday\/platform#\d*$/m',
"The commit title `###MESSAGE###` does not match our requirements. Example: \"NEXT-00000 - My Title, fixes shopwareBoostday/platform#1234\""
)
]
))
->after(function (Context $context) {
if ($context->platform instanceof Github && $context->hasFailures()) {
$context->platform->addLabels('Incomplete');
}
})
;