diff --git a/.editorconfig b/.editorconfig index 59aa812..c856203 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,10 +13,15 @@ ij_kotlin_packages_to_use_import_on_demand = io.ktor.** ij_kotlin_name_count_to_use_star_import = 200000000 ij_kotlin_name_count_to_use_star_import_for_members = 2000000000 ij_kotlin_parameter_annotation_wrap = off -ij_kotlin_allow_trailing_comma_on_call_site = false ij_kotlin_allow_trailing_comma = true +ij_kotlin_allow_trailing_comma_on_call_site = false +ktlint_standard_trailing-comma-on-call-site = disabled +ktlint_standard_trailing-comma-on-declaration-site = enabled ktlint_code_style = intellij_idea ktlint_standard_discouraged-comment-location = disabled [{*.markdown,*.md}] ij_wrap_on_typing = true + +[{*.js,*.jsx,*.ts,*.tsx}] +max_line_length = 140 diff --git a/.gitignore b/.gitignore index 527b7cf..6ac533a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gradle /build/ /plugin/build +.kotlin/ # Ignore Gradle GUI config gradle-app.setting diff --git a/build.gradle.kts b/build.gradle.kts index 8d90af4..7e85848 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { kotlin("multiplatform") version "2.3.20" kotlin("plugin.serialization") version "2.3.20" - id("org.jlleitschuh.gradle.ktlint") version "12.3.0" + id("org.jlleitschuh.gradle.ktlint") version "14.2.0" } group = "com.monta.slack.notifier" diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt index d5c6780..dd4515f 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubEvent.kt @@ -10,9 +10,7 @@ class GithubEvent( val workflow: String?, val prUrl: String?, ) { - fun getRunUrl(): String { - return "https://github.com/$repository/actions/runs/$runId" - } + fun getRunUrl(): String = "https://github.com/$repository/actions/runs/$runId" fun getChangeIdentifier(): String? { if (commitSHA != null) { return commitSHA @@ -29,14 +27,13 @@ class GithubEvent( } return "https://github.com/$repository/" } - fun getChangeMessage(): String? { - return message - ?.replace("\n", " ") - ?.replace("\r", " ") - ?.replace("<", "") - ?.replace(">", "") - ?.take(120) - } + fun getChangeMessage(): String? = message + ?.replace("\n", " ") + ?.replace("\r", " ") + ?.replace("<", "") + ?.replace(">", "") + ?.take(120) + fun getPRidentifier(url: String): String? { // Will extract the "pull/51" part of // "https://github.com/monta-app/data-smart-charge/pull/51", diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt index 6d2c781..db003fa 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt @@ -27,10 +27,8 @@ enum class JobStatus( ; companion object { - fun fromString(value: String?): JobStatus { - return values().find { state -> - state.name.equals(value, true) - } ?: Unknown - } + fun fromString(value: String?): JobStatus = entries.find { state -> + state.name.equals(value, true) + } ?: Unknown } } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt index d7675ee..e916683 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt @@ -18,16 +18,12 @@ enum class JobType( ; companion object { - fun fromString(value: String): JobType { - return JobType.values().find { state -> - state.name.equals(value, true) - } ?: throw RuntimeException("Unknown job type $value") - } + fun fromString(value: String): JobType = entries.find { state -> + state.name.equals(value, true) + } ?: throw RuntimeException("Unknown job type $value") - fun fromLabel(label: String?): JobType? { - return JobType.values().find { state -> - state.label.equals(label, true) - } + fun fromLabel(label: String?): JobType? = entries.find { state -> + state.label.equals(label, true) } } } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt index b689900..625bf66 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -40,9 +40,8 @@ fun readStringFromFile( * Populates the existing event type with information needed to generate * an entire Slack notification. */ -fun populateEventFromJson(eventJson: String): BaseGithubContext { - return populateOnJsonPush(eventJson) ?: populateOnJsonOpened(eventJson) ?: populateOnJsonCreated(eventJson) ?: handleFailure() -} +@Suppress("detekt:ParameterListWrapping") +fun populateEventFromJson(eventJson: String): BaseGithubContext = populateOnJsonPush(eventJson) ?: populateOnJsonOpened(eventJson) ?: populateOnJsonCreated(eventJson) ?: handleFailure() private fun populateOnJsonPush(eventJson: String): BaseGithubContext? { @Suppress("SwallowedException") @@ -89,11 +88,9 @@ private fun populateOnJsonCreated(eventJson: String): BaseGithubContext? { } } -private fun handleFailure(): BaseGithubContext { - return BaseGithubContext( - displayName = null, - sha = null, - message = null, - prUrl = null - ) -} +private fun handleFailure(): BaseGithubContext = BaseGithubContext( + displayName = null, + sha = null, + message = null, + prUrl = null +) diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/HttpClient.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/HttpClient.kt index b1ed3e9..4ad79d9 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/HttpClient.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/HttpClient.kt @@ -4,11 +4,11 @@ import io.ktor.client.* import io.ktor.client.engine.curl.* import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.json.Json import kotlin.experimental.ExperimentalNativeApi import kotlin.native.OsFamily import kotlin.native.Platform -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json @OptIn(ExperimentalSerializationApi::class, ExperimentalNativeApi::class) val client by lazy { diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt index a59ec3d..6a96a3f 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt @@ -29,25 +29,21 @@ fun buildTitle( private fun getTitle( serviceName: String?, repository: String?, -): String? { - return if (serviceName.isNullOrBlank()) { - repository.toTitle() - } else { - serviceName - } +): String? = if (serviceName.isNullOrBlank()) { + repository.toTitle() +} else { + serviceName } -private fun String?.toTitle(): String? { - return this?.split("/") - ?.last() - ?.split("-") - ?.joinToString(" ") { word -> - word.replaceFirstChar { firstChar -> - if (firstChar.isLowerCase()) { - firstChar.titlecase() - } else { - firstChar.toString() - } +private fun String?.toTitle(): String? = this?.split("/") + ?.last() + ?.split("-") + ?.joinToString(" ") { word -> + word.replaceFirstChar { firstChar -> + if (firstChar.isLowerCase()) { + firstChar.titlecase() + } else { + firstChar.toString() } } -} + }