[build statistics] Allow reporting milestostone and RC versions
This commit is contained in:
+11
-5
@@ -21,12 +21,18 @@ internal val salt: String by lazy {
|
||||
}
|
||||
|
||||
fun anonymizeComponentVersion(version: String): String {
|
||||
return version.replace('-', '.')
|
||||
val parts = version.toLowerCase().replace('-', '.')
|
||||
.split(".")
|
||||
.plus(listOf("0", "0")) // pad with zeros
|
||||
.take(3)
|
||||
.map { s -> s.toIntOrNull() ?: "0" }
|
||||
.joinToString(".")
|
||||
.plus(listOf("0", "0", "0")) // pad with zeros
|
||||
.take(4)
|
||||
val mainVersion = parts.take(3).map { s -> s.toIntOrNull()?.toString() ?: "0" }
|
||||
|
||||
val suffix = when {
|
||||
parts[3].matches("(rc|m)\\d{0,1}".toRegex()) -> "-${parts[3]}"
|
||||
parts[3].matches("(snapshot|dev|beta)".toRegex()) -> "-${parts[3]}"
|
||||
else -> ""
|
||||
}
|
||||
return mainVersion.joinToString(".") + suffix
|
||||
}
|
||||
|
||||
internal fun sha256(s: String): String {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
import org.jetbrains.kotlin.statistics.metrics.NumberAnonymizationPolicy.RANDOM_10_PERCENT
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringAnonymizationPolicy.COMPONENT_VERSION
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -24,4 +25,28 @@ class MetricPolicyTest {
|
||||
assertEquals(120, RANDOM_10_PERCENT.anonymize(123))
|
||||
assertEquals(200, RANDOM_10_PERCENT.anonymize(234))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun versionAnonymization() {
|
||||
assertEquals("0.0.0", COMPONENT_VERSION.anonymize("some.invalid.string"))
|
||||
assertEquals("1.0.0", COMPONENT_VERSION.anonymize("1"))
|
||||
assertEquals("1.2.0", COMPONENT_VERSION.anonymize("1.2"))
|
||||
|
||||
assertEquals("1.2.3", COMPONENT_VERSION.anonymize("1.2.3"))
|
||||
assertEquals("1.2.3", COMPONENT_VERSION.anonymize("1.2.3"))
|
||||
assertEquals("1.2.3", COMPONENT_VERSION.anonymize("1.2.3.4"))
|
||||
assertEquals("1.2.3-m", COMPONENT_VERSION.anonymize("1.2.3-M"))
|
||||
assertEquals("1.2.3-m1", COMPONENT_VERSION.anonymize("1.2.3-M1"))
|
||||
assertEquals("1.2.3-m2", COMPONENT_VERSION.anonymize("1.2.3.M2"))
|
||||
assertEquals("1.2.3-rc", COMPONENT_VERSION.anonymize("1.2.3-RC"))
|
||||
assertEquals("1.2.3-rc5", COMPONENT_VERSION.anonymize("1.2.3-RC5"))
|
||||
|
||||
assertEquals("1.2.3", COMPONENT_VERSION.anonymize("1.2.3.unknown suffix"))
|
||||
assertEquals("1.2.3", COMPONENT_VERSION.anonymize("1.2.3-unknown suffix"))
|
||||
|
||||
assertEquals("123.234.345-dev", COMPONENT_VERSION.anonymize("123.234.345-dev-12345"))
|
||||
assertEquals("1.7.255-snapshot", COMPONENT_VERSION.anonymize("1.7.255-SNAPSHOT"))
|
||||
|
||||
assertEquals("1.7.255-beta", COMPONENT_VERSION.anonymize("1.7.255-beta"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user