Изменение формата уведомлений
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
aee809304a
commit
b530c061f3
@ -13,6 +13,8 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
public static final String TYPE = "NewMrForAssignee";
|
public static final String TYPE = "NewMrForAssignee";
|
||||||
|
|
||||||
private final List<String> reviewers;
|
private final List<String> reviewers;
|
||||||
|
private final String oldAssigneeName;
|
||||||
|
private final String newAssigneeName;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewMrForAssignee(
|
private NewMrForAssignee(
|
||||||
@ -24,7 +26,9 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
String targetBranch,
|
String targetBranch,
|
||||||
String sourceBranch,
|
String sourceBranch,
|
||||||
Set<String> labels,
|
Set<String> labels,
|
||||||
@Singular List<String> reviewers
|
@Singular List<String> reviewers,
|
||||||
|
String oldAssigneeName,
|
||||||
|
String newAssigneeName
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
title,
|
title,
|
||||||
@ -37,6 +41,8 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
labels
|
labels
|
||||||
);
|
);
|
||||||
this.reviewers = reviewers;
|
this.reviewers = reviewers;
|
||||||
|
this.oldAssigneeName = oldAssigneeName;
|
||||||
|
this.newAssigneeName = newAssigneeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,7 +17,7 @@ public class Icons {
|
|||||||
public static final String ARROW = " ➜ ";
|
public static final String ARROW = " ➜ ";
|
||||||
public static final String DANGEROUS = "⚠️";
|
public static final String DANGEROUS = "⚠️";
|
||||||
public static final String PEN = "✏️";
|
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 BUILD = "\uD83D\uDEE0";
|
||||||
public static final String LINK = "\uD83D\uDD17";
|
public static final String LINK = "\uD83D\uDD17";
|
||||||
public static final String REVIEWER = "\uD83D\uDD0E";
|
public static final String REVIEWER = "\uD83D\uDD0E";
|
||||||
|
@ -28,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
if (!mergeRequest.isConflict()) {
|
if (!mergeRequest.isConflict()) {
|
||||||
final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName();
|
final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName();
|
||||||
if (botUserReviewer) sendNotifyNewMrReview(savedMergeRequest, projectName);
|
if (botUserReviewer) sendNotifyNewMrReview(savedMergeRequest, projectName);
|
||||||
if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName);
|
if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +129,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName) {
|
private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName, String oldAssigneeName) {
|
||||||
notifyService.send(
|
final NewMrForAssignee.NewMrForAssigneeBuilder builder = NewMrForAssignee.builder()
|
||||||
NewMrForAssignee.builder()
|
|
||||||
.projectName(projectName)
|
.projectName(projectName)
|
||||||
.labels(mergeRequest.getLabels())
|
.labels(mergeRequest.getLabels())
|
||||||
.author(mergeRequest.getAuthor().getName())
|
.author(mergeRequest.getAuthor().getName())
|
||||||
@ -139,9 +139,17 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
.url(mergeRequest.getWebUrl())
|
.url(mergeRequest.getWebUrl())
|
||||||
.targetBranch(mergeRequest.getTargetBranch())
|
.targetBranch(mergeRequest.getTargetBranch())
|
||||||
.sourceBranch(mergeRequest.getSourceBranch())
|
.sourceBranch(mergeRequest.getSourceBranch())
|
||||||
.reviewers(mergeRequest.getReviewers().stream().map(Person::getName).collect(Collectors.toList()))
|
.reviewers(mergeRequest.getReviewers().stream().map(Person::getName).toList());
|
||||||
.build()
|
|
||||||
);
|
if (checkNotNull(oldAssigneeName)) {
|
||||||
|
builder.oldAssigneeName(oldAssigneeName);
|
||||||
|
|
||||||
|
if (checkNotNull(mergeRequest.getAssignee())) {
|
||||||
|
builder.newAssigneeName(mergeRequest.getAssignee().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyService.send(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -175,7 +183,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
|
|
||||||
if (isChangedLinkedEntity) {
|
if (isChangedLinkedEntity) {
|
||||||
notifyReviewer(reviewerChanged, mergeRequest, project);
|
notifyReviewer(reviewerChanged, mergeRequest, project);
|
||||||
notifyAssignee(assigneeChanged, mergeRequest, project);
|
notifyAssignee(assigneeChanged, oldMergeRequest, mergeRequest, project);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return repository.save(mergeRequest);
|
return repository.save(mergeRequest);
|
||||||
@ -184,11 +192,11 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
return oldMergeRequest;
|
return oldMergeRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление
|
//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) {
|
switch (assigneeChanged) {
|
||||||
case BECOME -> sendNotifyNewAssignee(mergeRequest, project.getName());
|
case BECOME ->
|
||||||
|
sendNotifyNewAssignee(mergeRequest, project.getName(), Optional.ofNullable(oldMergeRequest.getAssignee()).map(Person::getName).orElse(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
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.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
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.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -27,10 +26,9 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator
|
|||||||
.map(label -> "#" + label)
|
.map(label -> "#" + label)
|
||||||
.collect(Collectors.joining(" "));
|
.collect(Collectors.joining(" "));
|
||||||
|
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible*")
|
final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible*")
|
||||||
.append(Icons.HR)
|
.append(Icons.HR)
|
||||||
.append(link(notify.getType(), notify.getUrl()));
|
.append(notify.getTitle());
|
||||||
|
|
||||||
if (!labelText.isEmpty()) {
|
if (!labelText.isEmpty()) {
|
||||||
builder.append("\n\n").append(labelText);
|
builder.append("\n\n").append(labelText);
|
||||||
@ -39,16 +37,20 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator
|
|||||||
builder.append(Icons.HR);
|
builder.append(Icons.HR);
|
||||||
|
|
||||||
if (checkNotNull(notify.getProjectName())) {
|
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
|
builder
|
||||||
.append(Icons.TREE).append(": ").append(notify.getSourceBranch()).append(Icons.ARROW).append(notify.getTargetBranch()).append("\n")
|
.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<String> reviewers = notify.getReviewers();
|
final List<String> reviewers = notify.getReviewers();
|
||||||
if (checkNotEmpty(reviewers)) {
|
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();
|
final String notifyMessage = builder.toString();
|
||||||
|
@ -7,7 +7,6 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.stream.Collectors;
|
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.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
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.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -28,7 +27,7 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<N
|
|||||||
|
|
||||||
final StringBuilder builder = new StringBuilder(Icons.FUN).append(" *New merge request for review*")
|
final StringBuilder builder = new StringBuilder(Icons.FUN).append(" *New merge request for review*")
|
||||||
.append(Icons.HR)
|
.append(Icons.HR)
|
||||||
.append(link(notify.getType(), notify.getUrl()));
|
.append(notify.getTitle());
|
||||||
|
|
||||||
if (!labelText.isEmpty()) {
|
if (!labelText.isEmpty()) {
|
||||||
builder.append("\n\n").append(labelText);
|
builder.append("\n\n").append(labelText);
|
||||||
|
@ -6,8 +6,12 @@ import dev.struchkov.bot.gitlab.context.utils.Smile;
|
|||||||
import dev.struchkov.godfather.main.domain.BoxAnswer;
|
import dev.struchkov.godfather.main.domain.BoxAnswer;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
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.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.checkNotNull;
|
||||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -16,9 +20,9 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
|
|||||||
@Override
|
@Override
|
||||||
public BoxAnswer generate(UpdateMrNotify notify) {
|
public BoxAnswer generate(UpdateMrNotify notify) {
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder(Icons.UPDATE).append(" *MergeRequest update | ").append(escapeMarkdown(notify.getProjectName())).append("*")
|
final StringBuilder builder = new StringBuilder(Icons.UPDATE).append(" *MergeRequest update*")
|
||||||
.append(Smile.HR.getValue())
|
.append(Smile.HR.getValue())
|
||||||
.append(link(notify.getTitle(), notify.getUrl()));
|
.append(notify.getTitle());
|
||||||
|
|
||||||
if (notify.getAllTasks() > 0) {
|
if (notify.getAllTasks() > 0) {
|
||||||
builder.append(Smile.HR.getValue())
|
builder.append(Smile.HR.getValue())
|
||||||
@ -29,11 +33,25 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(Icons.HR)
|
builder.append(Icons.HR);
|
||||||
|
|
||||||
|
if (checkNotNull(notify.getProjectName())) {
|
||||||
|
builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
builder
|
||||||
.append(Icons.AUTHOR).append(": ").append(notify.getAuthor());
|
.append(Icons.AUTHOR).append(": ").append(notify.getAuthor());
|
||||||
|
|
||||||
final String notifyMessage = builder.toString();
|
final String notifyMessage = builder.toString();
|
||||||
return boxAnswer(notifyMessage);
|
return boxAnswer(
|
||||||
|
notifyMessage,
|
||||||
|
inlineKeyBoard(
|
||||||
|
simpleLine(
|
||||||
|
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
||||||
|
urlButton(Icons.LINK, notify.getUrl())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user