Compare commits

..

No commits in common. "b530c061f341118bc029efb3be09e5cd0d20536c" and "b6fd20cd05a7e2779a65cf8d02bda9ef07b710b9" have entirely different histories.

7 changed files with 38 additions and 135 deletions

View File

@ -2,9 +2,7 @@ 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
@ -12,10 +10,6 @@ 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,
@ -25,10 +19,7 @@ public class NewMrForAssignee extends NewMrNotify {
String projectName,
String targetBranch,
String sourceBranch,
Set<String> labels,
@Singular List<String> reviewers,
String oldAssigneeName,
String newAssigneeName
Set<String> labels
) {
super(
title,
@ -40,9 +31,6 @@ public class NewMrForAssignee extends NewMrNotify {
sourceBranch,
labels
);
this.reviewers = reviewers;
this.oldAssigneeName = oldAssigneeName;
this.newAssigneeName = newAssigneeName;
}
@Override

View File

@ -10,8 +10,6 @@ public class NewMrForReview extends NewMrNotify {
public static final String TYPE = "NewMrForReview";
private final String assignee;
@Builder
private NewMrForReview(
String title,
@ -21,8 +19,7 @@ public class NewMrForReview extends NewMrNotify {
String projectName,
String targetBranch,
String sourceBranch,
Set<String> labels,
String assignee
Set<String> labels
) {
super(
title,
@ -34,7 +31,6 @@ public class NewMrForReview extends NewMrNotify {
sourceBranch,
labels
);
this.assignee = assignee;
}
@Override

View File

@ -17,11 +17,9 @@ public class Icons {
public static final String ARROW = "";
public static final String DANGEROUS = "⚠️";
public static final String PEN = "✏️";
public static final String ASSIGNEE = "\uD83C\uDFA9";
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";
public static final String PROJECT = "Project";
private Icons() {
utilityClass();

View File

@ -28,7 +28,6 @@ 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;
@ -70,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) sendNotifyNewAssignee(mergeRequest, projectName, null);
if (botUserAssignee) sendNotifyAboutAssignee(mergeRequest, projectName);
}
}
@ -124,32 +123,23 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
.url(mergeRequest.getWebUrl())
.targetBranch(mergeRequest.getTargetBranch())
.sourceBranch(mergeRequest.getSourceBranch())
.assignee(mergeRequest.getAssignee().getName())
.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());
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()
);
}
@Override
@ -183,7 +173,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
if (isChangedLinkedEntity) {
notifyReviewer(reviewerChanged, mergeRequest, project);
notifyAssignee(assigneeChanged, oldMergeRequest, mergeRequest, project);
notifyAssignee(assigneeChanged, mergeRequest, project);
}
}
return repository.save(mergeRequest);
@ -192,11 +182,11 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
return oldMergeRequest;
}
//TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление
private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
private void notifyAssignee(AssigneeChanged assigneeChanged, MergeRequest mergeRequest, Project project) {
switch (assigneeChanged) {
case BECOME ->
sendNotifyNewAssignee(mergeRequest, project.getName(), Optional.ofNullable(oldMergeRequest.getAssignee()).map(Person::getName).orElse(null));
case BECOME -> sendNotifyAboutAssignee(mergeRequest, project.getName());
}
}

View File

@ -5,16 +5,10 @@ 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
@ -26,44 +20,21 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator
.map(label -> "#" + label)
.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(notify.getTitle());
.append(link(notify.getType(), notify.getUrl()));
if (!labelText.isEmpty()) {
builder.append("\n\n").append(labelText);
}
builder.append(Icons.HR);
if (checkNotNull(notify.getProjectName())) {
builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n");
}
builder
builder.append(Icons.HR)
.append(Icons.TREE).append(": ").append(notify.getSourceBranch()).append(Icons.ARROW).append(notify.getTargetBranch()).append("\n")
.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");
}
.append(Icons.AUTHOR).append(": ").append(notify.getAuthor());
final String notifyMessage = builder.toString();
return boxAnswer(
notifyMessage,
inlineKeyBoard(
simpleLine(
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
urlButton(Icons.LINK, notify.getUrl())
)
)
);
return boxAnswer(notifyMessage);
}
@Override

View File

@ -7,12 +7,8 @@ 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
@ -25,38 +21,20 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<N
.collect(Collectors.joining(" "));
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(escapeMarkdown(notify.getProjectName())).append("*")
.append(Icons.HR)
.append(notify.getTitle());
.append(link(notify.getType(), notify.getUrl()));
if (!labelText.isEmpty()) {
builder.append("\n\n").append(labelText);
}
builder.append(Icons.HR);
if (checkNotNull(notify.getProjectName())) {
builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName()));
}
builder
builder.append(Icons.HR)
.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,
inlineKeyBoard(
simpleLine(
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
urlButton(Icons.LINK, notify.getUrl())
)
)
);
return boxAnswer(notifyMessage);
}
@Override

View File

@ -6,12 +6,8 @@ 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
@ -20,9 +16,9 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
@Override
public BoxAnswer generate(UpdateMrNotify notify) {
final StringBuilder builder = new StringBuilder(Icons.UPDATE).append(" *MergeRequest update*")
final StringBuilder builder = new StringBuilder(Icons.UPDATE).append(" *MergeRequest update | ").append(escapeMarkdown(notify.getProjectName())).append("*")
.append(Smile.HR.getValue())
.append(notify.getTitle());
.append(link(notify.getTitle(), notify.getUrl()));
if (notify.getAllTasks() > 0) {
builder.append(Smile.HR.getValue())
@ -33,25 +29,11 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
}
}
builder.append(Icons.HR);
if (checkNotNull(notify.getProjectName())) {
builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n");
}
builder
builder.append(Icons.HR)
.append(Icons.AUTHOR).append(": ").append(notify.getAuthor());
final String notifyMessage = builder.toString();
return boxAnswer(
notifyMessage,
inlineKeyBoard(
simpleLine(
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
urlButton(Icons.LINK, notify.getUrl())
)
)
);
return boxAnswer(notifyMessage);
}
@Override