Skip to content

Commit

Permalink
TW-80806: rename all adHoc... fields to serviceMessage...
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Rumyantsev committed Apr 26, 2023
1 parent 99b73a7 commit 39099c3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package jetbrains.buildServer.notification.slackNotifier

import jetbrains.buildServer.BaseTestCase
import jetbrains.buildServer.BuildProblemData
import jetbrains.buildServer.ExtensionHolder
import jetbrains.buildServer.buildFeatures.approvals.ApprovalConstants
Expand Down Expand Up @@ -45,7 +44,7 @@ open class BaseSlackTestCase : BaseNotificationRulesTestCase() {
protected lateinit var myChannelName: String
private lateinit var myUser: SUser
private lateinit var myAssignerUser: SUser
private lateinit var myAdHocMessageBuilder: PlainAdHocMessageBuilder
private lateinit var myAdHocMessageBuilder: PlainServiceMessageNotificationMessageBuilder
private lateinit var myNotificationCountHandler: BuildPromotionNotificationCountHandler
private lateinit var myDomainNameFinder: DomainNameFinder

Expand Down Expand Up @@ -81,7 +80,7 @@ open class BaseSlackTestCase : BaseNotificationRulesTestCase() {
myFixture.projectManager
)

myAdHocMessageBuilder = PlainAdHocMessageBuilder(detailsFormatter)
myAdHocMessageBuilder = PlainServiceMessageNotificationMessageBuilder(detailsFormatter)

myNotificationCountHandler = myFixture.getSingletonService(
BuildPromotionNotificationCountHandler::class.java
Expand Down Expand Up @@ -150,8 +149,8 @@ open class BaseSlackTestCase : BaseNotificationRulesTestCase() {
"secure:token" to "test_token",
"clientId" to "test_clientId",
"secure:clientSecret" to "test_clientSecret",
"adHocMaxNotificationsPerBuild" to maxNotificationsPerBuild.toString(),
"adHocAllowedDomainNames" to allowedDomainNames.joinToString(",")
"serviceMessageMaxNotificationsPerBuild" to maxNotificationsPerBuild.toString(),
"serviceMessageAllowedDomainNames" to allowedDomainNames.joinToString(",")
)
)
}
Expand Down
6 changes: 4 additions & 2 deletions src/kotlin-dsl/SlackConnection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
Client secret
</description>
</param>
<param name="adHocMaxNotificationsPerBuild" dslName="adHocMaxNotificationsPerBuild">
<param name="serviceMessageMaxNotificationsPerBuild">
<description>
Max number of service message notifications per build
</description>
</param>
<param name="adHocAllowedDomainNames" dslName="adHocAllowedDomainNames">
<param name="serviceMessageAllowedDomainNames">
<description>
Whitelist of domain names which may be included in service message notification
</description>
Expand All @@ -80,6 +80,8 @@
botToken = "credentialsJSON:321-321"
clientId = "Slack client id"
clientSecret = "credentialsJSON:123-123"
serviceMessageMaxNotificationsPerBuild = 0
serviceMessageAllowedDomainNames = "jetbrains.com,*.example.com"
}
</code>
</example>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ class SlackConnection(
errors.add(InvalidProperty("secure:clientSecret", "Client secret must be specified"))
}

val maxNotificationsPerBuild = it["adHocMaxNotificationsPerBuild"]
val maxNotificationsPerBuild = it["serviceMessageMaxNotificationsPerBuild"]
if (!maxNotificationsPerBuild.isNullOrEmpty() && maxNotificationsPerBuild.toIntOrNull() == null) {
errors.add(InvalidProperty("adHocMaxNotificationsPerBuild", "Could not parse integer value"))
errors.add(InvalidProperty("serviceMessageMaxNotificationsPerBuild", "Could not parse integer value"))
}

errors
}

