Обновил внешний вид уведомления о назначении ответственным

This commit is contained in:
Struchkov Mark 2023-01-17 11:17:16 +03:00
parent b6fd20cd05
commit 3fd2aa717d
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 42 additions and 7 deletions

View File

@ -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<String> reviewers;
@Builder
private NewMrForAssignee(
String title,
@ -19,7 +23,8 @@ public class NewMrForAssignee extends NewMrNotify {
String projectName,
String targetBranch,
String sourceBranch,
Set<String> labels
Set<String> labels,
@Singular List<String> reviewers
) {
super(
title,
@ -31,6 +36,7 @@ public class NewMrForAssignee extends NewMrNotify {
sourceBranch,
labels
);
this.reviewers = reviewers;
}
@Override

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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<String> 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