Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set message when building LegacyCustomWebhookMessage #670

Merged
merged 1 commit into from
Dec 1, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ data class Destination(
}
DestinationType.CUSTOM_WEBHOOK -> {
destinationMessage = LegacyCustomWebhookMessage.Builder(name)
.withUrl(getLegacyCustomWebhookMessageURL(customWebhook))
.withUrl(getLegacyCustomWebhookMessageURL(customWebhook, compiledMessage))
.withHeaderParams(customWebhook?.headerParams)
.withMessage(compiledMessage).build()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is passed in here. It's not required in getLegacyCustomWebhookMessageURL since that method is only combining the individual URL parameters to a String to pass to withUrl.

Copy link
Contributor

@qreshi qreshi Nov 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you're saying. We're not setting message in the builder and it's throwing an IllegalArgumentException when we call build() in getLegacyCustomWebhookMessageURL()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct. It is true that it is not required for actual construction of URI, but unfortunately it is required field of LegacyCustomWebhookMessage and it always throws IllegalArgumentException("Message content is missing"). I went with this solution as it is simple and this legacy destination is only used in limited number of cases (and it will probably be removed in some of future releases).

It would probably be best to completely separate URI construction code of constructing LegacyCustomWebhookMessage object itself, but as message is available here I went with this easy fix.

}
Expand Down Expand Up @@ -296,14 +296,15 @@ data class Destination(
return content
}

private fun getLegacyCustomWebhookMessageURL(customWebhook: CustomWebhook?): String {
private fun getLegacyCustomWebhookMessageURL(customWebhook: CustomWebhook?, message: String): String {
return LegacyCustomWebhookMessage.Builder(name)
.withUrl(customWebhook?.url)
.withScheme(customWebhook?.scheme)
.withHost(customWebhook?.host)
.withPort(customWebhook?.port)
.withPath(customWebhook?.path)
.withQueryParams(customWebhook?.queryParams)
.withMessage(message)
.build().uri.toString()
}
}