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 d520660..f19fbcb 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 @@ -13,6 +13,8 @@ public class NewMrForAssignee extends NewMrNotify { public static final String TYPE = "NewMrForAssignee"; private final List reviewers; + private final String oldAssigneeName; + private final String newAssigneeName; @Builder private NewMrForAssignee( @@ -24,7 +26,9 @@ public class NewMrForAssignee extends NewMrNotify { String targetBranch, String sourceBranch, Set labels, - @Singular List reviewers + @Singular List reviewers, + String oldAssigneeName, + String newAssigneeName ) { super( title, @@ -37,6 +41,8 @@ public class NewMrForAssignee extends NewMrNotify { labels ); this.reviewers = reviewers; + this.oldAssigneeName = oldAssigneeName; + this.newAssigneeName = newAssigneeName; } @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 60280d7..117671e 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 @@ -17,7 +17,7 @@ public class Icons { public static final String ARROW = " ➜ "; public static final String DANGEROUS = "⚠️"; public static final String PEN = "✏️"; - public static final String ASSIGNEE = "\uD83C\uDF96"; + public static final String ASSIGNEE = "\uD83C\uDFA9"; public static final String BUILD = "\uD83D\uDEE0"; public static final String LINK = "\uD83D\uDD17"; public static final String REVIEWER = "\uD83D\uDD0E"; 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 9933d60..c7312db 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 @@ -28,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -69,7 +70,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { if (!mergeRequest.isConflict()) { final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName(); if (botUserReviewer) sendNotifyNewMrReview(savedMergeRequest, projectName); - if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName); + if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null); } } @@ -128,20 +129,27 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { ); } - private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName) { - notifyService.send( - NewMrForAssignee.builder() - .projectName(projectName) - .labels(mergeRequest.getLabels()) - .author(mergeRequest.getAuthor().getName()) - .description(mergeRequest.getDescription()) - .title(mergeRequest.getTitle()) - .url(mergeRequest.getWebUrl()) - .targetBranch(mergeRequest.getTargetBranch()) - .sourceBranch(mergeRequest.getSourceBranch()) - .reviewers(mergeRequest.getReviewers().stream().map(Person::getName).collect(Collectors.toList())) - .build() - ); + private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName, String oldAssigneeName) { + final NewMrForAssignee.NewMrForAssigneeBuilder builder = NewMrForAssignee.builder() + .projectName(projectName) + .labels(mergeRequest.getLabels()) + .author(mergeRequest.getAuthor().getName()) + .description(mergeRequest.getDescription()) + .title(mergeRequest.getTitle()) + .url(mergeRequest.getWebUrl()) + .targetBranch(mergeRequest.getTargetBranch()) + .sourceBranch(mergeRequest.getSourceBranch()) + .reviewers(mergeRequest.getReviewers().stream().map(Person::getName).toList()); + + if (checkNotNull(oldAssigneeName)) { + builder.oldAssigneeName(oldAssigneeName); + + if (checkNotNull(mergeRequest.getAssignee())) { + builder.newAssigneeName(mergeRequest.getAssignee().getName()); + } + } + + notifyService.send(builder.build()); } @Override @@ -175,7 +183,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { if (isChangedLinkedEntity) { notifyReviewer(reviewerChanged, mergeRequest, project); - notifyAssignee(assigneeChanged, mergeRequest, project); + notifyAssignee(assigneeChanged, oldMergeRequest, mergeRequest, project); } } return repository.save(mergeRequest); @@ -184,11 +192,11 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { return oldMergeRequest; } - //TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление - private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest mergeRequest, Project project) { + private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { switch (assigneeChanged) { - case BECOME -> sendNotifyNewAssignee(mergeRequest, project.getName()); + case BECOME -> + sendNotifyNewAssignee(mergeRequest, project.getName(), Optional.ofNullable(oldMergeRequest.getAssignee()).map(Person::getName).orElse(null)); } } 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 e246ea9..cdec770 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 @@ -8,7 +8,6 @@ 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; @@ -27,10 +26,9 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator .map(label -> "#" + label) .collect(Collectors.joining(" ")); - final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible*") .append(Icons.HR) - .append(link(notify.getType(), notify.getUrl())); + .append(notify.getTitle()); if (!labelText.isEmpty()) { builder.append("\n\n").append(labelText); @@ -39,16 +37,20 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator builder.append(Icons.HR); if (checkNotNull(notify.getProjectName())) { - builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())); + builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n"); } builder .append(Icons.TREE).append(": ").append(notify.getSourceBranch()).append(Icons.ARROW).append(notify.getTargetBranch()).append("\n") - .append(Icons.AUTHOR).append(": ").append(notify.getAuthor()); + .append(Icons.AUTHOR).append(": ").append(notify.getAuthor()).append("\n"); final List reviewers = notify.getReviewers(); if (checkNotEmpty(reviewers)) { - builder.append(Icons.REVIEWER).append(": ").append(String.join(", ", reviewers)); + builder.append(Icons.REVIEWER).append(": ").append(String.join(", ", reviewers)).append("\n"); + } + + if (checkNotNull(notify.getOldAssigneeName()) && checkNotNull(notify.getNewAssigneeName())) { + builder.append(Icons.ASSIGNEE).append(": ").append(notify.getOldAssigneeName()).append(Icons.ARROW).append(notify.getNewAssigneeName()).append("\n"); } final String notifyMessage = builder.toString(); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java index c6e1fac..e9ec73e 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewMrForReviewNotifyGenerator.java @@ -7,7 +7,6 @@ import org.springframework.stereotype.Component; 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; @@ -28,7 +27,7 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator 0) { builder.append(Smile.HR.getValue()) @@ -29,11 +33,25 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator