-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile.df.kts
86 lines (76 loc) · 3.2 KB
/
Dangerfile.df.kts
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
import systems.danger.kotlin.danger
import systems.danger.kotlin.fail
import systems.danger.kotlin.onGitHub
import systems.danger.kotlin.warn
danger(args) {
val allSourceFiles = git.modifiedFiles + git.createdFiles
val isChangelogUpdated = allSourceFiles.contains("CHANGELOG.adoc")
onGitHub {
val branchName = pullRequest.head.label.substringAfter(":")
val isFeatureBranch = "(?:feature\\/(?:add|change|remove|fix|bump|security)-[a-z0-9-.]*)"
.toRegex()
.matches(branchName)
val isReleaseBranch = "(?:release\\/(?:\\d{1,3}\\.\\d{1,3}(?:\\.\\d{1,3})?)(?:\\/prepare-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})?)"
.toRegex()
.matches(branchName)
val isDependabotBranch = "dependabot/(.*)"
.toRegex()
.matches(branchName)
val isBugfixBranch = "bugfix/(.*)"
.toRegex()
.matches(branchName)
val isFeatureTitle = "(?:(?:\\[[A-Z]{2,8}-\\d{1,6}\\]\\s)?(?:Add|Change|Remove|Fix|Bump|Security)\\s.*)"
.toRegex()
.matches(pullRequest.title)
val isReleaseTitle = "(?:(?:Prepare )?Release \\d{1,3}\\.\\d{1,3}\\.\\d{1,3})"
.toRegex()
.matches(pullRequest.title)
if (!isFeatureBranch && !isBugfixBranch && !isReleaseBranch && !isDependabotBranch) {
fail(
"Branch name is not following our pattern:\n" +
"\nrelease/1.2(.3)(/prepare-1.2.3)\n" +
"\nfeature/add|change|remove|fix|bump|security-feature-title\n" +
"\n\n" +
"\n Current name: $branchName"
)
}
if (isFeatureBranch) {
if (!isFeatureTitle) {
fail(
"Title is not following our pattern:\n" +
"\nAdd|Change|Remove|Fix|Bump|Security {Core or Plugin title}"
)
}
}
if (isReleaseBranch) {
if (!isReleaseTitle) {
fail(
"Title is not following our pattern: Prepare Release major.minor.patch (1.2.0)"
)
}
}
// General
if (pullRequest.assignee == null) {
warn("Please assign someone to merge this PR")
}
if (pullRequest.milestone == null) {
warn("Set a milestone please")
}
when {
pullRequest.body == null -> warn("Please include a description of your PR changes")
else -> {/* do nothing*/}
}
// Changelog
if (isChangelogUpdated) {
warn("Changes should be reflected in the CHANGELOG.adoc")
}
// Size
val changes = (pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0)
when {
changes > 2000 -> fail("This Pull-Request is way to big, please slice it into smaller pull-requests.")
changes > 1000 -> warn("Too Big Pull-Request, keep changes smaller")
changes > 500 -> warn("Large Pull-Request, try to keep changes smaller if you can")
else -> {/* do nothing */}
}
}
}