
ru.tinkoff.plugins.buildmetrics.git.metrics.GitDiffMetric.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-metrics-git Show documentation
Show all versions of build-metrics-git Show documentation
Extension for tinkoff build metrics gradle plugin.
package ru.tinkoff.plugins.buildmetrics.git.metrics
import ru.tinkoff.plugins.buildmetrics.api.metrics.Metric
import java.util.regex.Pattern
private const val DEFAULT_ERROR_ANSWER = "undefined"
private val DIFF_ADDED_REGEX by lazy { Pattern.compile("(\\d+)\\sinsertions\\(\\+\\)") }
private val DIFF_DELETED_REGEX by lazy { Pattern.compile("(\\d+)\\sdeletions\\(-\\)") }
internal fun gitDiffMetrics(gitDiffCmdString: String): List> {
return listOf(
gitDiffMetric("git_lines_added", gitDiffCmdString, DIFF_ADDED_REGEX),
gitDiffMetric("git_lines_deleted", gitDiffCmdString, DIFF_DELETED_REGEX)
)
}
private fun gitDiffMetric(metricName: String, gitDiffCmdString: String, regexPattern: Pattern): Metric {
return Metric(
name = metricName,
value = findSubstring(gitDiffCmdString, regexPattern) ?: DEFAULT_ERROR_ANSWER
)
}
private fun findSubstring(input: String, regexPattern: Pattern): String? {
val matcher = regexPattern.matcher(input)
return if (matcher.find()) matcher.group(1) else null
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy