From 03ed80b7fd906992d4ea0937655b81564bdc2308 Mon Sep 17 00:00:00 2001 From: upagge Date: Fri, 2 Oct 2020 18:08:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8=20=D1=81=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=B2=20=D1=82=D0=B8=D0=BC=D1=81=D0=B8=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v.2.0.0/2020-09-06-cumulative.xml | 1 + .../2020-10-02-add-column-status-teamcity.xml | 19 ++++++++++++++ .../core/domain/entity/TeamcitySetting.java | 6 +++++ .../service/impl/BuildShortServiceImpl.java | 25 +++++++++++++------ 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml index 79212a1..3638d94 100644 --- a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml @@ -8,5 +8,6 @@ + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml new file mode 100644 index 0000000..3268baf --- /dev/null +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/domain/entity/TeamcitySetting.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/domain/entity/TeamcitySetting.java index 061c869..2933275 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/domain/entity/TeamcitySetting.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/domain/entity/TeamcitySetting.java @@ -35,4 +35,10 @@ public class TeamcitySetting { @Column(name = "project_id") private String projectId; + @Column(name = "success") + private boolean success; + + @Column(name = "failure") + private boolean failure; + } diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/service/impl/BuildShortServiceImpl.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/service/impl/BuildShortServiceImpl.java index e7af188..1a82897 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/service/impl/BuildShortServiceImpl.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/vcs/teamcity/core/service/impl/BuildShortServiceImpl.java @@ -5,9 +5,11 @@ import org.sadtech.basic.core.service.AbstractSimpleManagerService; import org.sadtech.bot.vcs.core.service.NotifyService; import org.sadtech.bot.vcs.teamcity.core.domain.ServiceNotify; import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort; +import org.sadtech.bot.vcs.teamcity.core.domain.entity.TeamcitySetting; import org.sadtech.bot.vcs.teamcity.core.repository.BuildShortRepository; import org.sadtech.bot.vcs.teamcity.core.service.BuildShortService; import org.sadtech.bot.vcs.teamcity.core.service.TeamcitySettingService; +import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus; import org.springframework.stereotype.Service; import java.util.Set; @@ -41,18 +43,25 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService notifyService.send( - ServiceNotify.builder() - .buildShort(buildShort) - .chatId(teamcitySetting.getChatId()) - .build() - ) - ); + .forEach(teamcitySetting -> sendNotification(teamcitySetting, buildShort)); return newBuildShort; } + private void sendNotification(TeamcitySetting teamcitySetting, BuildShort buildShort) { + if ( + (teamcitySetting.isFailure() && BuildStatus.FAILURE.equals(buildShort.getStatus())) + || (teamcitySetting.isSuccess() && BuildStatus.SUCCESS.equals(buildShort.getStatus())) + ) { + notifyService.send( + ServiceNotify.builder() + .buildShort(buildShort) + .chatId(teamcitySetting.getChatId()) + .build() + ); + } + } + @Override public BuildShort update(@NonNull BuildShort buildShort) { return buildShortRepository.save(buildShort);