forked from danger/kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dangerfile_ci.df.kts
75 lines (63 loc) · 2.55 KB
/
Dangerfile_ci.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
// Dangerfile.df.kts
/*
* Use external dependencies using the following annotations:
*/
@file:Repository("https://repo.maven.apache.org")
@file:DependsOn("org.apache.commons:commons-text:1.6")
//Testing plugin
@file:DependsOn("danger-kotlin-sample-plugin-sample.jar")
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.datetime.Clock
import org.apache.commons.text.WordUtils
import systems.danger.kotlin.*
import systems.danger.kotlin.models.danger.DangerDSL
import systems.danger.samples.plugin.SamplePlugin
register plugin SamplePlugin
danger(args) {
val allSourceFiles = git.modifiedFiles + git.createdFiles
val changelogChanged = allSourceFiles.contains("CHANGELOG.md")
val sourceChanges = allSourceFiles.firstOrNull { it.contains("src") }
SamplePlugin.myCustomCheck()
onGitHub {
val isTrivial = pullRequest.title.contains("#trivial")
// Changelog
if (!isTrivial && !changelogChanged && sourceChanges != null) {
warn(WordUtils.capitalize("any changes to library code should be reflected in the Changelog.\n\nPlease consider adding a note there and adhere to the [Changelog Guidelines](https://github.com/Moya/contributors/blob/master/Changelog%20Guidelines.md)."))
}
// Big PR Check
if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
warn("Big PR, try to keep changes smaller if you can")
}
// Work in progress check
if (pullRequest.title.contains("WIP", false)) {
warn("PR is classed as Work in Progress")
}
}
onGit {
//No Java files check
createdFiles.filter {
it.endsWith(".java")
}.forEach {
// Using apache commons-text dependency to be sure the dependency resolution always works
warn(WordUtils.capitalize("please consider to create new files in Kotlin"), it, 1)
}
}
// Coroutines checks in parallel test
val current = Clock.System.now()
runBlocking {
async { expensiveCheck("1", 1000) }
async { expensiveCheck("2", 3000) }
async { expensiveCheck("3", 2000) }
async { expensiveCheck("4", 5000) }
}
val after = Clock.System.now()
val runningTime = after.minus(current)
message("Coroutines checks terminated - runningFor $runningTime")
}
suspend fun DangerDSL.expensiveCheck(name: String, runForMillis: Long) {
// Example expensive check
delay(runForMillis)
message("Coroutine $name terminated in $runForMillis ms")
}