From d148e56cd49c05eff1832e3499015b31b7cb8b08 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 21 Feb 2023 13:52:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82=D0=B0=20=D0=B2?= =?UTF-8?q?=20=D1=87=D1=83=D0=B6=D0=BE=D0=BC=20=D0=9C=D0=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/mergerequest/UpdateMrNotify.java | 10 +++--- .../impl/MergeRequestsServiceImpl.java | 34 +++++++++++-------- .../notify/UpdateMrNotifyGenerator.java | 10 ++++-- 3 files changed, 33 insertions(+), 21 deletions(-) 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()); } }