-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dangerfile.df.kts
104 lines (92 loc) · 3.87 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (c) 2021. D4L data4life gGmbH / All rights reserved.
*
* D4L owns all legal rights, title and interest in and to the Software Development Kit ("SDK"),
* including any intellectual property rights that subsist in the SDK.
*
* The SDK and its documentation may be accessed and used for viewing/review purposes only.
* Any usage of the SDK for other purposes, including usage for the development of
* applications/third-party applications shall require the conclusion of a license agreement
* between you and D4L.
*
* If you are interested in licensing the SDK for your own applications/third-party
* applications and/or if you’d like to contribute to the development of the SDK, please
* contact D4L by email to [email protected].
*/
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\\/(?:[A-Z]{2,8}-\\d{1,6}\\/)?(?:add|change|remove|fix|bump|security)-[a-z,0-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 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 && !isReleaseBranch && !isDependabotBranch) {
fail(
"Branch name is not following our pattern:\n" +
"\nrelease/1.2(.3)(/prepare-1.2.3)\n" +
"\nfeature/(SDK-123)/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" +
"\n[ticket_id](optional) Add|Change|Remove|Fix|Bump|Security {Feature 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")
}
if (pullRequest.body == null || (pullRequest.body as String).length < 10) {
warn("Please include a description of your PR changes")
}
// Changelog
if (!isChangelogUpdated) {
warn("Changes should be reflected in the CHANGELOG.adoc")
}
// Size
val changes = (pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0)
if (changes > 2000) {
fail("This Pull-Request is way to big, please slice it into smaller pull-requests.")
} else if (changes > 1000) {
warn("Too Big Pull-Request, keep changes smaller")
} else if (changes > 500) {
warn("Large Pull-Request, try to keep changes smaller if you can")
}
}
}