diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java index 8976af7..bb6bd54 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java @@ -17,6 +17,7 @@ public class UpdateMrNotify extends MrNotify { private final Long allResolvedTasks; private final Long personTasks; private final Long personResolvedTasks; + private final String comment; @Builder private UpdateMrNotify( @@ -24,21 +25,22 @@ public class UpdateMrNotify extends MrNotify { String name, String url, String author, - String projectKey, + String projectName, Long allTasks, Long allResolvedTasks, Long personTasks, - Long personResolvedTasks + Long personResolvedTasks, + String comment ) { - super(mrId, projectKey, name, url); + super(mrId, projectName, name, url); this.author = author; this.allTasks = allTasks; this.allResolvedTasks = allResolvedTasks; this.personTasks = personTasks; this.personResolvedTasks = personResolvedTasks; + this.comment = comment; } - @Override public String getType() { return TYPE; diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index 16d1add..65059ac 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -283,17 +283,17 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { final Long botUserGitlabId = personInformation.getId(); - if ( !botUserGitlabId.equals(mergeRequest.getAuthor().getId()) // Автор MR не пользователь приложения && !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit()) // Изменилась дата последнего коммита && !mergeRequest.isConflict() // MR не находится в состоянии конфликта + && !botUserGitlabId.equals(oldMergeRequest.getAuthor().getId()) // и MR создан НЕ пользователем бота ) { - long allTask = 0; long resolvedTask = 0; long allYouTasks = 0; long resolvedYouTask = 0; + final List discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId()); for (Discussion discussion : discussions) { if (checkNotNull(discussion.getResponsible())) { @@ -310,19 +310,23 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { } } } - notifyService.send( - UpdateMrNotify.builder() - .mrId(oldMergeRequest.getId()) - .author(oldMergeRequest.getAuthor().getName()) - .name(oldMergeRequest.getTitle()) - .projectKey(project.getName()) - .url(oldMergeRequest.getWebUrl()) - .allTasks(allTask) - .allResolvedTasks(resolvedTask) - .personTasks(allYouTasks) - .personResolvedTasks(resolvedYouTask) - .build() - ); + + final UpdateMrNotify.UpdateMrNotifyBuilder notifyBuilder = UpdateMrNotify.builder() + .mrId(oldMergeRequest.getId()) + .author(oldMergeRequest.getAuthor().getName()) + .name(oldMergeRequest.getTitle()) + .projectName(project.getName()) + .url(oldMergeRequest.getWebUrl()) + .allTasks(allTask) + .allResolvedTasks(resolvedTask) + .personTasks(allYouTasks) + .personResolvedTasks(resolvedYouTask); + + if (oldMergeRequest.isConflict() && !mergeRequest.isConflict()) { + notifyBuilder.comment("The conflict has been resolved"); + } + + notifyService.send(notifyBuilder.build()); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/UpdateMrNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/UpdateMrNotifyGenerator.java index c7b2f52..7d78f9b 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/UpdateMrNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/UpdateMrNotifyGenerator.java @@ -14,6 +14,7 @@ import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoard import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton; +import static dev.struchkov.haiti.utils.Checker.checkNotBlank; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @@ -27,11 +28,16 @@ public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator 0) { + if (checkNotBlank(notify.getComment())) { + builder.append(Icons.HR) + .append(notify.getComment()); + } + + if (checkNotNull(notify.getAllTasks()) && notify.getAllTasks() > 0) { builder.append(Icons.HR) .append("All tasks: ").append(notify.getAllResolvedTasks()).append("/").append(notify.getAllTasks()); - if (notify.getPersonTasks() > 0) { + if (checkNotNull(notify.getPersonTasks()) && notify.getPersonTasks() > 0) { builder.append("\nYour tasks: ").append(notify.getPersonResolvedTasks()).append("/").append(notify.getPersonTasks()); } }