From c4293a8e5821069c857d50be5b6ca9948dd27fa1 Mon Sep 17 00:00:00 2001 From: Elena Lepilkina Date: Mon, 14 Sep 2020 11:47:04 +0300 Subject: [PATCH] Replace request to get branch name from TC in order to get right info in builds with several projects --- .../src/main/kotlin/routes/route.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/performance-server/src/main/kotlin/routes/route.kt b/tools/performance-server/src/main/kotlin/routes/route.kt index 5a2317c4a36..da4e4db3c59 100644 --- a/tools/performance-server/src/main/kotlin/routes/route.kt +++ b/tools/performance-server/src/main/kotlin/routes/route.kt @@ -125,12 +125,32 @@ data class BuildRegister(val buildId: String, val teamCityUser: String, val team fun sendTeamCityRequest(url: String, json: Boolean = false) = UrlNetworkConnector(teamCityUrl).sendRequest(RequestMethod.GET, url, teamCityUser, teamCityPassword, json) + fun getBranchName(project: String): Promise { + val url = "builds?locator=id:$buildId&fields=build(revisions(revision(vcsBranchName,vcs-root-instance)))" + var branch: String? = null + return sendTeamCityRequest(url, true).then { response -> + val data = JsonTreeParser.parse(response).jsonObject + data.getArray("build").forEach { + (it as JsonObject).getObject("revisions").getArray("revision").forEach { + val currentBranch = (it as JsonObject).getPrimitive("vcsBranchName").content.removePrefix("refs/heads/") + val currentProject = (it as JsonObject).getObject("vcs-root-instance").getPrimitive("name").content + if (project == currentProject) { + branch = currentBranch + } + return@forEach + } + } + branch ?: error("No project $project can be found in build $buildId") + } + } + + private fun format(timeValue: Int): String = if (timeValue < 10) "0$timeValue" else "$timeValue" fun getBuildInformation(): Promise { return Promise.all(arrayOf(sendTeamCityRequest("$teamCityBuildUrl/number"), - sendTeamCityRequest("$teamCityBuildUrl/branchName"), + getBranchName("Kotlin Native"), sendTeamCityRequest("$teamCityBuildUrl/startDate"))).then { results -> val (buildNumber, branch, startTime) = results val currentTime = Date()