Поправил уведомление о назначении в качестве ответсвенного

This commit is contained in:
Struchkov Mark 2023-01-17 01:06:17 +03:00
parent f2bd5247ae
commit ec48b5ee1d
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
14 changed files with 173 additions and 54 deletions

View File

@ -4,14 +4,14 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public class ConflictPrNotify extends PrNotify { public class ConflictMrNotify extends MrNotify {
public static final String TYPE = "ConflictPrNotify"; public static final String TYPE = "ConflictPrNotify";
private final String sourceBranch; private final String sourceBranch;
@Builder @Builder
private ConflictPrNotify( private ConflictMrNotify(
String name, String name,
String url, String url,
String projectKey, String projectKey,

View File

@ -4,13 +4,13 @@ import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public abstract class PrNotify implements Notify { public abstract class MrNotify implements Notify {
protected final String projectName; protected final String projectName;
protected final String title; protected final String title;
protected final String url; protected final String url;
protected PrNotify( protected MrNotify(
String projectName, String projectName,
String title, String title,
String url String url

View File

@ -0,0 +1,41 @@
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
import lombok.Builder;
import lombok.Getter;
import java.util.Set;
@Getter
public class NewMrForAssignee extends NewMrNotify {
public static final String TYPE = "NewMrForAssignee";
@Builder
private NewMrForAssignee(
String title,
String url,
String description,
String author,
String projectName,
String targetBranch,
String sourceBranch,
Set<String> labels
) {
super(
title,
url,
description,
author,
projectName,
targetBranch,
sourceBranch,
labels
);
}
@Override
public String getType() {
return TYPE;
}
}

View File

@ -0,0 +1,41 @@
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
import lombok.Builder;
import lombok.Getter;
import java.util.Set;
@Getter
public class NewMrForReview extends NewMrNotify {
public static final String TYPE = "NewMrForReview";
@Builder
private NewMrForReview(
String title,
String url,
String description,
String author,
String projectName,
String targetBranch,
String sourceBranch,
Set<String> labels
) {
super(
title,
url,
description,
author,
projectName,
targetBranch,
sourceBranch,
labels
);
}
@Override
public String getType() {
return TYPE;
}
}

View File

@ -1,23 +1,19 @@
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest; package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import java.util.Set; import java.util.Set;
@Getter @Getter
public class NewPrNotify extends PrNotify { public abstract class NewMrNotify extends MrNotify {
public static final String TYPE = "NewPrNotify"; protected final String description;
protected final String author;
protected final String targetBranch;
protected final String sourceBranch;
protected final Set<String> labels;
private final String description; protected NewMrNotify(
private final String author;
private final String targetBranch;
private final String sourceBranch;
private final Set<String> labels;
@Builder
private NewPrNotify(
String title, String title,
String url, String url,
String description, String description,
@ -35,9 +31,4 @@ public class NewPrNotify extends PrNotify {
this.labels = labels; this.labels = labels;
} }
@Override
public String getType() {
return TYPE;
}
} }

View File

@ -5,7 +5,7 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public class StatusPrNotify extends PrNotify { public class StatusMrNotify extends MrNotify {
public static final String TYPE = "StatusPrNotify"; public static final String TYPE = "StatusPrNotify";
@ -13,7 +13,7 @@ public class StatusPrNotify extends PrNotify {
private final MergeRequestState newStatus; private final MergeRequestState newStatus;
@Builder @Builder
private StatusPrNotify( private StatusMrNotify(
String name, String name,
String url, String url,
String projectName, String projectName,

View File

@ -4,7 +4,7 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public class UpdatePrNotify extends PrNotify { public class UpdateMrNotify extends MrNotify {
public static final String TYPE = "UpdatePrNotify"; public static final String TYPE = "UpdatePrNotify";
@ -15,7 +15,7 @@ public class UpdatePrNotify extends PrNotify {
private final Long personResolvedTasks; private final Long personResolvedTasks;
@Builder @Builder
private UpdatePrNotify( private UpdateMrNotify(
String name, String name,
String url, String url,
String author, String author,

View File

@ -17,6 +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 BUILD = "\uD83D\uDEE0"; public static final String BUILD = "\uD83D\uDEE0";
public static final String LINK = "\uD83D\uDD17"; public static final String LINK = "\uD83D\uDD17";

View File

@ -11,10 +11,11 @@ import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion;
import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.entity.Person;
import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.entity.Project;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrNotify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForAssignee;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForReview;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdatePrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrNotify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrNotify;
import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository; import dev.struchkov.bot.gitlab.context.repository.MergeRequestRepository;
import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.DiscussionService;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService; import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
@ -67,7 +68,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
if (botUserReviewer || botUserAssignee) { if (botUserReviewer || botUserAssignee) {
if (!mergeRequest.isConflict()) { if (!mergeRequest.isConflict()) {
final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName(); final String projectName = projectService.getByIdOrThrow(savedMergeRequest.getProjectId()).getName();
if (botUserReviewer) sendNotifyAboutNewMr(savedMergeRequest, projectName); if (botUserReviewer) sendNotifyNewMrReview(savedMergeRequest, projectName);
if (botUserAssignee) sendNotifyAboutAssignee(mergeRequest, projectName); if (botUserAssignee) sendNotifyAboutAssignee(mergeRequest, projectName);
} }
} }
@ -111,9 +112,9 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
return false; return false;
} }
private void sendNotifyAboutNewMr(MergeRequest mergeRequest, String projectName) { private void sendNotifyNewMrReview(MergeRequest mergeRequest, String projectName) {
notifyService.send( notifyService.send(
NewPrNotify.builder() NewMrForReview.builder()
.projectName(projectName) .projectName(projectName)
.labels(mergeRequest.getLabels()) .labels(mergeRequest.getLabels())
.author(mergeRequest.getAuthor().getName()) .author(mergeRequest.getAuthor().getName())
@ -128,7 +129,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
private void sendNotifyAboutAssignee(MergeRequest mergeRequest, String projectName) { private void sendNotifyAboutAssignee(MergeRequest mergeRequest, String projectName) {
notifyService.send( notifyService.send(
NewPrNotify.builder() NewMrForAssignee.builder()
.projectName(projectName) .projectName(projectName)
.labels(mergeRequest.getLabels()) .labels(mergeRequest.getLabels())
.author(mergeRequest.getAuthor().getName()) .author(mergeRequest.getAuthor().getName())
@ -185,15 +186,14 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
//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 mergeRequest, Project project) {
switch (assigneeChanged) { switch (assigneeChanged) {
case BECOME -> sendNotifyAboutNewMr(mergeRequest, project.getName()); case BECOME -> sendNotifyAboutAssignee(mergeRequest, project.getName());
} }
} }
//TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление ревьювера //TODO [05.12.2022|uPagge]: Добавить уведомление, если происходит удаление ревьювера
//TODO [05.12.2022|uPagge]: Заменить тип уведомления на самостоятельный
private void notifyReviewer(ReviewerChanged reviewerChanged, MergeRequest mergeRequest, Project project) { private void notifyReviewer(ReviewerChanged reviewerChanged, MergeRequest mergeRequest, Project project) {
switch (reviewerChanged) { switch (reviewerChanged) {
case BECOME -> sendNotifyAboutNewMr(mergeRequest, project.getName()); case BECOME -> sendNotifyNewMrReview(mergeRequest, project.getName());
} }
} }
@ -284,7 +284,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
} }
} }
notifyService.send( notifyService.send(
UpdatePrNotify.builder() UpdateMrNotify.builder()
.author(oldMergeRequest.getAuthor().getName()) .author(oldMergeRequest.getAuthor().getName())
.name(oldMergeRequest.getTitle()) .name(oldMergeRequest.getTitle())
.projectKey(project.getName()) .projectKey(project.getName())
@ -306,7 +306,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
&& gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // и MR создан пользователем бота && gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // и MR создан пользователем бота
) { ) {
notifyService.send( notifyService.send(
ConflictPrNotify.builder() ConflictMrNotify.builder()
.sourceBranch(oldMergeRequest.getSourceBranch()) .sourceBranch(oldMergeRequest.getSourceBranch())
.name(mergeRequest.getTitle()) .name(mergeRequest.getTitle())
.url(mergeRequest.getWebUrl()) .url(mergeRequest.getWebUrl())
@ -325,7 +325,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
&& gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // создатель MR является пользователем бота && gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // создатель MR является пользователем бота
) { ) {
notifyService.send( notifyService.send(
StatusPrNotify.builder() StatusMrNotify.builder()
.name(newMergeRequest.getTitle()) .name(newMergeRequest.getTitle())
.url(oldMergeRequest.getWebUrl()) .url(oldMergeRequest.getWebUrl())
.projectName(project.getName()) .projectName(project.getName())

View File

@ -1,6 +1,6 @@
package dev.struchkov.bot.gitlab.telegram.service.notify; package dev.struchkov.bot.gitlab.telegram.service.notify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrNotify;
import dev.struchkov.bot.gitlab.context.utils.Icons; 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;
@ -10,10 +10,10 @@ import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@Component @Component
public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator<ConflictPrNotify> { public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator<ConflictMrNotify> {
@Override @Override
public BoxAnswer generate(ConflictPrNotify notify) { public BoxAnswer generate(ConflictMrNotify notify) {
final StringBuilder builder = new StringBuilder(Icons.DANGEROUS).append(" *Attention! MergeRequest conflict | ").append(escapeMarkdown(notify.getProjectName())).append("*") final StringBuilder builder = new StringBuilder(Icons.DANGEROUS).append(" *Attention! MergeRequest conflict | ").append(escapeMarkdown(notify.getProjectName())).append("*")
.append(Icons.HR) .append(Icons.HR)
@ -25,7 +25,7 @@ public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator<Confl
@Override @Override
public String getNotifyType() { public String getNotifyType() {
return ConflictPrNotify.TYPE; return ConflictMrNotify.TYPE;
} }
} }

View File

@ -0,0 +1,45 @@
package dev.struchkov.bot.gitlab.telegram.service.notify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForAssignee;
import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.godfather.main.domain.BoxAnswer;
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.haiti.utils.Strings.escapeMarkdown;
@Component
public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator<NewMrForAssignee> {
@Override
public BoxAnswer generate(NewMrForAssignee notify) {
final String labelText = notify.getLabels().stream()
.map(label -> "#" + label)
.collect(Collectors.joining(" "));
final StringBuilder builder = new StringBuilder(Icons.ASSIGNEE).append(" *You have become responsible | ").append(escapeMarkdown(notify.getProjectName())).append("*")
.append(Icons.HR)
.append(link(notify.getType(), notify.getUrl()));
if (!labelText.isEmpty()) {
builder.append("\n\n").append(labelText);
}
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());
final String notifyMessage = builder.toString();
return boxAnswer(notifyMessage);
}
@Override
public String getNotifyType() {
return NewMrForAssignee.TYPE;
}
}

View File

@ -1,6 +1,6 @@
package dev.struchkov.bot.gitlab.telegram.service.notify; package dev.struchkov.bot.gitlab.telegram.service.notify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForReview;
import dev.struchkov.bot.gitlab.context.utils.Icons; 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;
@ -12,10 +12,10 @@ import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@Component @Component
public class NewPrNotifyGenerator implements NotifyBoxAnswerGenerator<NewPrNotify> { public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<NewMrForReview> {
@Override @Override
public BoxAnswer generate(NewPrNotify notify) { public BoxAnswer generate(NewMrForReview notify) {
final String labelText = notify.getLabels().stream() final String labelText = notify.getLabels().stream()
.map(label -> "#" + label) .map(label -> "#" + label)
.collect(Collectors.joining(" ")); .collect(Collectors.joining(" "));
@ -39,7 +39,7 @@ public class NewPrNotifyGenerator implements NotifyBoxAnswerGenerator<NewPrNotif
@Override @Override
public String getNotifyType() { public String getNotifyType() {
return NewPrNotify.TYPE; return NewMrForReview.TYPE;
} }
} }

View File

@ -1,6 +1,6 @@
package dev.struchkov.bot.gitlab.telegram.service.notify; package dev.struchkov.bot.gitlab.telegram.service.notify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusPrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrNotify;
import dev.struchkov.bot.gitlab.context.utils.Icons; 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;
@ -9,10 +9,10 @@ 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;
@Component @Component
public class StatusPrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusPrNotify> { public class StatusPrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusMrNotify> {
@Override @Override
public BoxAnswer generate(StatusPrNotify notify) { public BoxAnswer generate(StatusMrNotify notify) {
final StringBuilder builder = new StringBuilder(Icons.PEN).append(" *MergeRequest status changed | ").append(notify.getProjectName()).append("*") final StringBuilder builder = new StringBuilder(Icons.PEN).append(" *MergeRequest status changed | ").append(notify.getProjectName()).append("*")
.append(Icons.HR) .append(Icons.HR)
@ -27,7 +27,7 @@ public class StatusPrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusP
@Override @Override
public String getNotifyType() { public String getNotifyType() {
return StatusPrNotify.TYPE; return StatusMrNotify.TYPE;
} }
} }

View File

@ -1,6 +1,6 @@
package dev.struchkov.bot.gitlab.telegram.service.notify; package dev.struchkov.bot.gitlab.telegram.service.notify;
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdatePrNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrNotify;
import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.bot.gitlab.context.utils.Icons;
import dev.struchkov.bot.gitlab.context.utils.Smile; import dev.struchkov.bot.gitlab.context.utils.Smile;
import dev.struchkov.godfather.main.domain.BoxAnswer; import dev.struchkov.godfather.main.domain.BoxAnswer;
@ -11,10 +11,10 @@ import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@Component @Component
public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdatePrNotify> { public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateMrNotify> {
@Override @Override
public BoxAnswer generate(UpdatePrNotify 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(escapeMarkdown(notify.getProjectName())).append("*")
.append(Smile.HR.getValue()) .append(Smile.HR.getValue())
@ -38,7 +38,7 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateP
@Override @Override
public String getNotifyType() { public String getNotifyType() {
return UpdatePrNotify.TYPE; return UpdateMrNotify.TYPE;
} }
} }