Skip to content

Commit

Permalink
TW-81203: show service message notifications-related settings in the …
Browse files Browse the repository at this point in the history
…connection description
  • Loading branch information
Fedor Rumyantsev committed May 18, 2023
1 parent df7512c commit b01a9e1
Showing 1 changed file with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package jetbrains.buildServer.notification.slackNotifier

import com.intellij.openapi.util.text.StringUtil
import jetbrains.buildServer.serverSide.InvalidProperty
import jetbrains.buildServer.serverSide.PropertiesProcessor
import jetbrains.buildServer.serverSide.oauth.OAuthConnectionDescriptor
import jetbrains.buildServer.serverSide.oauth.OAuthProvider
import jetbrains.buildServer.serverSide.oauth.github.GitHubConstants
import jetbrains.buildServer.serverSide.oauth.github.GitHubOAuthProvider
import jetbrains.buildServer.web.openapi.PluginDescriptor
import org.springframework.context.annotation.Conditional
import org.springframework.stereotype.Service
Expand All @@ -41,12 +40,43 @@ class SlackConnection(
pluginDescriptor.getPluginResourcesPath("editConnectionParameters.jsp")

override fun describeConnection(connection: OAuthConnectionDescriptor): String {
val builder = StringBuilder()

val displayName = connection.connectionDisplayName
if (displayName.isEmpty()) {
return "Connection to a single Slack workspace"
builder.append("Connection to a single Slack workspace")
} else {
builder.append("Connection name: $displayName")
}

val rawLimitValue = connection.parameters["serviceMessageMaxNotificationsPerBuild"]
if (rawLimitValue != null) {
val limit: Long? = rawLimitValue.toLongOrNull()
if (limit != null && limit != 0L) {
builder
.append(System.lineSeparator())
.append("Service message notifications are enabled")
.append(System.lineSeparator())

when (limit) {
-1L -> {
builder.append("Each build may produce unlimited number of notifications")
}
else -> {
builder.append("Each build may produce $limit ${StringUtil.pluralize("notification", limit.toInt())}")
}
}

val allowedDomains = connection.parameters["serviceMessageAllowedDomainNames"] ?: ""
if (allowedDomains.isNotEmpty()) {
builder
.append(System.lineSeparator())
.append("Allowed domain name patterns: $allowedDomains")
}
}
}

return displayName
return builder.toString()
}

override fun getPropertiesProcessor(): PropertiesProcessor = PropertiesProcessor {
Expand Down

0 comments on commit b01a9e1

Please sign in to comment.