Управление уведомлениями сброк в тимсити

This commit is contained in:
upagge 2020-10-02 18:08:17 +03:00
parent 76ca3e8406
commit 03ed80b7fd
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
4 changed files with 43 additions and 8 deletions

View File

@ -8,5 +8,6 @@
<include file="liquibase/v.2.0.0/2020-09-20-setting-notify.xml"/> <include file="liquibase/v.2.0.0/2020-09-20-setting-notify.xml"/>
<include file="liquibase/v.2.0.0/2020-09-20-teamcity.xml"/> <include file="liquibase/v.2.0.0/2020-09-20-teamcity.xml"/>
<include file="liquibase/v.2.0.0/2020-10-01-rating.xml"/> <include file="liquibase/v.2.0.0/2020-10-01-rating.xml"/>
<include file="liquibase/v.2.0.0/2020-10-02-add-column-status-teamcity.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -0,0 +1,19 @@
<databaseChangeLog
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="2020-10-02" author="upagge">
<addColumn tableName="teamcity_setting">
<column name="success" type="boolean">
<constraints nullable="false"/>
</column>
</addColumn>
<addColumn tableName="teamcity_setting">
<column name="failure" type="boolean">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>
</databaseChangeLog>

View File

@ -35,4 +35,10 @@ public class TeamcitySetting {
@Column(name = "project_id") @Column(name = "project_id")
private String projectId; private String projectId;
@Column(name = "success")
private boolean success;
@Column(name = "failure")
private boolean failure;
} }

View File

@ -5,9 +5,11 @@ import org.sadtech.basic.core.service.AbstractSimpleManagerService;
import org.sadtech.bot.vcs.core.service.NotifyService; 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.ServiceNotify;
import org.sadtech.bot.vcs.teamcity.core.domain.entity.BuildShort; 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.repository.BuildShortRepository;
import org.sadtech.bot.vcs.teamcity.core.service.BuildShortService; import org.sadtech.bot.vcs.teamcity.core.service.BuildShortService;
import org.sadtech.bot.vcs.teamcity.core.service.TeamcitySettingService; import org.sadtech.bot.vcs.teamcity.core.service.TeamcitySettingService;
import org.sadtech.bot.vcs.teamcity.sdk.BuildStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Set; import java.util.Set;
@ -41,18 +43,25 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildSho
final BuildShort newBuildShort = buildShortRepository.save(buildShort); final BuildShort newBuildShort = buildShortRepository.save(buildShort);
teamcitySettingService.getAllByProjectId(buildShort.getProjectId()) teamcitySettingService.getAllByProjectId(buildShort.getProjectId())
.forEach( .forEach(teamcitySetting -> sendNotification(teamcitySetting, buildShort));
teamcitySetting -> notifyService.send(
ServiceNotify.builder()
.buildShort(buildShort)
.chatId(teamcitySetting.getChatId())
.build()
)
);
return newBuildShort; 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 @Override
public BuildShort update(@NonNull BuildShort buildShort) { public BuildShort update(@NonNull BuildShort buildShort) {
return buildShortRepository.save(buildShort); return buildShortRepository.save(buildShort);