From 936490de2346f1f2713d36034095f9ab18f7b972 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 3 Sep 2024 22:51:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D1=85=20=D1=83=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../context/domain/entity/MergeRequest.java | 4 ++ .../context/domain/entity/PersonTelegram.java | 31 +++++++++ .../context/domain/notify/GroupNotify.java | 5 ++ .../context/domain/notify/PersonalNotify.java | 5 ++ ...ify.java => NewCommentPersonalNotify.java} | 6 +- .../NewMergeRequestGroupPersonalNotify.java | 49 ++++++++++++++ ...a => ApprovalChangedMrPersonalNotify.java} | 7 +- ...ify.java => ConflictMrPersonalNotify.java} | 6 +- ...a => ConflictResolveMrPersonalNotify.java} | 6 +- .../{MrNotify.java => MrPersonalNotify.java} | 6 +- .../notify/mergerequest/NewMrForAssignee.java | 2 +- .../notify/mergerequest/NewMrForReview.java | 2 +- ...MrNotify.java => NewMrPersonalNotify.java} | 4 +- ...otify.java => StatusMrPersonalNotify.java} | 6 +- ...otify.java => UpdateMrPersonalNotify.java} | 6 +- ...otify.java => PipelinePersonalNotify.java} | 8 +-- ...ify.java => NewProjectPersonalNotify.java} | 8 +-- ....java => DiscussionNewPersonalNotify.java} | 6 +- ...fy.java => ThreadClosePersonalNotify.java} | 6 +- ...dNotify.java => ThreadPersonalNotify.java} | 6 +- .../context/prop/GroupNotifyProperty.java | 15 +++++ .../context/repository/PersonRepository.java | 3 + .../context/service/MessageSendService.java | 8 ++- .../gitlab/context/service/NotifyService.java | 9 ++- .../gitlab/context/service/PersonService.java | 5 +- .../core/handler/DiscussionHandler.java | 14 ++-- .../core/handler/MergeRequestHandler.java | 54 ++++++++++----- .../gitlab/core/handler/PipelineHandler.java | 26 +++++++- .../gitlab/core/handler/ProjectHandler.java | 4 +- .../gitlab/core/parser/PipelineParser.java | 4 +- .../core/service/NotifyServiceImpl.java | 19 +++++- .../core/service/PersonServiceImpl.java | 13 ++-- .../core/service/PipelineServiceImpl.java | 8 +-- .../data/impl/PersonRepositoryImpl.java | 8 +++ .../data/jpa/PersonTelegramRepository.java | 8 +++ .../bot/gitlab/config/AppConfig.java | 7 ++ gitlab-app/src/main/resources/application.yml | 3 + .../v.2.0.0/2024-09-03-add-group-notify.xml | 35 ++++++++++ .../resources/liquibase/v.2.0.0/changelog.xml | 1 + pom.xml | 2 +- .../service/MessageSendTelegramService.java | 31 ++++++++- .../gitlab/telegram/service/StartNotify.java | 2 + .../ApprovalChangedMrNotifyGenerator.java | 8 +-- .../notify/ConflictPrNotifyGenerator.java | 8 +-- .../ConflictResolvePrNotifyGenerator.java | 8 +-- .../notify/NewCommentNotifyGenerator.java | 8 +-- .../notify/NewProjectNotifyGenerator.java | 8 +-- .../notify/NewThreadNotifyGenerator.java | 8 +-- .../notify/NotifyBoxAnswerGenerator.java | 4 +- .../notify/PipelineNotifyGenerator.java | 8 +-- .../notify/StatusMrNotifyGenerator.java | 8 +-- .../notify/ThreadCloseNotifyGenerate.java | 8 +-- .../notify/UpdateMrNotifyGenerator.java | 8 +-- .../NewMergeRequestGroupNotifyGenerator.java | 65 +++++++++++++++++++ 54 files changed, 469 insertions(+), 138 deletions(-) create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/PersonTelegram.java create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GroupNotify.java create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/PersonalNotify.java rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/{NewCommentNotify.java => NewCommentPersonalNotify.java} (89%) create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/group/mr/NewMergeRequestGroupPersonalNotify.java rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{ApprovalChangedMrNotify.java => ApprovalChangedMrPersonalNotify.java} (84%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{ConflictMrNotify.java => ConflictMrPersonalNotify.java} (82%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{ConflictResolveMrNotify.java => ConflictResolveMrPersonalNotify.java} (80%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{MrNotify.java => MrPersonalNotify.java} (77%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{NewMrNotify.java => NewMrPersonalNotify.java} (89%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{StatusMrNotify.java => StatusMrPersonalNotify.java} (86%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/{UpdateMrNotify.java => UpdateMrPersonalNotify.java} (89%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/{PipelineNotify.java => PipelinePersonalNotify.java} (84%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/{NewProjectNotify.java => NewProjectPersonalNotify.java} (84%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/{DiscussionNewNotify.java => DiscussionNewPersonalNotify.java} (86%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/{ThreadCloseNotify.java => ThreadClosePersonalNotify.java} (87%) rename bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/{ThreadNotify.java => ThreadPersonalNotify.java} (75%) create mode 100644 bot-context/src/main/java/dev/struchkov/bot/gitlab/context/prop/GroupNotifyProperty.java create mode 100644 bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/PersonTelegramRepository.java create mode 100644 gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-09-03-add-group-notify.xml create mode 100644 telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/group/NewMergeRequestGroupNotifyGenerator.java diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java index 4f8d43a..e8073d7 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/MergeRequest.java @@ -24,6 +24,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import java.time.LocalDateTime; import java.util.ArrayList; @@ -39,6 +40,7 @@ import java.util.Set; @Getter @Setter @Entity +@ToString(onlyExplicitlyIncluded = true) @NoArgsConstructor @Builder(toBuilder = true) @Table(name = "merge_request") @@ -48,6 +50,7 @@ import java.util.Set; public class MergeRequest { @Id + @ToString.Include @Column(name = "id") @EqualsAndHashCode.Include private Long id; @@ -58,6 +61,7 @@ public class MergeRequest { @Column(name = "project_id") private Long projectId; + @ToString.Include @Column(name = "title") private String title; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/PersonTelegram.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/PersonTelegram.java new file mode 100644 index 0000000..0de7b76 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/PersonTelegram.java @@ -0,0 +1,31 @@ +package dev.struchkov.bot.gitlab.context.domain.entity; + +import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; +import dev.struchkov.haiti.utils.fieldconstants.domain.Mode; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Entity +@Getter +@Setter +@ToString +@Table(name = "person_telegram") +@FieldNames(mode = {Mode.TABLE, Mode.SIMPLE}) +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class PersonTelegram { + + @Id + @EqualsAndHashCode.Include + @Column(name = "id") + private Long id; + + @Column(name = "telegram_username") + private String telegramUserName; + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GroupNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GroupNotify.java new file mode 100644 index 0000000..9371cbb --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/GroupNotify.java @@ -0,0 +1,5 @@ +package dev.struchkov.bot.gitlab.context.domain.notify; + +public interface GroupNotify extends Notify { + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/PersonalNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/PersonalNotify.java new file mode 100644 index 0000000..3606c02 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/PersonalNotify.java @@ -0,0 +1,5 @@ +package dev.struchkov.bot.gitlab.context.domain.notify; + +public interface PersonalNotify extends Notify{ + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentPersonalNotify.java similarity index 89% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentPersonalNotify.java index 151cda1..d00830b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/comment/NewCommentPersonalNotify.java @@ -1,13 +1,13 @@ package dev.struchkov.bot.gitlab.context.domain.notify.comment; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; @Getter @FieldNames -public final class NewCommentNotify implements Notify { +public final class NewCommentPersonalNotify implements PersonalNotify { public static final String TYPE = "NewCommentNotify"; @@ -23,7 +23,7 @@ public final class NewCommentNotify implements Notify { private final int numberNotes; @Builder - public NewCommentNotify( + public NewCommentPersonalNotify( String threadId, String mergeRequestName, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/group/mr/NewMergeRequestGroupPersonalNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/group/mr/NewMergeRequestGroupPersonalNotify.java new file mode 100644 index 0000000..9ba6c77 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/group/mr/NewMergeRequestGroupPersonalNotify.java @@ -0,0 +1,49 @@ +package dev.struchkov.bot.gitlab.context.domain.notify.group.mr; + +import dev.struchkov.bot.gitlab.context.domain.entity.Person; +import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify; +import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; +import lombok.Builder; +import lombok.Getter; + +import java.util.Map; + +@Getter +@FieldNames +public class NewMergeRequestGroupPersonalNotify implements GroupNotify { + + public static final String TYPE = "NewMergeRequestGroupNotify"; + + protected final Long mrId; + protected final String projectName; + protected final String title; + protected final String url; + protected final String milestone; + protected final String description; + protected final String author; + protected final String targetBranch; + protected final String sourceBranch; + protected final Map reviewerTelegramUsernames; + protected final Person assignee; + + @Builder + public NewMergeRequestGroupPersonalNotify(Long mrId, String projectName, String title, String url, String milestone, String description, String author, String targetBranch, String sourceBranch, Map reviewerTelegramUsernames, Person assignee) { + this.mrId = mrId; + this.projectName = projectName; + this.title = title; + this.url = url; + this.milestone = milestone; + this.description = description; + this.author = author; + this.targetBranch = targetBranch; + this.sourceBranch = sourceBranch; + this.reviewerTelegramUsernames = reviewerTelegramUsernames; + this.assignee = assignee; + } + + @Override + public String getType() { + return TYPE; + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrPersonalNotify.java similarity index 84% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrPersonalNotify.java index 01488c4..f75399c 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ApprovalChangedMrPersonalNotify.java @@ -7,11 +7,12 @@ import lombok.Getter; import java.util.Set; -import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrPersonalNotifyFields.CLASS_NAME; + @Getter @FieldNames -public class ApprovalChangedMrNotify extends MrNotify { +public class ApprovalChangedMrPersonalNotify extends MrPersonalNotify { public static final String TYPE = CLASS_NAME; @@ -19,7 +20,7 @@ public class ApprovalChangedMrNotify extends MrNotify { private final Set dontApproval; @Builder - public ApprovalChangedMrNotify( + public ApprovalChangedMrPersonalNotify( Long mrId, String projectName, String title, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrPersonalNotify.java similarity index 82% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrPersonalNotify.java index 4dd42cc..5a998b3 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictMrPersonalNotify.java @@ -4,18 +4,18 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrPersonalNotifyFields.CLASS_NAME; @Getter @FieldNames -public class ConflictMrNotify extends MrNotify { +public class ConflictMrPersonalNotify extends MrPersonalNotify { public static final String TYPE = CLASS_NAME; private final String sourceBranch; @Builder - private ConflictMrNotify( + private ConflictMrPersonalNotify( Long mrId, String name, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrPersonalNotify.java similarity index 80% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrPersonalNotify.java index 2a0c129..1c4c76b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/ConflictResolveMrPersonalNotify.java @@ -4,18 +4,18 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrPersonalNotifyFields.CLASS_NAME; @Getter @FieldNames -public class ConflictResolveMrNotify extends MrNotify { +public class ConflictResolveMrPersonalNotify extends MrPersonalNotify { public static final String TYPE = CLASS_NAME; private final String sourceBranch; @Builder - private ConflictResolveMrNotify( + private ConflictResolveMrPersonalNotify( Long mrId, String name, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrPersonalNotify.java similarity index 77% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrPersonalNotify.java index d4c7f0c..ecab47b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/MrPersonalNotify.java @@ -1,10 +1,10 @@ package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import lombok.Getter; @Getter -public abstract class MrNotify implements Notify { +public abstract class MrPersonalNotify implements PersonalNotify { protected final Long mrId; protected final String projectName; @@ -12,7 +12,7 @@ public abstract class MrNotify implements Notify { protected final String url; protected final String milestone; - protected MrNotify( + protected MrPersonalNotify( Long mrId, String projectName, String title, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java index 3a22ebc..c7fb715 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForAssignee.java @@ -12,7 +12,7 @@ import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrF @Getter @FieldNames -public class NewMrForAssignee extends NewMrNotify { +public class NewMrForAssignee extends NewMrPersonalNotify { public static final String TYPE = CLASS_NAME; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java index fe79ebe..3b9282b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrForReview.java @@ -10,7 +10,7 @@ import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrF @Getter @FieldNames -public class NewMrForReview extends NewMrNotify { +public class NewMrForReview extends NewMrPersonalNotify { public static final String TYPE = CLASS_NAME; diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrPersonalNotify.java similarity index 89% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrPersonalNotify.java index 2183231..cd56f08 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/NewMrPersonalNotify.java @@ -5,7 +5,7 @@ import lombok.Getter; import java.util.Set; @Getter -public abstract class NewMrNotify extends MrNotify { +public abstract class NewMrPersonalNotify extends MrPersonalNotify { protected final String description; protected final String author; @@ -13,7 +13,7 @@ public abstract class NewMrNotify extends MrNotify { protected final String sourceBranch; protected final Set labels; - protected NewMrNotify( + protected NewMrPersonalNotify( Long mrId, String title, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrPersonalNotify.java similarity index 86% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrPersonalNotify.java index 22c80d4..38c4536 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/StatusMrPersonalNotify.java @@ -5,11 +5,11 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrPersonalNotifyFields.CLASS_NAME; @Getter @FieldNames -public class StatusMrNotify extends MrNotify { +public class StatusMrPersonalNotify extends MrPersonalNotify { public static final String TYPE = CLASS_NAME; @@ -17,7 +17,7 @@ public class StatusMrNotify extends MrNotify { private final MergeRequestState newStatus; @Builder - private StatusMrNotify( + private StatusMrPersonalNotify( Long mrId, String name, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrPersonalNotify.java similarity index 89% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrPersonalNotify.java index 61ec84f..761e469 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/mergerequest/UpdateMrPersonalNotify.java @@ -4,11 +4,11 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrPersonalNotifyFields.CLASS_NAME; @Getter @FieldNames -public class UpdateMrNotify extends MrNotify { +public class UpdateMrPersonalNotify extends MrPersonalNotify { public static final String TYPE = CLASS_NAME; @@ -20,7 +20,7 @@ public class UpdateMrNotify extends MrNotify { private final String comment; @Builder - private UpdateMrNotify( + private UpdateMrPersonalNotify( Long mrId, String name, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelinePersonalNotify.java similarity index 84% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelinePersonalNotify.java index c619e76..d7cdf5b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelineNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/pipeline/PipelinePersonalNotify.java @@ -1,12 +1,12 @@ package dev.struchkov.bot.gitlab.context.domain.notify.pipeline; import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelinePersonalNotifyFields.CLASS_NAME; /** * @author upagge 17.01.2021 @@ -14,7 +14,7 @@ import static dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNo //TODO [16.12.2022|uPagge]: Нужно реализовать заполнение projectName @Getter @FieldNames -public final class PipelineNotify implements Notify { +public final class PipelinePersonalNotify implements PersonalNotify { public static final String TYPE = CLASS_NAME; @@ -26,7 +26,7 @@ public final class PipelineNotify implements Notify { private final String webUrl; @Builder - public PipelineNotify( + public PipelinePersonalNotify( Long projectId, Long pipelineId, String refName, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectPersonalNotify.java similarity index 84% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectPersonalNotify.java index a91ac95..4964135 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/project/NewProjectPersonalNotify.java @@ -1,18 +1,18 @@ package dev.struchkov.bot.gitlab.context.domain.notify.project; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectPersonalNotifyFields.CLASS_NAME; /** * @author upagge 15.01.2021 */ @Getter @FieldNames -public final class NewProjectNotify implements Notify { +public final class NewProjectPersonalNotify implements PersonalNotify { public static final String TYPE = CLASS_NAME; @@ -25,7 +25,7 @@ public final class NewProjectNotify implements Notify { private final String httpUrlToRepo; @Builder - public NewProjectNotify( + public NewProjectPersonalNotify( Long projectId, String projectName, String projectUrl, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewPersonalNotify.java similarity index 86% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewPersonalNotify.java index 882c1a3..97023f2 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/DiscussionNewPersonalNotify.java @@ -8,14 +8,14 @@ import lombok.Singular; import java.util.List; -import static dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewPersonalNotifyFields.CLASS_NAME; /** * @author upagge 10.09.2020 */ @Getter @FieldNames -public class DiscussionNewNotify extends ThreadNotify { +public class DiscussionNewPersonalNotify extends ThreadPersonalNotify { public static final String TYPE = CLASS_NAME; @@ -23,7 +23,7 @@ public class DiscussionNewNotify extends ThreadNotify { private final List> notes; @Builder - public DiscussionNewNotify( + public DiscussionNewPersonalNotify( String threadId, String mergeRequestName, String authorName, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadCloseNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadClosePersonalNotify.java similarity index 87% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadCloseNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadClosePersonalNotify.java index 8565182..94832a9 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadCloseNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadClosePersonalNotify.java @@ -4,14 +4,14 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import lombok.Builder; import lombok.Getter; -import static dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadCloseNotifyFields.CLASS_NAME; +import static dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadClosePersonalNotifyFields.CLASS_NAME; /** * @author upagge 10.09.2020 */ @Getter @FieldNames -public class ThreadCloseNotify extends ThreadNotify { +public class ThreadClosePersonalNotify extends ThreadPersonalNotify { public static final String TYPE = CLASS_NAME; @@ -21,7 +21,7 @@ public class ThreadCloseNotify extends ThreadNotify { private final String messageLastNote; @Builder - protected ThreadCloseNotify( + protected ThreadClosePersonalNotify( String mergeRequestName, String authorName, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadNotify.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadPersonalNotify.java similarity index 75% rename from bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadNotify.java rename to bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadPersonalNotify.java index c8d34d2..f8c8ece 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadNotify.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/notify/task/ThreadPersonalNotify.java @@ -1,17 +1,17 @@ package dev.struchkov.bot.gitlab.context.domain.notify.task; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import lombok.Getter; @Getter -public abstract class ThreadNotify implements Notify { +public abstract class ThreadPersonalNotify implements PersonalNotify { protected final String mergeRequestName; protected final String authorName; protected final String url; protected final String messageTask; - protected ThreadNotify( + protected ThreadPersonalNotify( String mergeRequestName, String authorName, String url, diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/prop/GroupNotifyProperty.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/prop/GroupNotifyProperty.java new file mode 100644 index 0000000..71966b7 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/prop/GroupNotifyProperty.java @@ -0,0 +1,15 @@ +package dev.struchkov.bot.gitlab.context.prop; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Optional; + +@Getter +@Setter +public class GroupNotifyProperty { + + private Optional chatId; + private Optional threadId; + +} diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java index 1cbe322..33c0834 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/PersonRepository.java @@ -1,6 +1,7 @@ package dev.struchkov.bot.gitlab.context.repository; import dev.struchkov.bot.gitlab.context.domain.entity.Person; +import dev.struchkov.bot.gitlab.context.domain.entity.PersonTelegram; import java.util.List; import java.util.Optional; @@ -17,4 +18,6 @@ public interface PersonRepository { List findAllById(Set personIds); + List getAllTelegramInfoByIds(Set personIds); + } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MessageSendService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MessageSendService.java index a9a6982..b26ba83 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MessageSendService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MessageSendService.java @@ -1,11 +1,13 @@ package dev.struchkov.bot.gitlab.context.service; +import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; import lombok.NonNull; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; -@FunctionalInterface public interface MessageSendService { - void send(@NonNull Notify notify); + void send(@NonNull PersonalNotify notify); + + void send(@NonNull GroupNotify notify); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NotifyService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NotifyService.java index 25ce24a..51678be 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NotifyService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/NotifyService.java @@ -1,15 +1,18 @@ package dev.struchkov.bot.gitlab.context.service; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; /** * Сервис по работе с изменениями в битбакете. * * @author upagge - * @see Notify + * @see PersonalNotify */ public interface NotifyService { - void send(T notify); + void send(T notify); + + void send(T notify); } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java index 0aa4d7a..ff9d882 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/PersonService.java @@ -5,6 +5,7 @@ import dev.struchkov.bot.gitlab.context.domain.entity.Person; import lombok.NonNull; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -14,12 +15,12 @@ public interface PersonService { Person create(@NonNull Person person); - Person update(@NonNull Person person); - Person getByIdOrThrown(@NonNull Long personId); ExistContainer existsById(Set personIds); List createAll(List newPersons); + Map getTelegramUsernamesByPersonIds(Set personIds); + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/DiscussionHandler.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/DiscussionHandler.java index 8b31335..9a5902f 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/DiscussionHandler.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/DiscussionHandler.java @@ -6,10 +6,10 @@ import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequestForDiscussion; import dev.struchkov.bot.gitlab.context.domain.entity.Note; import dev.struchkov.bot.gitlab.context.domain.event.NewDiscussionEvent; import dev.struchkov.bot.gitlab.context.domain.event.UpdateDiscussionEvent; -import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentPersonalNotify; import dev.struchkov.bot.gitlab.context.domain.notify.level.DiscussionLevel; -import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotify; -import dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadCloseNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewPersonalNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadClosePersonalNotify; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.NotifyService; @@ -100,7 +100,7 @@ public class DiscussionHandler { final Note firstNote = discussion.getFirstNote(); final MergeRequestForDiscussion mergeRequest = discussion.getMergeRequest(); - final DiscussionNewNotify.DiscussionNewNotifyBuilder messageBuilder = DiscussionNewNotify.builder() + final DiscussionNewPersonalNotify.DiscussionNewPersonalNotifyBuilder messageBuilder = DiscussionNewPersonalNotify.builder() .url(firstNote.getWebUrl()) .threadId(discussion.getId()) .mergeRequestName(mergeRequest.getTitle()) @@ -150,7 +150,7 @@ public class DiscussionHandler { } if (recipientsLogins.contains(personInformation.getUsername())) { - final NewCommentNotify.NewCommentNotifyBuilder notifyBuilder = NewCommentNotify.builder() + final NewCommentPersonalNotify.NewCommentPersonalNotifyBuilder notifyBuilder = NewCommentPersonalNotify.builder() .threadId(discussion.getId()) .mergeRequestName(discussion.getMergeRequest().getTitle()) .url(note.getWebUrl()); @@ -186,7 +186,7 @@ public class DiscussionHandler { && !personInformation.getId().equals(note.getAuthor().getId())) { final Note firstNote = discussion.getFirstNote(); - final NewCommentNotify.NewCommentNotifyBuilder notifyBuilder = NewCommentNotify.builder() + final NewCommentPersonalNotify.NewCommentPersonalNotifyBuilder notifyBuilder = NewCommentPersonalNotify.builder() .threadId(discussion.getId()) .url(note.getWebUrl()) .mergeRequestName(discussion.getMergeRequest().getTitle()); @@ -229,7 +229,7 @@ public class DiscussionHandler { .filter(discussion -> personInformation.getId().equals(discussion.getFirstNote().getAuthor().getId()) && discussion.getResolved()) .count(); - final ThreadCloseNotify.ThreadCloseNotifyBuilder notifyBuilder = ThreadCloseNotify.builder() + final ThreadClosePersonalNotify.ThreadClosePersonalNotifyBuilder notifyBuilder = ThreadClosePersonalNotify.builder() .mergeRequestName(mergeRequest.getTitle()) .url(oldNote.getWebUrl()) .personTasks(allYouTasks) diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/MergeRequestHandler.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/MergeRequestHandler.java index c91a5ad..56de03e 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/MergeRequestHandler.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/MergeRequestHandler.java @@ -11,21 +11,24 @@ 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.event.NewMergeRequestEvent; import dev.struchkov.bot.gitlab.context.domain.event.UpdateMergeRequestEvent; -import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrNotify; -import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrNotify; -import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupPersonalNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrPersonalNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrPersonalNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrPersonalNotify; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForAssignee; import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForReview; -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.domain.notify.mergerequest.StatusMrPersonalNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrPersonalNotify; import dev.struchkov.bot.gitlab.context.service.DiscussionService; import dev.struchkov.bot.gitlab.context.service.NotifyService; +import dev.struchkov.bot.gitlab.context.service.PersonService; import dev.struchkov.bot.gitlab.context.service.ProjectService; import lombok.RequiredArgsConstructor; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -41,6 +44,7 @@ public class MergeRequestHandler { private final NotifyService notifyService; + private final PersonService personService; private final PersonInformation personInformation; private final ProjectService projectService; private final DiscussionService discussionService; @@ -52,12 +56,32 @@ public class MergeRequestHandler { final boolean userReviewer = mergeRequest.isUserReviewer(); final boolean userAssignee = mergeRequest.isUserAssignee(); - if (userReviewer || userAssignee) { - if (!mergeRequest.isConflict()) { - - if (userReviewer) sendNotifyNewMrReview(mergeRequest, projectName); - if (userAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null); + if (!mergeRequest.isConflict()) { + if (mergeRequest.isNotification()) { + if (userReviewer || userAssignee) { + if (userReviewer) sendNotifyNewMrReview(mergeRequest, projectName); + if (userAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null); + } } + final Map reviewerTelegramUsernames = personService.getTelegramUsernamesByPersonIds(mergeRequest.getReviewers().stream().map(Person::getId).collect(Collectors.toSet())); + if (!reviewerTelegramUsernames.isEmpty()) { + notifyService.send( + NewMergeRequestGroupPersonalNotify.builder() + .mrId(mergeRequest.getId()) + .title(mergeRequest.getTitle()) + .url(mergeRequest.getWebUrl()) + .author(mergeRequest.getAuthor().getName()) + .reviewerTelegramUsernames(reviewerTelegramUsernames) + .milestone(mergeRequest.getMilestone()) + .projectName(projectName) + .targetBranch(mergeRequest.getTargetBranch()) + .sourceBranch(mergeRequest.getSourceBranch()) + .description(mergeRequest.getDescription()) + .build() + ); + } + } else { + //TODO [03.09.2024|uPagge]: Уведомление о конфликте } } @@ -107,7 +131,7 @@ public class MergeRequestHandler { if (checkNotEmpty(newApproval) || checkNotEmpty(dontApproval)) { notifyService.send( - ApprovalChangedMrNotify.builder() + ApprovalChangedMrPersonalNotify.builder() .mrId(mergeRequest.getId()) .milestone(mergeRequest.getMilestone()) .projectName(project.getName()) @@ -196,7 +220,7 @@ public class MergeRequestHandler { } } - final UpdateMrNotify.UpdateMrNotifyBuilder notifyBuilder = UpdateMrNotify.builder() + final UpdateMrPersonalNotify.UpdateMrPersonalNotifyBuilder notifyBuilder = UpdateMrPersonalNotify.builder() .mrId(oldMergeRequest.getId()) .author(oldMergeRequest.getAuthor().getName()) .name(oldMergeRequest.getTitle()) @@ -224,7 +248,7 @@ public class MergeRequestHandler { && gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // и MR создан пользователем бота ) { notifyService.send( - ConflictMrNotify.builder() + ConflictMrPersonalNotify.builder() .mrId(oldMergeRequest.getId()) .sourceBranch(oldMergeRequest.getSourceBranch()) .name(mergeRequest.getTitle()) @@ -245,7 +269,7 @@ public class MergeRequestHandler { } else { if (gitlabUserId.equals(oldMergeRequest.getAuthor().getId())) { notifyService.send( - ConflictResolveMrNotify.builder() + ConflictResolveMrPersonalNotify.builder() .mrId(oldMergeRequest.getId()) .sourceBranch(oldMergeRequest.getSourceBranch()) .name(mergeRequest.getTitle()) @@ -268,7 +292,7 @@ public class MergeRequestHandler { && gitlabUserId.equals(oldMergeRequest.getAuthor().getId()) // создатель MR является пользователем бота ) { notifyService.send( - StatusMrNotify.builder() + StatusMrPersonalNotify.builder() .mrId(oldMergeRequest.getId()) .name(newMergeRequest.getTitle()) .url(oldMergeRequest.getWebUrl()) diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/PipelineHandler.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/PipelineHandler.java index 0d6af53..92d20ef 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/PipelineHandler.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/PipelineHandler.java @@ -5,7 +5,8 @@ import dev.struchkov.bot.gitlab.context.domain.PipelineStatus; import dev.struchkov.bot.gitlab.context.domain.entity.Person; import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline; import dev.struchkov.bot.gitlab.context.domain.event.NewPipelineEvent; -import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotify; +import dev.struchkov.bot.gitlab.context.domain.event.UpdatePipelineEvent; +import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelinePersonalNotify; import dev.struchkov.bot.gitlab.context.service.NotifyService; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -13,6 +14,7 @@ import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; import java.time.LocalDateTime; +import java.util.Objects; import java.util.Set; import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.CANCELED; @@ -36,7 +38,7 @@ public class PipelineHandler { final Pipeline pipeline = event.getPipeline(); if (isNeedNotifyNewPipeline(pipeline)) { notifyService.send( - PipelineNotify.builder() + PipelinePersonalNotify.builder() .projectId(pipeline.getProjectId()) .newStatus(pipeline.getStatus()) .pipelineId(pipeline.getId()) @@ -48,6 +50,26 @@ public class PipelineHandler { } } + @EventListener + public void updatePipelineHandle(UpdatePipelineEvent event) { + final Pipeline oldPipeline = event.getOldPipeline(); + final Pipeline newPipeline = event.getNewPipeline(); + if (!Objects.equals(oldPipeline.getUpdated(), newPipeline.getUpdated())) { + if (isNeedNotifyNewPipeline(newPipeline)) { + notifyService.send( + PipelinePersonalNotify.builder() + .projectId(newPipeline.getProjectId()) + .newStatus(newPipeline.getStatus()) + .pipelineId(newPipeline.getId()) + .refName(newPipeline.getRef()) + .webUrl(newPipeline.getWebUrl()) + .oldStatus(oldPipeline.getStatus()) + .build() + ); + } + } + } + private boolean isNeedNotifyNewPipeline(@NonNull Pipeline pipeline) { final Person personPipelineCreator = pipeline.getPerson(); return notificationStatus.contains(pipeline.getStatus()) // Пайплайн имеет статус необходимый для уведомления diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/ProjectHandler.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/ProjectHandler.java index 4f8c858..7e33a16 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/ProjectHandler.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/handler/ProjectHandler.java @@ -2,7 +2,7 @@ package dev.struchkov.bot.gitlab.core.handler; import dev.struchkov.bot.gitlab.context.domain.entity.Project; import dev.struchkov.bot.gitlab.context.domain.event.NewProjectEvent; -import dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.project.NewProjectPersonalNotify; import dev.struchkov.bot.gitlab.context.service.NotifyService; import dev.struchkov.bot.gitlab.context.service.PersonService; import lombok.RequiredArgsConstructor; @@ -21,7 +21,7 @@ public class ProjectHandler { final Project newProject = event.getProject(); final String authorName = personService.getByIdOrThrown(newProject.getCreatorId()).getName(); notifyService.send( - NewProjectNotify.builder() + NewProjectPersonalNotify.builder() .projectId(newProject.getId()) .projectDescription(newProject.getDescription()) .projectName(newProject.getName()) diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/parser/PipelineParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/parser/PipelineParser.java index 6f6f770..c38739f 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/parser/PipelineParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/parser/PipelineParser.java @@ -40,7 +40,7 @@ import static java.util.stream.Collectors.toSet; @RequiredArgsConstructor public class PipelineParser { - private static final Set oldStatus = Set.of( + private static final Set oldSOLD_STATUSES = Set.of( CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL ); @@ -91,7 +91,7 @@ public class PipelineParser { public void scanOldPipeline() { log.debug("Старт обработки старых пайплайнов"); - final List pipelines = pipelineService.getAllByStatuses(oldStatus); + final List pipelines = pipelineService.getAllByStatuses(oldSOLD_STATUSES); final List newPipelines = gitlabSdkManager.getAllPipelineForProject( pipelines.stream() diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/NotifyServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/NotifyServiceImpl.java index d228c22..21ac714 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/NotifyServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/NotifyServiceImpl.java @@ -1,6 +1,8 @@ package dev.struchkov.bot.gitlab.core.service; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; +import dev.struchkov.bot.gitlab.context.prop.GroupNotifyProperty; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.service.MessageSendService; import dev.struchkov.bot.gitlab.context.service.NotifyService; @@ -10,22 +12,33 @@ import org.springframework.stereotype.Service; @Service public class NotifyServiceImpl implements NotifyService { + private final GroupNotifyProperty groupNotifyProperty; private final MessageSendService messageSendService; private final AppSettingService settingService; public NotifyServiceImpl( - @Lazy MessageSendService messageSendService, + GroupNotifyProperty groupNotifyProperty, @Lazy MessageSendService messageSendService, AppSettingService settingService ) { + this.groupNotifyProperty = groupNotifyProperty; this.messageSendService = messageSendService; this.settingService = settingService; } @Override - public void send(T notify) { + public void send(T notify) { if (settingService.isEnableAllNotify()) { messageSendService.send(notify); } } + @Override + public void send(T notify) { + if (settingService.isEnableAllNotify()) { + if (groupNotifyProperty.getChatId().isPresent()) { + messageSendService.send(notify); + } + } + } + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PersonServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PersonServiceImpl.java index 3ea260c..96b0df7 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PersonServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PersonServiceImpl.java @@ -2,6 +2,7 @@ package dev.struchkov.bot.gitlab.core.service; import dev.struchkov.bot.gitlab.context.domain.ExistContainer; import dev.struchkov.bot.gitlab.context.domain.entity.Person; +import dev.struchkov.bot.gitlab.context.domain.entity.PersonTelegram; import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.context.service.PersonService; import lombok.NonNull; @@ -10,6 +11,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -29,11 +31,6 @@ public class PersonServiceImpl implements PersonService { return repository.save(person); } - @Override - public Person update(@NonNull Person person) { - return repository.save(person); - } - @Override @Transactional(readOnly = true) public Person getByIdOrThrown(@NonNull Long personId) { @@ -64,4 +61,10 @@ public class PersonServiceImpl implements PersonService { .toList(); } + @Override + public Map getTelegramUsernamesByPersonIds(Set personIds) { + return repository.getAllTelegramInfoByIds(personIds).stream() + .collect(Collectors.toMap(PersonTelegram::getId, PersonTelegram::getTelegramUserName)); + } + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PipelineServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PipelineServiceImpl.java index 42089cc..4cbb749 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PipelineServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/PipelineServiceImpl.java @@ -58,12 +58,8 @@ public class PipelineServiceImpl implements PipelineService { pipeline.setProjectId(oldPipeline.getProjectId()); - if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) { - eventPublisher.publishEvent(updatePipeline(oldPipeline.toBuilder().build(), pipeline)); - return repository.save(pipeline); - } - - return oldPipeline; + eventPublisher.publishEvent(updatePipeline(oldPipeline.toBuilder().build(), pipeline)); + return repository.save(pipeline); } @Override diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java index ad830b6..13d6889 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/PersonRepositoryImpl.java @@ -1,8 +1,10 @@ package dev.struchkov.bot.gitlab.data.impl; import dev.struchkov.bot.gitlab.context.domain.entity.Person; +import dev.struchkov.bot.gitlab.context.domain.entity.PersonTelegram; import dev.struchkov.bot.gitlab.context.repository.PersonRepository; import dev.struchkov.bot.gitlab.data.jpa.PersonJpaRepository; +import dev.struchkov.bot.gitlab.data.jpa.PersonTelegramRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -18,6 +20,7 @@ import java.util.Set; public class PersonRepositoryImpl implements PersonRepository { private final PersonJpaRepository jpaRepository; + private final PersonTelegramRepository jpaTelegramRepository; @Override public Person save(Person person) { @@ -34,4 +37,9 @@ public class PersonRepositoryImpl implements PersonRepository { return jpaRepository.findAllById(personIds); } + @Override + public List getAllTelegramInfoByIds(Set personIds) { + return jpaTelegramRepository.findAllById(personIds); + } + } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/PersonTelegramRepository.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/PersonTelegramRepository.java new file mode 100644 index 0000000..f6f9d7f --- /dev/null +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/PersonTelegramRepository.java @@ -0,0 +1,8 @@ +package dev.struchkov.bot.gitlab.data.jpa; + +import dev.struchkov.bot.gitlab.context.domain.entity.PersonTelegram; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PersonTelegramRepository extends JpaRepository { + +} diff --git a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java index 71708fc..fb2c89a 100644 --- a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java +++ b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java @@ -2,6 +2,7 @@ package dev.struchkov.bot.gitlab.config; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.prop.AppProperty; +import dev.struchkov.bot.gitlab.context.prop.GroupNotifyProperty; import dev.struchkov.bot.gitlab.context.prop.PersonProperty; import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; @@ -73,6 +74,12 @@ public class AppConfig { return new PersonProperty(); } + @Bean + @ConfigurationProperties(prefix = "gitlab-bot.group-notify") + public GroupNotifyProperty groupNotifyProperty() { + return new GroupNotifyProperty(); + } + @Bean("parserPool") public ForkJoinPool parserPool() { return new ForkJoinPool(4); diff --git a/gitlab-app/src/main/resources/application.yml b/gitlab-app/src/main/resources/application.yml index 94cd7ef..6ff5903 100644 --- a/gitlab-app/src/main/resources/application.yml +++ b/gitlab-app/src/main/resources/application.yml @@ -45,6 +45,9 @@ gitlab-bot: new-merge-request: ${CRON_NEW_MR:0 */15 * * * *} person: telegram-id: ${TELEGRAM_PERSON_ID} + group-notify: + chat-id: "-1002233809566" + thread-id: "2" gitlab-sdk: access-token: ${GITLAB_PERSONAL_TOKEN} base-url: ${GITLAB_URL} diff --git a/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-09-03-add-group-notify.xml b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-09-03-add-group-notify.xml new file mode 100644 index 0000000..4e2e0f7 --- /dev/null +++ b/gitlab-app/src/main/resources/liquibase/v.2.0.0/2024-09-03-add-group-notify.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml b/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml index 26c582a..35cb564 100644 --- a/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml +++ b/gitlab-app/src/main/resources/liquibase/v.2.0.0/changelog.xml @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index da32763..82844ef 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ UTF-8 UTF-8 - 1.0.0 + 1.0.1-SNAPSHOT 3.0.3 1.1.1 diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java index f185440..085a3bc 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -1,7 +1,9 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; -import dev.struchkov.bot.gitlab.context.domain.notify.Notify; +import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.PersonalNotify; +import dev.struchkov.bot.gitlab.context.prop.GroupNotifyProperty; import dev.struchkov.bot.gitlab.context.service.MessageSendService; import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator; import dev.struchkov.godfather.simple.domain.BoxAnswer; @@ -16,6 +18,8 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.THREAD_ID; + /** * Отправляет сообщение в телеграмм. * @@ -29,19 +33,21 @@ public class MessageSendTelegramService implements MessageSendService { private final TelegramSending sending; private final PersonInformation personInformation; + private final GroupNotifyProperty groupNotifyProperty; public MessageSendTelegramService( List generators, TelegramSending sending, - PersonInformation personInformation + PersonInformation personInformation, GroupNotifyProperty groupNotifyProperty ) { this.generatorMap = generators.stream().collect(Collectors.toMap(NotifyBoxAnswerGenerator::getNotifyType, n -> n)); this.sending = sending; this.personInformation = personInformation; + this.groupNotifyProperty = groupNotifyProperty; } @Override - public void send(@NonNull Notify notify) { + public void send(@NonNull PersonalNotify notify) { getGenerator(notify.getType()) .map(generator -> { final BoxAnswer answer = generator.generate(notify); @@ -53,6 +59,25 @@ public class MessageSendTelegramService implements MessageSendService { .ifPresent(sending::send); } + @Override + public void send(@NonNull GroupNotify notify) { + final Optional optChatId = groupNotifyProperty.getChatId(); + if (optChatId.isPresent()) { + final String chatId = optChatId.get(); + getGenerator(notify.getType()) + .map(generator -> { + final BoxAnswer answer = generator.generate(notify); + answer.setRecipientPersonId(chatId); + groupNotifyProperty.getThreadId().ifPresent( + threadId -> answer.addPayload(THREAD_ID, threadId) + ); + log.debug("Будет отправлено следующее уведомление: {}. Текст: {}", answer, answer.getMessage()); + return answer; + }).ifPresent(sending::send); + } + + } + private Optional getGenerator(String notifyType) { return Optional.ofNullable(generatorMap.get(notifyType)); } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java index f49f080..60d7c24 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/StartNotify.java @@ -1,6 +1,7 @@ package dev.struchkov.bot.gitlab.telegram.service; import dev.struchkov.bot.gitlab.context.prop.AppProperty; +import dev.struchkov.bot.gitlab.context.prop.GroupNotifyProperty; import dev.struchkov.bot.gitlab.context.prop.PersonProperty; import dev.struchkov.bot.gitlab.context.service.AppSettingService; import dev.struchkov.bot.gitlab.context.utils.Icons; @@ -35,6 +36,7 @@ public class StartNotify { private final AppProperty appProperty; private final AppSettingService settingService; private final PersonProperty personProperty; + private final GroupNotifyProperty groupNotifyProperty; @PostConstruct public void sendStartNotification() { diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ApprovalChangedMrNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ApprovalChangedMrNotifyGenerator.java index 4218d32..3b834c4 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ApprovalChangedMrNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ApprovalChangedMrNotifyGenerator.java @@ -1,7 +1,7 @@ package dev.struchkov.bot.gitlab.telegram.service.notify; import dev.struchkov.bot.gitlab.context.domain.entity.Person; -import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrPersonalNotify; import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.godfather.simple.domain.BoxAnswer; import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload; @@ -25,10 +25,10 @@ import static java.util.stream.Collectors.joining; @Component @RequiredArgsConstructor -public class ApprovalChangedMrNotifyGenerator implements NotifyBoxAnswerGenerator { +public class ApprovalChangedMrNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(ApprovalChangedMrNotify notify) { + public BoxAnswer generate(ApprovalChangedMrPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.APPROVAL).append(" *Approvals changed*") .append(Icons.HR) .append(escapeMarkdown(notify.getTitle())); @@ -77,7 +77,7 @@ public class ApprovalChangedMrNotifyGenerator implements NotifyBoxAnswerGenerato @Override public String getNotifyType() { - return ApprovalChangedMrNotify.TYPE; + return ApprovalChangedMrPersonalNotify.TYPE; } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java index 4066383..518fa3c 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/ConflictPrNotifyGenerator.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.telegram.service.notify; -import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrPersonalNotify; import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.godfather.simple.domain.BoxAnswer; import org.springframework.stereotype.Component; @@ -18,10 +18,10 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @Component -public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator { +public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(ConflictMrNotify notify) { + public BoxAnswer generate(ConflictMrPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.DANGEROUS).append(" *Attention. MergeRequest conflict!*") .append(Icons.HR) @@ -53,7 +53,7 @@ public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator { +public class ConflictResolvePrNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(ConflictResolveMrNotify notify) { + public BoxAnswer generate(ConflictResolveMrPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.GREEN_CIRCLE).append(" *Merge request conflict resolved!*") .append(Icons.HR) @@ -53,7 +53,7 @@ public class ConflictResolvePrNotifyGenerator implements NotifyBoxAnswerGenerato @Override public String getNotifyType() { - return ConflictResolveMrNotify.TYPE; + return ConflictResolveMrPersonalNotify.TYPE; } } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java index dd075db..578759d 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.telegram.service.notify; -import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentPersonalNotify; import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.godfather.simple.domain.BoxAnswer; import lombok.RequiredArgsConstructor; @@ -20,10 +20,10 @@ import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @Component @RequiredArgsConstructor -public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator { +public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(NewCommentNotify notify) { + public BoxAnswer generate(NewCommentPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.COMMENT).append(" *New answer in Thread*"); if (checkNotBlank(notify.getDiscussionMessage()) || checkNotNull(notify.getPreviousMessage()) || checkNotNull(notify.getMessage())) { @@ -65,7 +65,7 @@ public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator { +public class NewProjectNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(NewProjectNotify notify) { + public BoxAnswer generate(NewProjectPersonalNotify notify) { final Optional optDescription = Optional.ofNullable(notify.getProjectDescription()) .filter(Checker::checkNotBlank) .map(Strings::escapeMarkdown); @@ -61,7 +61,7 @@ public class NewProjectNotifyGenerator implements NotifyBoxAnswerGenerator { +public class NewThreadNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(DiscussionNewNotify notify) { + public BoxAnswer generate(DiscussionNewPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.THREAD).append(" *New Thread in your MR*"); if (checkNotBlank(notify.getMessageTask())) { @@ -69,7 +69,7 @@ public class NewThreadNotifyGenerator implements NotifyBoxAnswerGenerator { +public interface NotifyBoxAnswerGenerator { BoxAnswer generate(T notify); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java index 044df42..73254c7 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/PipelineNotifyGenerator.java @@ -1,6 +1,6 @@ package dev.struchkov.bot.gitlab.telegram.service.notify; -import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotify; +import dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelinePersonalNotify; import dev.struchkov.bot.gitlab.context.service.ProjectService; import dev.struchkov.bot.gitlab.context.utils.Icons; import dev.struchkov.godfather.simple.domain.BoxAnswer; @@ -19,12 +19,12 @@ import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENA @Service @RequiredArgsConstructor -public class PipelineNotifyGenerator implements NotifyBoxAnswerGenerator { +public class PipelineNotifyGenerator implements NotifyBoxAnswerGenerator { private final ProjectService projectService; @Override - public BoxAnswer generate(PipelineNotify notify) { + public BoxAnswer generate(PipelinePersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.BUILD).append(" *New pipeline | ").append(notify.getPipelineId()).append("*"); builder @@ -58,7 +58,7 @@ public class PipelineNotifyGenerator implements NotifyBoxAnswerGenerator { +public class StatusMrNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(StatusMrNotify notify) { + public BoxAnswer generate(StatusMrPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.PEN).append(" *MergeRequest status changed*") .append(Icons.HR) @@ -50,7 +50,7 @@ public class StatusMrNotifyGenerator implements NotifyBoxAnswerGenerator { +public class ThreadCloseNotifyGenerate implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(ThreadCloseNotify notify) { + public BoxAnswer generate(ThreadClosePersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.THREAD).append(" *Closed thread*") .append("\n-- -- -- merge request -- -- --\n") @@ -50,7 +50,7 @@ public class ThreadCloseNotifyGenerate implements NotifyBoxAnswerGenerator { +public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator { @Override - public BoxAnswer generate(UpdateMrNotify notify) { + public BoxAnswer generate(UpdateMrPersonalNotify notify) { final StringBuilder builder = new StringBuilder(Icons.UPDATE).append(" *MergeRequest update*") .append(Icons.HR) @@ -71,7 +71,7 @@ public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator { + + @Override + public BoxAnswer generate(NewMergeRequestGroupPersonalNotify notify) { + final String reviewerUsernames = String.join(", ", notify.getReviewerTelegramUsernames().values()); + final StringBuilder builder = new StringBuilder(Icons.FUN) + .append("*You are reviewers:* ").append(reviewerUsernames) + .append(Icons.HR) + .append(escapeMarkdown(notify.getTitle())); + + builder.append(Icons.HR); + + if (checkNotNull(notify.getProjectName())) { + builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n"); + } + + if (checkNotNull(notify.getMilestone())) { + builder.append(Icons.MILESTONE).append(": ").append(notify.getMilestone()).append("\n"); + } + + builder + .append(Icons.TREE).append(": ").append(escapeMarkdown(notify.getSourceBranch())).append(Icons.ARROW).append(escapeMarkdown(notify.getTargetBranch())).append("\n") + .append(Icons.AUTHOR).append(": ").append(notify.getAuthor()).append("\n"); + + if (checkNotNull(notify.getAssignee())) { + builder.append(Icons.ASSIGNEE).append(": ").append(notify.getAssignee()); + } + + final String notifyMessage = builder.toString(); + + return BoxAnswer.builder() + .message(notifyMessage) + .keyBoard(inlineKeyBoard( + keyBoardLine( + urlButton(Icons.LINK, notify.getUrl()) + ) + )) + .payload(ENABLE_MARKDOWN) + .build(); + } + + @Override + public String getNotifyType() { + return NewMergeRequestGroupPersonalNotify.TYPE; + } + +}