Skip to content

Commit

Permalink
ignore: applied new linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianEstrada committed Dec 11, 2023
1 parent 9e6fb93 commit 2d3ac8e
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 33 deletions.
24 changes: 21 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
ij_kotlin_allow_trailing_comma = true
ktlint_code_style = intellij_idea
ktlint_standard_discouraged-comment-location = disabled

[{*.markdown,*.md}]
ij_wrap_on_typing = true
File renamed without changes.
14 changes: 7 additions & 7 deletions src/commonMain/kotlin/com/monta/slack/notifier/SlackClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -41,7 +41,7 @@ class SlackClient(
messageId: String,
githubPushContext: GithubPushContext,
jobType: JobType,
jobStatus: JobStatus
jobStatus: JobStatus,
): String {
val previousMessage = getSlackMessageById(messageId)

Expand All @@ -64,7 +64,7 @@ class SlackClient(
jobType: JobType,
jobStatus: JobStatus,
messageId: String? = null,
previousAttachments: List<SlackMessage.Attachment>? = null
previousAttachments: List<SlackMessage.Attachment>? = null,
): SlackMessage {
val attachments = mutableMapOf<JobType, SlackMessage.Attachment>()

Expand Down Expand Up @@ -96,7 +96,7 @@ class SlackClient(
}

private suspend fun getSlackMessageById(
messageId: String
messageId: String,
): MessageResponse? {
val response = client.get {
header("Authorization", "Bearer $slackToken")
Expand Down Expand Up @@ -145,14 +145,14 @@ class SlackClient(
@SerialName("channel")
val channel: String, // C024BE91L
@SerialName("ts")
val ts: String // 1401383885.000061
val ts: String, // 1401383885.000061
)

@Serializable
private data class MessageResponse(
@SerialName("ok")
val ok: Boolean, // true
@SerialName("messages")
val messages: List<SlackMessage>
val messages: List<SlackMessage>,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -93,7 +93,7 @@ data class GithubPushContext(
serviceEmoji: String?,
slackChannelId: String,
messageId: String?,
attachments: List<SlackMessage.Attachment>?
attachments: List<SlackMessage.Attachment>?,
): SlackMessage {
val commit = event?.headCommit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand All @@ -23,7 +23,8 @@ enum class JobStatus(
Unknown(
message = "Something went wrong :question:",
color = "#DBAB09"
);
),
;

companion object {
fun fromString(value: String?): JobStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.monta.slack.notifier.model

enum class JobType(
val label: String
val label: String,
) {
Test(
label = "Test :test_tube:"
Expand All @@ -14,7 +14,8 @@ enum class JobType(
),
PublishDocs(
label = "Publish Docs :jigsaw:"
);
),
;

companion object {
fun fromString(value: String): JobType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SlackBlock(
@SerialName("text")
val text: Text? = null,
@SerialName("fields")
val fields: List<Text>? = null
val fields: List<Text>? = null,
) {
@Serializable
class Text(
Expand All @@ -21,6 +21,6 @@ class SlackBlock(
@SerialName("emoji")
val emoji: Boolean = true,
@SerialName("short")
val short: Boolean = true
val short: Boolean = true,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class SlackMessage(
val ts: String? = null,
val text: String? = null,
val blocks: List<SlackBlock>? = null,
val attachments: List<Attachment>? = null
val attachments: List<Attachment>? = null,
) {
@Serializable
data class Attachment(
Expand Down Expand Up @@ -40,7 +40,7 @@ data class SlackMessage(
@SerialName("footer_icon")
val footerIcon: String? = null,
@SerialName("blocks")
val blocks: List<SlackBlock>? = null
val blocks: List<SlackBlock>? = null,
) {

val jobType = JobType.fromLabel(
Expand All @@ -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
Expand All @@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PublishSlackService(
serviceName: String?,
serviceEmoji: String?,
slackToken: String,
slackChannelId: String
slackChannelId: String,
) {

private val slackClient = SlackClient(
Expand All @@ -24,7 +24,7 @@ class PublishSlackService(
githubPushContext: GithubPushContext,
jobType: JobType,
jobStatus: JobStatus,
slackMessageId: String?
slackMessageId: String?,
): String {
val messageId = if (slackMessageId.isNullOrBlank()) {
slackClient.create(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fun buildTitle(
repository: String?,
workflow: String?,
serviceName: String?,
serviceEmoji: String?
serviceEmoji: String?,
): String {
val title: String? = getTitle(
serviceName = serviceName,
Expand All @@ -28,7 +28,7 @@ fun buildTitle(

private fun getTitle(
serviceName: String?,
repository: String?
repository: String?,
): String? {
return if (serviceName.isNullOrBlank()) {
repository.toTitle()
Expand Down

0 comments on commit 2d3ac8e

Please sign in to comment.