Skip to content

Commit

Permalink
MBS-9781 alert to slack about lint errors (#621)
Browse files Browse the repository at this point in the history
* MBS-9781 alert to slack about lint errors
  • Loading branch information
dsvoronin committed Nov 9, 2020
1 parent df76281 commit b874c73
Show file tree
Hide file tree
Showing 18 changed files with 2,224 additions and 43 deletions.
1 change: 1 addition & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.exclusions=**/integTest/resources/*.*
14 changes: 14 additions & 0 deletions subprojects/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ subprojects {

tasks.withType<Test> {
systemProperty("rootDir", "${project.rootDir}")

val testProperties = listOf(
"avito.slack.test.channel",
"avito.slack.test.token",
"avito.slack.test.workspace"
)
testProperties.forEach { key ->
val property = if (project.hasProperty(key)) {
project.property(key)!!.toString()
} else {
""
}
systemProperty(key, property)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@ import org.gradle.kotlin.dsl.invoke
class LintCheck(context: String, name: String) : SuppressibleBuildStep(context, name),
ImpactAnalysisAwareBuildStep by ImpactAnalysisAwareBuildStep.Impl() {

var slackChannelForAlerts = ""

override fun registerTask(project: Project, rootTask: TaskProvider<out Task>) {
require(project.isAndroidApp()) {
"Lint check can be applied only to android application modules"
}

if (project.buildEnvironment !is BuildEnvironment.CI) return

if (useImpactAnalysis && !project.internalModule.isModified()) return

project.pluginManager.withPlugin("com.avito.android.lint-report") {

val lintReports = project.tasks.withType<LintReportTask>()

lintReports.configureEach {
if (slackChannelForAlerts.isNotBlank()) {
it.slackReportChannel.set(slackChannelForAlerts)
}
it.abortOnError.set(!suppressFailures)
}

lintReports.forEach { task ->
task.onlyIf { !useImpactAnalysis || project.internalModule.lintConfiguration.isModified }
rootTask {
Expand Down
10 changes: 6 additions & 4 deletions subprojects/gradle/lint-report/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("java-gradle-plugin")
`maven-publish`
id("com.jfrog.bintray")
id("nebula.integtest")
}

dependencies {
Expand All @@ -13,14 +14,15 @@ dependencies {
implementation(Dependencies.kotlinHtml)
implementation(Dependencies.okhttp)

implementation(project(":gradle:android"))
implementation(project(":gradle:ci-logger"))
implementation(project(":common:okhttp"))
implementation(project(":gradle:impact-shared"))
implementation(project(":common:sentry"))
implementation(project(":gradle:git"))
implementation(project(":gradle:android"))
implementation(project(":gradle:bitbucket"))
implementation(project(":gradle:ci-logger"))
implementation(project(":gradle:git"))
implementation(project(":gradle:impact-shared"))
implementation(project(":gradle:kotlin-dsl-support"))
implementation(project(":gradle:slack"))

testImplementation(project(":gradle:logging-test-fixtures"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.avito.android.lint

import com.avito.slack.SlackClient
import com.avito.slack.model.SlackChannel
import com.avito.utils.logging.CILogger
import org.junit.jupiter.api.Test
import java.io.File

internal class LintSlackAlertIntegrationTest {

private val testChannel = SlackChannel(requireNotNull(System.getProperty("avito.slack.test.channel")))
private val testToken = requireNotNull(System.getProperty("avito.slack.test.token"))
private val workspace = requireNotNull(System.getProperty("avito.slack.test.workspace"))
private val slackClient: SlackClient = SlackClient.Impl(testToken, workspace)
private val logger: CILogger = CILogger.allToStdout

@Test
fun integrationTest() {
val parser = LintResultsParser(File("src/integTest/resources"), logger)

val reportModels = parser.parse()

val lintSlackReporter: LintSlackReporter = LintSlackReporter.Impl(slackClient, logger)

lintSlackReporter.report(reportModels, testChannel)
}
}
Loading

0 comments on commit b874c73

Please sign in to comment.