diff --git a/README.md b/README.md index 00652bd..cd8ec1d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build/pom.xml b/build/pom.xml index 045c397..2003e00 100644 --- a/build/pom.xml +++ b/build/pom.xml @@ -10,7 +10,7 @@ pom yyyyMMddHHmmss - 1.1.5 + 1.1.6 Alex Kvak https://github.com/alexkvak diff --git a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/Helpers.scala b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/Helpers.scala index ff0978f..29d7874 100644 --- a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/Helpers.scala +++ b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/Helpers.scala @@ -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 diff --git a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/MessageBuilder.scala b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/MessageBuilder.scala index 17b5413..fa56023 100644 --- a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/MessageBuilder.scala +++ b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/MessageBuilder.scala @@ -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 { @@ -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 { diff --git a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/NotificationSender.scala b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/NotificationSender.scala index 8615ae9..d5710da 100644 --- a/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/NotificationSender.scala +++ b/slackIntegration-server/src/main/scala/com/fpd/teamcity/slack/NotificationSender.scala @@ -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) diff --git a/slackIntegration-server/src/test/scala/com/fpd/teamcity/slack/MessageBuilderTest.scala b/slackIntegration-server/src/test/scala/com/fpd/teamcity/slack/MessageBuilderTest.scala index b087fe6..fbba3a8 100644 --- a/slackIntegration-server/src/test/scala/com/fpd/teamcity/slack/MessageBuilderTest.scala +++ b/slackIntegration-server/src/test/scala/com/fpd/teamcity/slack/MessageBuilderTest.scala @@ -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]