I'm not 100% happy with this change. It definitely simplifies the creation of slack messages from the data that is generated by the TeamCity build status events. However, I notice that the SlackWrapper class is basically a useless abstraction in the current way the code is organized.
For each event the SlackNotificator receives and each user in the set of users who need to be notified for this event, we instantiate a new SlackWrapper and then call send on that wrapper instance. But, we never need to reuse any of the state on the SlackWrapper object, so, we might as well just be passing the data straight through instead of storing it on an object.
I'd like to get this much of the code integrated into the project as it provides some benefit (no longer need the SlackPayload class.) But, then I'm going to continue restructuring the SlackNotificator such that it's job is basically to:
Create a TeamCityEvent object which describes what happened from TeamCity's point of view (e.g. The build failed.)
For each user who needs to be notified, create a SlackTarget object which describes the data we currently keep on SlackWrapper and then passes that Set<SlackTarget> and TeamCityEvent to a new version of SlackWrapper.send() which will just be responsible for creating a SlackMessage and sending it to the SlackApi for each SlackTarget and TeamCityEvent This way, we can construct the SlackWrapper only once and cache instances of SlackApi based on the slackUrl from which they are constructed.
If you'd prefer, I can go ahead and work on those changes as part of this pull request, but this code is working, so I'd prefer to get it checked in, and then add these other pieces incrementally.
I'm not 100% happy with this change. It definitely simplifies the creation of slack messages from the data that is generated by the TeamCity build status events. However, I notice that the
SlackWrapper
class is basically a useless abstraction in the current way the code is organized.For each event the
SlackNotificator
receives and each user in the set of users who need to be notified for this event, we instantiate a newSlackWrapper
and then callsend
on that wrapper instance. But, we never need to reuse any of the state on theSlackWrapper
object, so, we might as well just be passing the data straight through instead of storing it on an object.I'd like to get this much of the code integrated into the project as it provides some benefit (no longer need the
SlackPayload
class.) But, then I'm going to continue restructuring theSlackNotificator
such that it's job is basically to:TeamCityEvent
object which describes what happened from TeamCity's point of view (e.g. The build failed.)SlackTarget
object which describes the data we currently keep onSlackWrapper
and then passes thatSet<SlackTarget>
andTeamCityEvent
to a new version ofSlackWrapper.send()
which will just be responsible for creating aSlackMessage
and sending it to theSlackApi
for eachSlackTarget
andTeamCityEvent
This way, we can construct theSlackWrapper
only once and cache instances ofSlackApi
based on theslackUrl
from which they are constructed.If you'd prefer, I can go ahead and work on those changes as part of this pull request, but this code is working, so I'd prefer to get it checked in, and then add these other pieces incrementally.