Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
/build/
/plugin/build
.kotlin/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
14 changes: 5 additions & 9 deletions src/commonMain/kotlin/com/monta/slack/notifier/model/JobType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
19 changes: 8 additions & 11 deletions src/commonMain/kotlin/com/monta/slack/notifier/util/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 14 additions & 18 deletions src/commonMain/kotlin/com/monta/slack/notifier/util/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}