diff --git a/.editorconfig b/.editorconfig index 031412f..59aa812 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,22 @@ -[*.{kt,kts}] -ktlint_disabled_rules = no-wildcard-imports +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{*.kt,*.kts}] +ij_kotlin_import_nested_classes = false +ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^ +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 = false \ No newline at end of file +ij_kotlin_allow_trailing_comma = true +ktlint_code_style = intellij_idea +ktlint_standard_discouraged-comment-location = disabled + +[{*.markdown,*.md}] +ij_wrap_on_typing = true diff --git a/renovate.json b/.github/renovate.json similarity index 100% rename from renovate.json rename to .github/renovate.json diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt index 8d50644..542e339 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt @@ -17,13 +17,13 @@ class SlackClient( private val serviceName: String?, private val serviceEmoji: String?, private val slackToken: String, - private val slackChannelId: String + private val slackChannelId: String, ) { suspend fun create( githubPushContext: GithubPushContext, jobType: JobType, - jobStatus: JobStatus + jobStatus: JobStatus, ): String { val response = makeSlackRequest( url = "https://slack.com/api/chat.postMessage", @@ -41,7 +41,7 @@ class SlackClient( messageId: String, githubPushContext: GithubPushContext, jobType: JobType, - jobStatus: JobStatus + jobStatus: JobStatus, ): String { val previousMessage = getSlackMessageById(messageId) @@ -64,7 +64,7 @@ class SlackClient( jobType: JobType, jobStatus: JobStatus, messageId: String? = null, - previousAttachments: List? = null + previousAttachments: List? = null, ): SlackMessage { val attachments = mutableMapOf() @@ -96,7 +96,7 @@ class SlackClient( } private suspend fun getSlackMessageById( - messageId: String + messageId: String, ): MessageResponse? { val response = client.get { header("Authorization", "Bearer $slackToken") @@ -145,7 +145,7 @@ class SlackClient( @SerialName("channel") val channel: String, // C024BE91L @SerialName("ts") - val ts: String // 1401383885.000061 + val ts: String, // 1401383885.000061 ) @Serializable @@ -153,6 +153,6 @@ class SlackClient( @SerialName("ok") val ok: Boolean, // true @SerialName("messages") - val messages: List + val messages: List, ) } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt index af04628..16d73f4 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/GithubPushContext.kt @@ -27,7 +27,7 @@ data class GithubPushContext( @SerialName("ref_name") val refName: String? = null, // develop @SerialName("ref_type") - val refType: String? = null // branch + val refType: String? = null, // branch ) { @Serializable @@ -37,7 +37,7 @@ data class GithubPushContext( @SerialName("pusher") val pusher: Committer? = null, @SerialName("ref") - val ref: String? = null // refs/heads/develop + val ref: String? = null, // refs/heads/develop ) @Serializable @@ -57,7 +57,7 @@ data class GithubPushContext( @SerialName("tree_id") val treeId: String? = null, // f3667a7332372de2ccb6a1cc5c310e780915a28e @SerialName("url") - val url: String? = null // https://github.com/monta-app/service-integrations/commit/c545a1613f18937a88a13935c4d644e8f81b71d6 + val url: String? = null, // https://github.com/monta-app/service-integrations/commit/c545a1613f18937a88a13935c4d644e8f81b71d6 ) @Serializable @@ -67,7 +67,7 @@ data class GithubPushContext( @SerialName("name") val name: String? = null, // Brian Estrada @SerialName("username") - val username: String? = null // BrianEstrada + val username: String? = null, // BrianEstrada ) { val displayName: String? = when { email == null && name == null -> null @@ -93,7 +93,7 @@ data class GithubPushContext( serviceEmoji: String?, slackChannelId: String, messageId: String?, - attachments: List? + attachments: List?, ): SlackMessage { val commit = event?.headCommit 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 c9db180..6d2c781 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobStatus.kt @@ -2,7 +2,7 @@ package com.monta.slack.notifier.model enum class JobStatus( val message: String, - val color: String + val color: String, ) { Progress( message = "In Progress :construction:", @@ -23,7 +23,8 @@ enum class JobStatus( Unknown( message = "Something went wrong :question:", color = "#DBAB09" - ); + ), + ; companion object { fun fromString(value: String?): JobStatus { 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 5f5e137..d7675ee 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt @@ -1,7 +1,7 @@ package com.monta.slack.notifier.model enum class JobType( - val label: String + val label: String, ) { Test( label = "Test :test_tube:" @@ -14,7 +14,8 @@ enum class JobType( ), PublishDocs( label = "Publish Docs :jigsaw:" - ); + ), + ; companion object { fun fromString(value: String): JobType { diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackBlock.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackBlock.kt index 9069ba0..644671d 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackBlock.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackBlock.kt @@ -10,7 +10,7 @@ class SlackBlock( @SerialName("text") val text: Text? = null, @SerialName("fields") - val fields: List? = null + val fields: List? = null, ) { @Serializable class Text( @@ -21,6 +21,6 @@ class SlackBlock( @SerialName("emoji") val emoji: Boolean = true, @SerialName("short") - val short: Boolean = true + val short: Boolean = true, ) } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackMessage.kt b/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackMessage.kt index 9aec1aa..ae670d8 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackMessage.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/model/SlackMessage.kt @@ -9,7 +9,7 @@ data class SlackMessage( val ts: String? = null, val text: String? = null, val blocks: List? = null, - val attachments: List? = null + val attachments: List? = null, ) { @Serializable data class Attachment( @@ -40,7 +40,7 @@ data class SlackMessage( @SerialName("footer_icon") val footerIcon: String? = null, @SerialName("blocks") - val blocks: List? = null + val blocks: List? = null, ) { val jobType = JobType.fromLabel( @@ -54,7 +54,7 @@ data class SlackMessage( @SerialName("value") val value: String, // This field's value @SerialName("short") - val short: Boolean // false + val short: Boolean, // false ) @Serializable @@ -64,7 +64,7 @@ data class SlackMessage( @SerialName("value") val text: String, // This field's value @SerialName("url") - val url: String // false + val url: String, // false ) } } diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt b/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt index 51510e0..4d0838d 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/service/PublishSlackService.kt @@ -10,7 +10,7 @@ class PublishSlackService( serviceName: String?, serviceEmoji: String?, slackToken: String, - slackChannelId: String + slackChannelId: String, ) { private val slackClient = SlackClient( @@ -24,7 +24,7 @@ class PublishSlackService( githubPushContext: GithubPushContext, jobType: JobType, jobStatus: JobStatus, - slackMessageId: String? + slackMessageId: String?, ): String { val messageId = if (slackMessageId.isNullOrBlank()) { slackClient.create( 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 7439826..5821344 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt @@ -1,6 +1,7 @@ package com.monta.slack.notifier.util import kotlinx.cinterop.ByteVar +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.allocArray import kotlinx.cinterop.memScoped import kotlinx.cinterop.toKString @@ -8,10 +9,12 @@ import platform.posix.fclose import platform.posix.fgets import platform.posix.fopen -fun readStringFromFile(filePath: String): String { +@OptIn(ExperimentalForeignApi::class) +fun readStringFromFile( + filePath: String, +): String { val returnBuffer = StringBuilder() - val file = fopen(filePath, "r") - ?: throw IllegalArgumentException("Cannot open file $filePath for reading") + val file = fopen(filePath, "r") ?: throw IllegalArgumentException("Cannot open file $filePath for reading") try { memScoped { val readBufferLength = 64 * 1024 diff --git a/src/commonMain/kotlin/com/monta/slack/notifier/util/GithubActionExtensions.kt b/src/commonMain/kotlin/com/monta/slack/notifier/util/GithubActionExtensions.kt index 578bebc..f9ce03d 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/GithubActionExtensions.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/GithubActionExtensions.kt @@ -1,5 +1,6 @@ package com.monta.slack.notifier.util +import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.memScoped import kotlinx.cinterop.toKString import platform.posix.EOF @@ -8,7 +9,11 @@ import platform.posix.fopen import platform.posix.fputs import platform.posix.getenv -fun writeToOutput(key: String, value: String) { +@OptIn(ExperimentalForeignApi::class) +fun writeToOutput( + key: String, + value: String, +) { println("Writing to output $key $value") val githubOutput = getenv("GITHUB_OUTPUT")?.toKString() 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 d827f48..a59ec3d 100644 --- a/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt +++ b/src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt @@ -4,7 +4,7 @@ fun buildTitle( repository: String?, workflow: String?, serviceName: String?, - serviceEmoji: String? + serviceEmoji: String?, ): String { val title: String? = getTitle( serviceName = serviceName, @@ -28,7 +28,7 @@ fun buildTitle( private fun getTitle( serviceName: String?, - repository: String? + repository: String?, ): String? { return if (serviceName.isNullOrBlank()) { repository.toTitle()