All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avito.test.gradle.Git.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2024.32
Show newest version
package com.avito.test.gradle

import com.avito.utils.ProcessRunner
import java.io.File
import java.security.MessageDigest
import java.time.Duration
import java.util.Random

public fun File.git(command: String): String =
    processRunner().run(
        command = "git $command",
        timeout = Duration.ofSeconds(10)
    ).getOrThrow()

public fun File.getCommitHash(): String = git("rev-parse HEAD")

public fun File.commit(message: String = "changes") {
    git("add --all")
    git("commit --author='test <>' --all --message='${message.escape()}'")
}

private fun File.processRunner(): ProcessRunner {
    return ProcessRunner.create(
        workingDirectory = this
    )
}

public fun randomCommitHash(): String =
    MessageDigest.getInstance("SHA-1")
        .digest(random.nextLong().toString().toByteArray())
        .fold("") { str, bytes -> str + "%02x".format(bytes) }

private fun String.escape() = replace("\\s+".toRegex()) { "_" }

private val random = Random()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy