diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java index 81e8816..d520660 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java @@ -2,7 +2,9 @@ package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest; import lombok.Builder; import lombok.Getter; +import lombok.Singular; +import java.util.List; import java.util.Set; @Getter @@ -10,6 +12,8 @@ public class NewMrForAssignee extends NewMrNotify { public static final String TYPE = "NewMrForAssignee"; + private final List reviewers; + @Builder private NewMrForAssignee( String title, @@ -19,7 +23,8 @@ public class NewMrForAssignee extends NewMrNotify { String projectName, String targetBranch, String sourceBranch, - Set labels + Set labels, + @Singular List reviewers ) { super( title, @@ -31,6 +36,7 @@ public class NewMrForAssignee extends NewMrNotify { sourceBranch, labels ); + this.reviewers = reviewers; } @Override diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java index 91f92f7..0458e67 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/utils/Icons.java @@ -20,6 +20,7 @@ public class Icons { public static final String ASSIGNEE = "\uD83C\uDF96"; public static final String BUILD = "\uD83D\uDEE0"; public static final String LINK = "\uD83D\uDD17"; + public static final String REVIEWER = "\uD83D\uDD0E"; private Icons() { utilityClass(); 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 d818088..997b56e 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 @@ -69,7 +69,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { if (!mergeRequest.isConflict()) { final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName(); if (botUserReviewer) sendNotifyNewMrReview(savedMergeRequest, projectName); - if (botUserAssignee) sendNotifyAboutAssignee(mergeRequest, projectName); + if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName); } } @@ -127,7 +127,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { ); } - private void sendNotifyAboutAssignee(MergeRequest mergeRequest, String projectName) { + private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName) { notifyService.send( NewMrForAssignee.builder() .projectName(projectName) @@ -138,6 +138,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { .url(mergeRequest.getWebUrl()) .targetBranch(mergeRequest.getTargetBranch()) .sourceBranch(mergeRequest.getSourceBranch()) + .reviewers(mergeRequest.getReviewers().stream().map(Person::getName).collect(Collectors.toList())) .build() ); } @@ -186,7 +187,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { //TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest mergeRequest, Project project) { switch (assigneeChanged) { - case BECOME -> sendNotifyAboutAssignee(mergeRequest, project.getName()); + case BECOME -> sendNotifyNewAssignee(mergeRequest, project.getName()); } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForAssigneeNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForAssigneeNotifyGenerator.java index cd17eb1..87e9351 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForAssigneeNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForAssigneeNotifyGenerator.java @@ -5,10 +5,17 @@ import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.godfather.main.domain.BoxAnswer; import org.springframework.stereotype.Component; +import java.util.List; import java.util.stream.Collectors; import static dev.struchkov.bot.gitlab.context.utils.Icons.link; import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; +import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton; +import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine; +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.checkNotEmpty; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @Component @@ -21,7 +28,7 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator .collect(Collectors.joining(" ")); - final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible | ").append(escapeMarkdown(notify.getProjectName())).append("*") + final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible*") .append(Icons.HR) .append(link(notify.getType(), notify.getUrl())); @@ -29,12 +36,32 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator builder.append("\n\n").append(labelText); } - builder.append(Icons.HR) + builder.append(Icons.HR); + + if (checkNotNull(notify.getProjectName())) { + builder.append("Project").append(": ").append(escapeMarkdown(notify.getProjectName())); + } + + builder .append(Icons.TREE).append(": ").append(notify.getSourceBranch()).append(Icons.ARROW).append(notify.getTargetBranch()).append("\n") .append(Icons.AUTHOR).append(": ").append(notify.getAuthor()); + final List reviewers = notify.getReviewers(); + if (checkNotEmpty(reviewers)) { + builder.append(Icons.REVIEWER).append(": ").append(String.join(", ", reviewers)); + } + final String notifyMessage = builder.toString(); - return boxAnswer(notifyMessage); + + return boxAnswer( + notifyMessage, + inlineKeyBoard( + simpleLine( + simpleButton(Icons.VIEW, "DELETE_MESSAGE"), + urlButton(Icons.LINK, notify.getUrl()) + ) + ) + ); } @Override