-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
48 lines (43 loc) · 1.49 KB
/
build.gradle.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
import java.io.IOException
import java.io.InputStream
object GithooksPath {
private const val WORKSPACE_PATH = ".githooks"
private fun configure() =
ProcessBuilder("git", "config", "--local", "core.hooksPath", WORKSPACE_PATH)
.start()
.takeIf { it.waitFor() != 0 }
?.run(Process::getErrorStream)
?.run(InputStream::readBytes)
?.run(ByteArray::decodeToString)
?.run("Githooks path configuration failed: "::plus)
?.run(System.err::println)
?: println("Configured local githooks path: $WORKSPACE_PATH")
fun check() =
ProcessBuilder("git", "config", "core.hooksPath")
.start()
.takeIf { it.waitFor() == 0 }
?.run(Process::getInputStream)
?.run(InputStream::readBytes)
?.run(ByteArray::decodeToString)
?.run(String::trim)
?.also { println("Found githooks path: $it") }
?.takeIf { it == WORKSPACE_PATH }
?.let { } // Reduce return to <Unit>
?: this.configure()
}
val isCiEnvironment = System.getenv()
.entries
.firstOrNull { (key, _) -> key.equals("ci", true) }
?.value
?.equals("true", true)
?: false
if (!isCiEnvironment) {
try {
GithooksPath.check()
} catch(exception: IOException) {
System.err.run {
println("Githooks path check failed (see stacktrace below):")
exception.printStackTrace(this)
}
}
}