Compare commits
4 Commits
b6fd20cd05
...
b530c061f3
Author | SHA1 | Date | |
---|---|---|---|
b530c061f3 | |||
aee809304a | |||
ea65a98778 | |||
3fd2aa717d |
@ -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,10 @@ public class NewMrForAssignee extends NewMrNotify {
|
||||
|
||||
public static final String TYPE = "NewMrForAssignee";
|
||||
|
||||
private final List<String> reviewers;
|
||||
private final String oldAssigneeName;
|
||||
private final String newAssigneeName;
|
||||
|
||||
@Builder
|
||||
private NewMrForAssignee(
|
||||
String title,
|
||||
@ -19,7 +25,10 @@ public class NewMrForAssignee extends NewMrNotify {
|
||||
String projectName,
|
||||
String targetBranch,
|
||||
String sourceBranch,
|
||||
Set<String> labels
|
||||
Set<String> labels,
|
||||
@Singular List<String> reviewers,
|
||||
String oldAssigneeName,
|
||||
String newAssigneeName
|
||||
) {
|
||||
super(
|
||||
title,
|
||||
@ -31,6 +40,9 @@ public class NewMrForAssignee extends NewMrNotify {
|
||||
sourceBranch,
|
||||
labels
|
||||
);
|
||||
this.reviewers = reviewers;
|
||||
this.oldAssigneeName = oldAssigneeName;
|
||||
this.newAssigneeName = newAssigneeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,8 @@ public class NewMrForReview extends NewMrNotify {
|
||||
|
||||
public static final String TYPE = "NewMrForReview";
|
||||
|
||||
private final String assignee;
|
||||
|
||||
@Builder
|
||||
private NewMrForReview(
|
||||
String title,
|
||||
@ -19,7 +21,8 @@ public class NewMrForReview extends NewMrNotify {
|
||||
String projectName,
|
||||
String targetBranch,
|
||||
String sourceBranch,
|
||||
Set<String> labels
|
||||
Set<String> labels,
|
||||
String assignee
|
||||
) {
|
||||
super(
|
||||
title,
|
||||
@ -31,6 +34,7 @@ public class NewMrForReview extends NewMrNotify {
|
||||
sourceBranch,
|
||||
labels
|
||||
);
|
||||
this.assignee = assignee;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,9 +17,11 @@ 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";
|
||||
public static final String PROJECT = "Project";
|
||||
|
||||
private Icons() {
|
||||
utilityClass();
|
||||
|
@ -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) sendNotifyAboutAssignee(mergeRequest, projectName);
|
||||
if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,23 +124,32 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
||||
.url(mergeRequest.getWebUrl())
|
||||
.targetBranch(mergeRequest.getTargetBranch())
|
||||
.sourceBranch(mergeRequest.getSourceBranch())
|
||||
.assignee(mergeRequest.getAssignee().getName())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void sendNotifyAboutAssignee(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())
|
||||
.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
|
||||
@ -173,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);
|
||||
@ -182,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 -> sendNotifyAboutAssignee(mergeRequest, project.getName());
|
||||
case BECOME ->
|
||||
sendNotifyNewAssignee(mergeRequest, project.getName(), Optional.ofNullable(oldMergeRequest.getAssignee()).map(Person::getName).orElse(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,10 +5,16 @@ 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
|
||||
@ -20,21 +26,44 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator
|
||||
.map(label -> "#" + label)
|
||||
.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()));
|
||||
.append(notify.getTitle());
|
||||
|
||||
if (!labelText.isEmpty()) {
|
||||
builder.append("\n\n").append(labelText);
|
||||
}
|
||||
|
||||
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.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();
|
||||
if (checkNotEmpty(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();
|
||||
return boxAnswer(notifyMessage);
|
||||
|
||||
return boxAnswer(
|
||||
notifyMessage,
|
||||
inlineKeyBoard(
|
||||
simpleLine(
|
||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
||||
urlButton(Icons.LINK, notify.getUrl())
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,8 +7,12 @@ 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;
|
||||
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;
|
||||
|
||||
@Component
|
||||
@ -21,20 +25,38 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<N
|
||||
.collect(Collectors.joining(" "));
|
||||
|
||||
|
||||
final StringBuilder builder = new StringBuilder(Icons.FUN).append(" *New merge request for review | ").append(escapeMarkdown(notify.getProjectName())).append("*")
|
||||
final StringBuilder builder = new StringBuilder(Icons.FUN).append(" *New merge request for review*")
|
||||
.append(Icons.HR)
|
||||
.append(link(notify.getType(), notify.getUrl()));
|
||||
.append(notify.getTitle());
|
||||
|
||||
if (!labelText.isEmpty()) {
|
||||
builder.append("\n\n").append(labelText);
|
||||
}
|
||||
|
||||
builder.append(Icons.HR)
|
||||
builder.append(Icons.HR);
|
||||
|
||||
if (checkNotNull(notify.getProjectName())) {
|
||||
builder.append(Icons.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());
|
||||
|
||||
if (checkNotNull(notify.getAssignee())) {
|
||||
builder.append(Icons.ASSIGNEE).append(": ").append(notify.getAssignee());
|
||||
}
|
||||
|
||||
final String notifyMessage = builder.toString();
|
||||
return boxAnswer(notifyMessage);
|
||||
return boxAnswer(
|
||||
notifyMessage,
|
||||
inlineKeyBoard(
|
||||
simpleLine(
|
||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
||||
urlButton(Icons.LINK, notify.getUrl())
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,8 +6,12 @@ import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import dev.struchkov.godfather.main.domain.BoxAnswer;
|
||||
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.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;
|
||||
|
||||
@Component
|
||||
@ -16,9 +20,9 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
|
||||
@Override
|
||||
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(link(notify.getTitle(), notify.getUrl()));
|
||||
.append(notify.getTitle());
|
||||
|
||||
if (notify.getAllTasks() > 0) {
|
||||
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());
|
||||
|
||||
final String notifyMessage = builder.toString();
|
||||
return boxAnswer(notifyMessage);
|
||||
return boxAnswer(
|
||||
notifyMessage,
|
||||
inlineKeyBoard(
|
||||
simpleLine(
|
||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
||||
urlButton(Icons.LINK, notify.getUrl())
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user