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.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Singular;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -10,6 +12,10 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
|
|
||||||
public static final String TYPE = "NewMrForAssignee";
|
public static final String TYPE = "NewMrForAssignee";
|
||||||
|
|
||||||
|
private final List<String> reviewers;
|
||||||
|
private final String oldAssigneeName;
|
||||||
|
private final String newAssigneeName;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewMrForAssignee(
|
private NewMrForAssignee(
|
||||||
String title,
|
String title,
|
||||||
@ -19,7 +25,10 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
String projectName,
|
String projectName,
|
||||||
String targetBranch,
|
String targetBranch,
|
||||||
String sourceBranch,
|
String sourceBranch,
|
||||||
Set<String> labels
|
Set<String> labels,
|
||||||
|
@Singular List<String> reviewers,
|
||||||
|
String oldAssigneeName,
|
||||||
|
String newAssigneeName
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
title,
|
title,
|
||||||
@ -31,6 +40,9 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
sourceBranch,
|
sourceBranch,
|
||||||
labels
|
labels
|
||||||
);
|
);
|
||||||
|
this.reviewers = reviewers;
|
||||||
|
this.oldAssigneeName = oldAssigneeName;
|
||||||
|
this.newAssigneeName = newAssigneeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,6 +10,8 @@ public class NewMrForReview extends NewMrNotify {
|
|||||||
|
|
||||||
public static final String TYPE = "NewMrForReview";
|
public static final String TYPE = "NewMrForReview";
|
||||||
|
|
||||||
|
private final String assignee;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewMrForReview(
|
private NewMrForReview(
|
||||||
String title,
|
String title,
|
||||||
@ -19,7 +21,8 @@ public class NewMrForReview extends NewMrNotify {
|
|||||||
String projectName,
|
String projectName,
|
||||||
String targetBranch,
|
String targetBranch,
|
||||||
String sourceBranch,
|
String sourceBranch,
|
||||||
Set<String> labels
|
Set<String> labels,
|
||||||
|
String assignee
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
title,
|
title,
|
||||||
@ -31,6 +34,7 @@ public class NewMrForReview extends NewMrNotify {
|
|||||||
sourceBranch,
|
sourceBranch,
|
||||||
labels
|
labels
|
||||||
);
|
);
|
||||||
|
this.assignee = assignee;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,9 +17,11 @@ 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 PROJECT = "Project";
|
||||||
|
|
||||||
private Icons() {
|
private Icons() {
|
||||||
utilityClass();
|
utilityClass();
|
||||||
|
@ -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) sendNotifyAboutAssignee(mergeRequest, projectName);
|
if (botUserAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,23 +124,32 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
.url(mergeRequest.getWebUrl())
|
.url(mergeRequest.getWebUrl())
|
||||||
.targetBranch(mergeRequest.getTargetBranch())
|
.targetBranch(mergeRequest.getTargetBranch())
|
||||||
.sourceBranch(mergeRequest.getSourceBranch())
|
.sourceBranch(mergeRequest.getSourceBranch())
|
||||||
|
.assignee(mergeRequest.getAssignee().getName())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotifyAboutAssignee(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())
|
.description(mergeRequest.getDescription())
|
||||||
.description(mergeRequest.getDescription())
|
.title(mergeRequest.getTitle())
|
||||||
.title(mergeRequest.getTitle())
|
.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).toList());
|
||||||
.build()
|
|
||||||
);
|
if (checkNotNull(oldAssigneeName)) {
|
||||||
|
builder.oldAssigneeName(oldAssigneeName);
|
||||||
|
|
||||||
|
if (checkNotNull(mergeRequest.getAssignee())) {
|
||||||
|
builder.newAssigneeName(mergeRequest.getAssignee().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyService.send(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -173,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);
|
||||||
@ -182,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 -> 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 dev.struchkov.godfather.main.domain.BoxAnswer;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
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.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;
|
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -20,21 +26,44 @@ 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(escapeMarkdown(notify.getProjectName())).append("*")
|
|
||||||
.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.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();
|
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
|
||||||
|
@ -7,8 +7,12 @@ 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.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
|
||||||
@ -21,20 +25,38 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<N
|
|||||||
.collect(Collectors.joining(" "));
|
.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(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.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());
|
||||||
|
|
||||||
|
if (checkNotNull(notify.getAssignee())) {
|
||||||
|
builder.append(Icons.ASSIGNEE).append(": ").append(notify.getAssignee());
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -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