Первая версия групповых уведомлений
This commit is contained in:
parent
c11a3148be
commit
936490de23
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify;
|
||||
|
||||
public interface GroupNotify extends Notify {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify;
|
||||
|
||||
public interface PersonalNotify extends Notify{
|
||||
|
||||
}
|
@ -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,
|
@ -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<Long, String> 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<Long, String> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<Person> dontApproval;
|
||||
|
||||
@Builder
|
||||
public ApprovalChangedMrNotify(
|
||||
public ApprovalChangedMrPersonalNotify(
|
||||
Long mrId,
|
||||
String projectName,
|
||||
String title,
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<String> labels;
|
||||
|
||||
protected NewMrNotify(
|
||||
protected NewMrPersonalNotify(
|
||||
Long mrId,
|
||||
String title,
|
||||
String url,
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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<Pair<String, String>> notes;
|
||||
|
||||
@Builder
|
||||
public DiscussionNewNotify(
|
||||
public DiscussionNewPersonalNotify(
|
||||
String threadId,
|
||||
String mergeRequestName,
|
||||
String authorName,
|
@ -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,
|
@ -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,
|
@ -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<String> chatId;
|
||||
private Optional<Integer> threadId;
|
||||
|
||||
}
|
@ -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<Person> findAllById(Set<Long> personIds);
|
||||
|
||||
List<PersonTelegram> getAllTelegramInfoByIds(Set<Long> personIds);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
<T extends Notify> void send(T notify);
|
||||
<T extends PersonalNotify> void send(T notify);
|
||||
|
||||
<T extends GroupNotify> void send(T notify);
|
||||
|
||||
}
|
||||
|
@ -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<Person, Long> existsById(Set<Long> personIds);
|
||||
|
||||
List<Person> createAll(List<Person> newPersons);
|
||||
|
||||
Map<Long, String> getTelegramUsernamesByPersonIds(Set<Long> personIds);
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<Long, String> 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())
|
||||
|
@ -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()) // Пайплайн имеет статус необходимый для уведомления
|
||||
|
@ -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())
|
||||
|
@ -40,7 +40,7 @@ import static java.util.stream.Collectors.toSet;
|
||||
@RequiredArgsConstructor
|
||||
public class PipelineParser {
|
||||
|
||||
private static final Set<PipelineStatus> oldStatus = Set.of(
|
||||
private static final Set<PipelineStatus> 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<Pipeline> pipelines = pipelineService.getAllByStatuses(oldStatus);
|
||||
final List<Pipeline> pipelines = pipelineService.getAllByStatuses(oldSOLD_STATUSES);
|
||||
|
||||
final List<Pipeline> newPipelines = gitlabSdkManager.getAllPipelineForProject(
|
||||
pipelines.stream()
|
||||
|
@ -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 <T extends Notify> void send(T notify) {
|
||||
public <T extends PersonalNotify> void send(T notify) {
|
||||
if (settingService.isEnableAllNotify()) {
|
||||
messageSendService.send(notify);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends GroupNotify> void send(T notify) {
|
||||
if (settingService.isEnableAllNotify()) {
|
||||
if (groupNotifyProperty.getChatId().isPresent()) {
|
||||
messageSendService.send(notify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Long, String> getTelegramUsernamesByPersonIds(Set<Long> personIds) {
|
||||
return repository.getAllTelegramInfoByIds(personIds).stream()
|
||||
.collect(Collectors.toMap(PersonTelegram::getId, PersonTelegram::getTelegramUserName));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<PersonTelegram> getAllTelegramInfoByIds(Set<Long> personIds) {
|
||||
return jpaTelegramRepository.findAllById(personIds);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<PersonTelegram, Long> {
|
||||
|
||||
}
|
@ -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);
|
||||
|
@ -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}
|
||||
|
@ -0,0 +1,35 @@
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.17.xsd">
|
||||
|
||||
<changeSet id="2024-09-03-add-column-telegram-username" author="mstruchkov">
|
||||
<addColumn tableName="person">
|
||||
<column name="telegram_username" type="varchar"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2024-09-03-add-column-telegram-username-2" author="mstruchkov">
|
||||
<dropColumn tableName="person">
|
||||
<column name="telegram_username"/>
|
||||
</dropColumn>
|
||||
<createTable tableName="person_telegram">
|
||||
<column name="id" type="int">
|
||||
<constraints nullable="false" primaryKey="true"/>
|
||||
</column>
|
||||
<column name="telegram_username" type="varchar">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
</createTable>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="2024-09-03-add-link-for-telegram-username" author="mstruchkov">
|
||||
<addForeignKeyConstraint baseTableName="person"
|
||||
baseColumnNames="id"
|
||||
constraintName="fk_person_telegram_id_person_id"
|
||||
referencedTableName="person"
|
||||
referencedColumnNames="id"
|
||||
deleteCascade="true"/>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -10,5 +10,6 @@
|
||||
<include file="2024-02-06-change-varchar.xml" relativeToChangelogFile="true"/>
|
||||
<include file="2024-08-21-add-milestone.xml" relativeToChangelogFile="true"/>
|
||||
<include file="2024-01-20-create-merge-request-approvals.xml" relativeToChangelogFile="true"/>
|
||||
<include file="2024-09-03-add-group-notify.xml" relativeToChangelogFile="true"/>
|
||||
|
||||
</databaseChangeLog>
|
2
pom.xml
2
pom.xml
@ -42,7 +42,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<godfather.telegram.version>1.0.0</godfather.telegram.version>
|
||||
<godfather.telegram.version>1.0.1-SNAPSHOT</godfather.telegram.version>
|
||||
<!-- https://mvnrepository.com/artifact/dev.struchkov.haiti/haiti-utils -->
|
||||
<haiti.utils.version>3.0.3</haiti.utils.version>
|
||||
<haiti.utils.fields.version>1.1.1</haiti.utils.fields.version>
|
||||
|
@ -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<NotifyBoxAnswerGenerator> 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<String> 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<NotifyBoxAnswerGenerator> getGenerator(String notifyType) {
|
||||
return Optional.ofNullable(generatorMap.get(notifyType));
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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<ApprovalChangedMrNotify> {
|
||||
public class ApprovalChangedMrNotifyGenerator implements NotifyBoxAnswerGenerator<ApprovalChangedMrPersonalNotify> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<ConflictMrNotify> {
|
||||
public class ConflictPrNotifyGenerator implements NotifyBoxAnswerGenerator<ConflictMrPersonalNotify> {
|
||||
|
||||
@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<Confl
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return ConflictMrNotify.TYPE;
|
||||
return ConflictMrPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrPersonalNotify;
|
||||
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 ConflictResolvePrNotifyGenerator implements NotifyBoxAnswerGenerator<ConflictResolveMrNotify> {
|
||||
public class ConflictResolvePrNotifyGenerator implements NotifyBoxAnswerGenerator<ConflictResolveMrPersonalNotify> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<NewCommentNotify> {
|
||||
public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator<NewCommentPersonalNotify> {
|
||||
|
||||
@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<NewCo
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return NewCommentNotify.TYPE;
|
||||
return NewCommentPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
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.utils.Icons;
|
||||
import dev.struchkov.bot.gitlab.telegram.utils.Const;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
@ -19,10 +19,10 @@ import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENA
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
public class NewProjectNotifyGenerator implements NotifyBoxAnswerGenerator<NewProjectNotify> {
|
||||
public class NewProjectNotifyGenerator implements NotifyBoxAnswerGenerator<NewProjectPersonalNotify> {
|
||||
|
||||
@Override
|
||||
public BoxAnswer generate(NewProjectNotify notify) {
|
||||
public BoxAnswer generate(NewProjectPersonalNotify notify) {
|
||||
final Optional<String> optDescription = Optional.ofNullable(notify.getProjectDescription())
|
||||
.filter(Checker::checkNotBlank)
|
||||
.map(Strings::escapeMarkdown);
|
||||
@ -61,7 +61,7 @@ public class NewProjectNotifyGenerator implements NotifyBoxAnswerGenerator<NewPr
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return NewProjectNotify.TYPE;
|
||||
return NewProjectPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.haiti.utils.container.Pair;
|
||||
@ -22,10 +22,10 @@ import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
public class NewThreadNotifyGenerator implements NotifyBoxAnswerGenerator<DiscussionNewNotify> {
|
||||
public class NewThreadNotifyGenerator implements NotifyBoxAnswerGenerator<DiscussionNewPersonalNotify> {
|
||||
|
||||
@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<Discus
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return DiscussionNewNotify.TYPE;
|
||||
return DiscussionNewPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface NotifyBoxAnswerGenerator<T> {
|
||||
public interface NotifyBoxAnswerGenerator<T extends Notify> {
|
||||
|
||||
BoxAnswer generate(T notify);
|
||||
|
||||
|
@ -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<PipelineNotify> {
|
||||
public class PipelineNotifyGenerator implements NotifyBoxAnswerGenerator<PipelinePersonalNotify> {
|
||||
|
||||
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<Pipelin
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return PipelineNotify.TYPE;
|
||||
return PipelinePersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.StatusMrPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -15,10 +15,10 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
public class StatusMrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusMrNotify> {
|
||||
public class StatusMrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusMrPersonalNotify> {
|
||||
|
||||
@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<StatusM
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return StatusMrNotify.TYPE;
|
||||
return StatusMrPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadCloseNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.ThreadClosePersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -14,10 +14,10 @@ import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
public class ThreadCloseNotifyGenerate implements NotifyBoxAnswerGenerator<ThreadCloseNotify> {
|
||||
public class ThreadCloseNotifyGenerate implements NotifyBoxAnswerGenerator<ThreadClosePersonalNotify> {
|
||||
|
||||
@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<Threa
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return ThreadCloseNotify.TYPE;
|
||||
return ThreadClosePersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.UpdateMrPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -19,10 +19,10 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateMrNotify> {
|
||||
public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateMrPersonalNotify> {
|
||||
|
||||
@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<UpdateM
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return UpdateMrNotify.TYPE;
|
||||
return UpdateMrPersonalNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify.group;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.SimpleKeyBoardLine.keyBoardLine;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton;
|
||||
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NewMergeRequestGroupNotifyGenerator implements NotifyBoxAnswerGenerator<NewMergeRequestGroupPersonalNotify> {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user