override fun getDefaultProperties(): MutableMap<String, String> {
return hashMapOf("adHocMaxNotificationsPerBuild" to "0")
return hashMapOf("serviceMessageMaxNotificationsPerBuild" to "0")
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SlackNotifierDescriptor(

fun getType(): String = notifierType

fun getServiceMessageNotifierType(): String = adHocNotifierType
fun getServiceMessageNotifierType(): String = serviceMessageNotifierType

fun getDisplayName(): String {
if (displayNameClashes()) {
Expand All @@ -99,7 +99,7 @@ class SlackNotifierDescriptor(

companion object {
const val notifierType = "jbSlackNotifier"
const val adHocNotifierType = "slack"
const val serviceMessageNotifierType = "slack"
const val defaultDisplayName = "Slack Notifier"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import jetbrains.buildServer.serverSide.SRunningBuild
import org.springframework.stereotype.Service

@Service
class PlainAdHocMessageBuilder(
class PlainServiceMessageNotificationMessageBuilder(
private val detailsFormatter: DetailsFormatter
): AdHocMessageBuilder {
): ServiceMessageNotificationMessageBuilder {
override fun buildRelatedNotification(
build: SRunningBuild,
message: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package jetbrains.buildServer.notification.slackNotifier.notification

import jetbrains.buildServer.serverSide.SRunningBuild

interface AdHocMessageBuilder {
interface ServiceMessageNotificationMessageBuilder {
/**
* Called when a new service message notification is sent.
* @param build started build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SlackNotifier(
notifierRegistry: NotificatorRegistry,
slackApiFactory: SlackWebApiFactory,
private val messageBuilderFactory: ChoosingMessageBuilderFactory,
private val adHocMessageBuilder: PlainAdHocMessageBuilder,
private val serviceMessageMessageBuilder: PlainServiceMessageNotificationMessageBuilder,
private val projectManager: ProjectManager,
private val oauthManager: OAuthConnectionsManager,
private val descriptor: SlackNotifierDescriptor,
Expand Down Expand Up @@ -370,7 +370,7 @@ class SlackNotifier(
val sendTo = parameters["sendTo"]
?: throw ServiceMessageNotificationException("'sendTo' argument was not specified for message $message, build ID ${runningBuild.buildId}")

val processedMessagePayload = adHocMessageBuilder.buildRelatedNotification(
val processedMessagePayload = serviceMessageMessageBuilder.buildRelatedNotification(
runningBuild,
message
)
Expand Down Expand Up @@ -408,7 +408,7 @@ class SlackNotifier(
}

private fun getMaxAdHocNotificationsPerBuild(descriptor: OAuthConnectionDescriptor): Int {
val rawLimitValue = descriptor.parameters["adHocMaxNotificationsPerBuild"] ?: return 0
val rawLimitValue = descriptor.parameters["serviceMessageMaxNotificationsPerBuild"] ?: return 0

try {
return rawLimitValue.toInt()
Expand Down Expand Up @@ -449,7 +449,7 @@ class SlackNotifier(
message: String,
descriptor: OAuthConnectionDescriptor
) {
val allowedDomainNamePatternsString = descriptor.parameters["adHocAllowedDomainNames"]
val allowedDomainNamePatternsString = descriptor.parameters["serviceMessageAllowedDomainNames"]
?: ""

val allowedPatterns = domainNameFinder.getPatterns(allowedDomainNamePatternsString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,20 @@
</td>
</tr>
<tr>
<td><label for="adHocMaxNotificationsPerBuild">Notifications limit:</label></td>
<td><label for="serviceMessageMaxNotificationsPerBuild">Notifications limit:</label></td>
<td>
<props:textProperty name="adHocMaxNotificationsPerBuild"
value="${empty propertiesBean.properties[\"adHocMaxNotificationsPerBuild\"]
? propertiesBean.defaultProperties[\"adHocMaxNotificationsPerBuild\"]
: propertiesBean.properties[\"adHocMaxNotificationsPerBuild\"]}"/>
<props:textProperty name="serviceMessageMaxNotificationsPerBuild"
value="${empty propertiesBean.properties[\"serviceMessageMaxNotificationsPerBuild\"]
? propertiesBean.defaultProperties[\"serviceMessageMaxNotificationsPerBuild\"]
: propertiesBean.properties[\"serviceMessageMaxNotificationsPerBuild\"]}"/>
<bs:smallNote>Limits the number of service message notifications per build run. Set to '0' to disable service message notifications.</bs:smallNote>
<span class="error" id="error_adHocMaxNotificationsPerBuild"></span>
<span class="error" id="error_serviceMessageMaxNotificationsPerBuild"></span>
</td>
</tr>
<tr>
<td><label for="adHocAllowedDomainNames">Allowed hostnames:</label></td>
<td><label for="serviceMessageAllowedDomainNames">Allowed hostnames:</label></td>
<td>
<props:textProperty name="adHocAllowedDomainNames" expandable="true" style="width: 20em"/>
<props:textProperty name="serviceMessageAllowedDomainNames" expandable="true" style="width: 20em"/>
<bs:smallNote>For security reasons, only links to this TeamCity server are allowed in notifications. Notifications with URLs to external web resources are automatically blocked. This setting allows you to specify comma-separated list of trusted hostnames that can be referenced in notifications. Use the asterisk (*) as a wildcard for any string (for example, *.test.co.uk).</bs:smallNote>
</td>
</tr>
Expand Down

0 comments on commit 39099c3

Please sign in to comment.