diff --git a/subprojects/gradle/lint-report/src/integTest/kotlin/com/avito/android/lint/LintSlackAlertIntegrationTest.kt b/subprojects/gradle/lint-report/src/integTest/kotlin/com/avito/android/lint/LintSlackAlertIntegrationTest.kt index 1c5d4acf90..8546d41898 100644 --- a/subprojects/gradle/lint-report/src/integTest/kotlin/com/avito/android/lint/LintSlackAlertIntegrationTest.kt +++ b/subprojects/gradle/lint-report/src/integTest/kotlin/com/avito/android/lint/LintSlackAlertIntegrationTest.kt @@ -4,6 +4,7 @@ import com.avito.android.lint.slack.LintSlackReporter import com.avito.slack.SlackClient import com.avito.slack.model.SlackChannel import com.avito.utils.logging.CILogger +import okhttp3.HttpUrl.Companion.toHttpUrl import org.junit.jupiter.api.Test import java.io.File @@ -27,7 +28,11 @@ internal class LintSlackAlertIntegrationTest { val lintSlackReporter: LintSlackReporter = LintSlackReporter.Impl(slackClient, logger) - lintSlackReporter.report(reportModels, testChannel) + lintSlackReporter.report( + lintReport = reportModels, + channel = testChannel, + buildUrl = "https://stubbuildurl".toHttpUrl() + ) } } diff --git a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportPlugin.kt b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportPlugin.kt index 6db4158eff..9976395a9a 100644 --- a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportPlugin.kt +++ b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportPlugin.kt @@ -7,7 +7,6 @@ import com.avito.bitbucket.atlassianCredentials import com.avito.bitbucket.bitbucketConfig import com.avito.utils.gradle.BuildEnvironment import com.avito.utils.gradle.buildEnvironment -import com.avito.utils.gradle.envArgs import com.avito.utils.logging.ciLogger import org.gradle.api.Plugin import org.gradle.api.Project @@ -37,8 +36,6 @@ open class LintReportPlugin : Plugin { } ) } - - buildId.set(project.envArgs.build.id) } if (app.buildEnvironment is BuildEnvironment.CI) { diff --git a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportTask.kt b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportTask.kt index 247ad6a2dd..2e1d8d1a9a 100644 --- a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportTask.kt +++ b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/LintReportTask.kt @@ -5,14 +5,12 @@ import com.avito.android.lint.html.LintReportMerger import com.avito.android.lint.model.LintIssue import com.avito.android.lint.model.LintReportModel import com.avito.android.lint.model.hasErrors +import com.avito.android.lint.teamcity.TeamcityBuildLinkAccessor import com.avito.bitbucket.Bitbucket import com.avito.bitbucket.Severity import com.avito.git.gitState import com.avito.impact.configuration.internalModule -import com.avito.kotlin.dsl.getMandatoryStringProperty import com.avito.utils.logging.ciLogger -import okhttp3.HttpUrl -import okhttp3.HttpUrl.Companion.toHttpUrl import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Project @@ -28,9 +26,6 @@ abstract class LintReportTask : DefaultTask(), BuildVerdictTask { @get:Input abstract val abortOnError: Property - @get:Input - abstract val buildId: Property - @get:Internal abstract val bitbucket: Property @@ -100,6 +95,7 @@ abstract class LintReportTask : DefaultTask(), BuildVerdictTask { private fun sendToBitbucket(reports: List) { val git = project.gitState() + val teamcityBuildLinkAccessor: TeamcityBuildLinkAccessor = TeamcityBuildLinkAccessor.Impl(project) if (!git.isPresent || !bitbucket.isPresent) { project.ciLogger.info("Sending to bitbucket skipped") @@ -117,7 +113,7 @@ abstract class LintReportTask : DefaultTask(), BuildVerdictTask { targetCommitHash = targetBranch.commit, key = "android-lint", title = "Android Lint", - link = mergedReportLink(), + link = teamcityBuildLinkAccessor.getLintArtifactUrl(), issues = reports .filterIsInstance() .flatMap { it.issues } @@ -139,11 +135,6 @@ abstract class LintReportTask : DefaultTask(), BuildVerdictTask { } } - private fun mergedReportLink(): HttpUrl { - val teamcityUrl = project.getMandatoryStringProperty("teamcityUrl").removeSuffix("/") - return "${teamcityUrl}/repository/download/AvitoAndroid_Build/${buildId.get()}:id/${project.name}/build/reports/lint-results-release.html".toHttpUrl() - } - private fun failIfNeeded(reports: List, report: File) { if (!abortOnError.getOrElse(true)) return val failed = reports.filter { it.hasErrors() } diff --git a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReportTask.kt b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReportTask.kt index 8b9bd33d72..2702b3619c 100644 --- a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReportTask.kt +++ b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReportTask.kt @@ -1,6 +1,7 @@ package com.avito.android.lint.slack import com.avito.android.lint.LintResultsParser +import com.avito.android.lint.teamcity.TeamcityBuildLinkAccessor import com.avito.slack.SlackClient import com.avito.slack.model.SlackChannel import com.avito.utils.logging.ciLogger @@ -34,9 +35,12 @@ abstract class LintSlackReportTask : DefaultTask() { lintHtml = lintHtml.get().asFile ) + val teamcityBuildLinkAccessor = createTeamcityBuildLinkAccessor() + createLintSlackAlert().report( lintReport = models, - channel = SlackChannel(slackReportChannel.get()) + channel = SlackChannel(slackReportChannel.get()), + buildUrl = teamcityBuildLinkAccessor.getBuildUrl() ) } @@ -44,6 +48,8 @@ abstract class LintSlackReportTask : DefaultTask() { log = project.ciLogger ) + private fun createTeamcityBuildLinkAccessor(): TeamcityBuildLinkAccessor = TeamcityBuildLinkAccessor.Impl(project) + private fun createLintSlackAlert(): LintSlackReporter = LintSlackReporter.Impl( slackClient = slackClient.get(), logger = ciLogger diff --git a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReporter.kt b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReporter.kt index 5f32333d71..3778aa9e9e 100644 --- a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReporter.kt +++ b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/slack/LintSlackReporter.kt @@ -5,12 +5,14 @@ import com.avito.android.lint.model.LintReportModel import com.avito.slack.SlackClient import com.avito.slack.model.SlackChannel import com.avito.utils.logging.CILogger +import okhttp3.HttpUrl interface LintSlackReporter { fun report( lintReport: LintReportModel, - channel: SlackChannel + channel: SlackChannel, + buildUrl: HttpUrl ) class Impl( @@ -22,14 +24,15 @@ interface LintSlackReporter { override fun report( lintReport: LintReportModel, - channel: SlackChannel + channel: SlackChannel, + buildUrl: HttpUrl ) { if (shouldSendAlert(lintReport)) { logger.debug("$tag: Sending lint alert...") slackClient.uploadHtml( channel = channel, - message = buildSlackMessage(lintReport), + message = buildSlackMessage(lintReport, buildUrl), file = lintReport.htmlFile ).fold( { logger.debug("$tag: Report sent successfully") }, @@ -44,9 +47,10 @@ interface LintSlackReporter { return (model is LintReportModel.Valid) && model.issues.any { it.severity == LintIssue.Severity.ERROR } } - private fun buildSlackMessage(model: LintReportModel): String { + private fun buildSlackMessage(model: LintReportModel, buildUrl: HttpUrl): String { return buildString { - appendln("*Critical lint problems detected for project ${model.projectRelativePath}!*") + appendln("*Critical lint problems detected for project ${model.projectRelativePath}*") + appendln("Build: <$buildUrl|link>") appendln() if (model is LintReportModel.Valid) { diff --git a/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/teamcity/TeamcityBuildLinkAccessor.kt b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/teamcity/TeamcityBuildLinkAccessor.kt new file mode 100644 index 0000000000..8d3f1d34fb --- /dev/null +++ b/subprojects/gradle/lint-report/src/main/kotlin/com/avito/android/lint/teamcity/TeamcityBuildLinkAccessor.kt @@ -0,0 +1,29 @@ +package com.avito.android.lint.teamcity + +import com.avito.kotlin.dsl.getMandatoryStringProperty +import com.avito.utils.gradle.envArgs +import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrl +import org.gradle.api.Project + +interface TeamcityBuildLinkAccessor { + + fun getBuildUrl(): HttpUrl + + fun getLintArtifactUrl(): HttpUrl + + class Impl(private val project: Project) : TeamcityBuildLinkAccessor { + + private val buildId = project.envArgs.build.id + + private val teamcityUrl = project.getMandatoryStringProperty("teamcityUrl").removeSuffix("/") + + override fun getBuildUrl(): HttpUrl { + return "$teamcityUrl/viewLog.html?buildId=$buildId".toHttpUrl() + } + + override fun getLintArtifactUrl(): HttpUrl { + return "$teamcityUrl/repository/download/AvitoAndroid_Build/$buildId:id/${project.name}/build/reports/lint-results-release.html".toHttpUrl() + } + } +}