Skip to content

Commit

Permalink
fix: Correct handling of empty variables set via ENV variables. These… (
Browse files Browse the repository at this point in the history
#19)

* fix: Correct handling of empty variables set via ENV variables. These were converted to empty strings instead of null.

* ignore: Spelling

* ignore: Added `.editorconfig`
  • Loading branch information
morten-andersen authored May 26, 2023
1 parent acbc004 commit 287fe32
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{kt,kts}]
ktlint_disabled_rules = no-wildcard-imports
ij_kotlin_allow_trailing_comma_on_call_site = false
ij_kotlin_allow_trailing_comma = false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ A CLI project for sending slack messages usable in GitHub workflows.

Typically you do not use this directly but via the [slack-notifier-cli-action](https://github.com/monta-app/slack-notifier-cli-action)

Most project don't use this directly, but indirectly through the [github-workflows](https://github.com/monta-app/github-workflows)
Most projects don't use this directly, but indirectly through the [github-workflows](https://github.com/monta-app/github-workflows)
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,22 @@ class PublishSlackCommand : CliktCommand() {
override fun run() {
runBlocking {
PublishSlackService(
serviceName = serviceName,
serviceEmoji = serviceEmoji,
serviceName = serviceName.valueOrNull(),
serviceEmoji = serviceEmoji.valueOrNull(),
slackToken = slackToken,
slackChannelId = slackChannelId
).publish(
githubContext = githubContext,
jobType = JobType.fromString(jobType),
jobStatus = JobStatus.fromString(jobStatus),
slackMessageId = slackMessageId
slackMessageId = slackMessageId.valueOrNull()
)
}
}

/**
* Needed for optional parameters as the return the empty string instead of null
* if set via ENV variables (as we do from our GitHub Actions)
*/
private fun String?.valueOrNull() = if (this.isNullOrBlank()) null else this
}

0 comments on commit 287fe32

Please sign in to comment.