1
+ package com.intellij.ide.starter.report
2
+
3
+ import com.intellij.ide.starter.ci.CIServer
4
+ import com.intellij.ide.starter.ci.teamcity.asTeamCity
5
+ import com.intellij.ide.starter.report.FailureDetailsOnCI.Companion.getTestMethodName
6
+ import com.intellij.ide.starter.runner.IDERunContext
7
+ import com.intellij.ide.starter.utils.replaceSpecialCharactersWithHyphens
8
+ import com.intellij.openapi.vfs.CharsetToolkit
9
+ import java.net.URI
10
+ import java.net.URLEncoder
11
+
12
+ object FailureDetailsForTeamcity : FailureDetailsOnCI {
13
+ override fun getFailureDetails (runContext : IDERunContext ): String {
14
+
15
+ return if (CIServer .instance.isBuildRunningOnCI)
16
+ getFailureDetailsForCI(runContext)
17
+ else getFailureDetailsForLocalRun(runContext)
18
+ }
19
+
20
+ private fun getFailureDetailsForCI (runContext : IDERunContext ): String {
21
+ val testMethodName = getTestMethodName().ifEmpty { runContext.contextName }
22
+ val uri = getLinkToCIArtifacts(runContext)
23
+ return " Test: $testMethodName " + System .lineSeparator() +
24
+ " You can find logs and other info in CI artifacts under the path ${runContext.contextName} " + System .lineSeparator() +
25
+ " Link on TC artifacts $uri "
26
+ }
27
+
28
+ override fun getLinkToCIArtifacts (runContext : IDERunContext ): String {
29
+ val teamCityCI = CIServer .instance.asTeamCity()
30
+ val urlString = " ${teamCityCI.serverUri} /buildConfiguration/${teamCityCI.buildTypeId} /${teamCityCI.buildId} " +
31
+ " ?buildTab=artifacts#${URLEncoder .encode(" /" + runContext.contextName.replaceSpecialCharactersWithHyphens(), CharsetToolkit .UTF8 )} "
32
+ return URI (urlString).normalize().toString()
33
+ }
34
+
35
+ private fun getFailureDetailsForLocalRun (runContext : IDERunContext ): String {
36
+ val testMethodName = getTestMethodName().ifEmpty { runContext.contextName }
37
+
38
+ return " Test: $testMethodName " + System .lineSeparator() +
39
+ " You can find logs and other info under the path ${runContext.logsDir.toRealPath()} "
40
+ }
41
+ }
0 commit comments