Skip to content

Commit

Permalink
New placeholder users which enumerates changes authors as teamcity us…
Browse files Browse the repository at this point in the history
…er names #26
  • Loading branch information
alexkvak committed Feb 16, 2018
1 parent 50c1fc9 commit bc1b525
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ See [TeamCity Docs](https://confluence.jetbrains.com/x/iwt2B#WorkingwithFeatureB
URL to view results page.

###### {mentions}
Slack users mentions. Unknown users will be skipped.
Slack users mentions only if build fails. Unknown users will be skipped.

###### {users}
TeamCity user name list only if build fails. Unknown users will be skipped.

###### {changes}
Concatenated description of head 5 changes from build with author name (from VCS)
Expand Down
2 changes: 1 addition & 1 deletion build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<packaging>pom</packaging>
<properties>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
<teamcity.slackIntegration.plugin.version>1.1.5</teamcity.slackIntegration.plugin.version>
<teamcity.slackIntegration.plugin.version>1.1.6</teamcity.slackIntegration.plugin.version>
<teamcity.slackIntegration.plugin.vendorName>Alex Kvak</teamcity.slackIntegration.plugin.vendorName>
<teamcity.slackIntegration.plugin.vendorUrl>https://github.com/alexkvak</teamcity.slackIntegration.plugin.vendorUrl>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ object Helpers {
}

implicit class RichBuild(val build: SBuild) extends AnyVal {
def committees: Vector[String] = {
val users = build.getContainingChanges.asScala.toVector.flatMap(_.getCommitters.asScala).distinct
users.map(user Option(user.getEmail).getOrElse("")).filter(_.length > 0)
}
def committees: Vector[SUser] =
build.getContainingChanges.asScala.toVector.flatMap(_.getCommitters.asScala).distinct

def committeeEmails: Vector[String] =
committees.map(user Option(user.getEmail)).collect { case Some(x) if x.length > 0 x }

def matchBranch(mask: String): Boolean =
mask.r.findFirstIn(Option(build.getBranch).map(_.getDisplayName).getOrElse("")).isDefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ class MessageBuilder(build: SBuild, context: MessageBuilderContext) {
} mkString "\n"

def mentions = if (build.getBuildStatus.isSuccessful) "" else {
build.committees.map(context.userByEmail).collect { case Some(x) s"<@$x>" }.mkString(" ")
build.committeeEmails.map(context.userByEmail).collect { case Some(x) s"<@$x>" }.mkString(" ")
}

def users = if (build.getBuildStatus.isSuccessful) "" else {
build.committees.map(user user.getDescriptiveName).mkString(", ")
}

def reason = if (build.getBuildStatus.isSuccessful) "" else {
Expand All @@ -72,6 +76,7 @@ class MessageBuilder(build: SBuild, context: MessageBuilderContext) {
case "artifactLinks" artifactLinks
case "link" context.getViewResultsUrl(build)
case "mentions" mentions
case "users" users
case "reason" reason
case x if x.startsWith("%") && x.endsWith("%")
context.getBuildParameter(build, x.substring(1, x.length - 1).trim) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait NotificationSender {
def send(build: SBuild, flags: Set[BuildSettingFlag]): Future[Vector[MessageSent]] = {
val settings = prepareSettings(build, flags)

lazy val emails = build.committees
lazy val emails = build.committeeEmails
lazy val messageBuilder = messageBuilderFactory.createForBuild(build)
lazy val sendPersonal = shouldSendPersonal(build)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ class MessageBuilderTest extends FlatSpec with MockFactory with Matchers {
""".stripMargin.trim, MessageBuilder.statusNormalColor)
}

"MessageBuilder.compile" should "compile template with users placeholders" in {
implicit val build = stub[SBuild]

build.getFullName _ when() returns "Full name"
build.getBuildNumber _ when() returns "2"
build.getBuildStatus _ when() returns Status.FAILURE
build.getContainingChanges _ when() returns mockChanges

val messageTemplate = """{name}
|{users}
""".stripMargin

messageBuilder().compile(messageTemplate) shouldEqual SlackAttachment(
"""Full name
|name1, name2
""".stripMargin.trim, Status.FAILURE.getHtmlColor)
}

private def mockChanges = {
val vcsModification1 = stub[SVcsModification]
val vcsModification2 = stub[SVcsModification]
Expand Down

0 comments on commit bc1b525

Please sign in to comment.