Добавил возможность отписываться от уведомлений по конкретным MR
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1040ce5ed2
commit
91bd1bbc4b
@ -12,12 +12,13 @@ public class ConflictMrNotify extends MrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private ConflictMrNotify(
|
private ConflictMrNotify(
|
||||||
|
Long mrId,
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String projectKey,
|
String projectKey,
|
||||||
String sourceBranch
|
String sourceBranch
|
||||||
) {
|
) {
|
||||||
super(projectKey, name, url);
|
super(mrId, projectKey, name, url);
|
||||||
this.sourceBranch = sourceBranch;
|
this.sourceBranch = sourceBranch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,15 +6,18 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public abstract class MrNotify implements Notify {
|
public abstract class MrNotify implements Notify {
|
||||||
|
|
||||||
|
protected final Long mrId;
|
||||||
protected final String projectName;
|
protected final String projectName;
|
||||||
protected final String title;
|
protected final String title;
|
||||||
protected final String url;
|
protected final String url;
|
||||||
|
|
||||||
protected MrNotify(
|
protected MrNotify(
|
||||||
|
Long mrId,
|
||||||
String projectName,
|
String projectName,
|
||||||
String title,
|
String title,
|
||||||
String url
|
String url
|
||||||
) {
|
) {
|
||||||
|
this.mrId = mrId;
|
||||||
this.projectName = projectName;
|
this.projectName = projectName;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -18,6 +18,7 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewMrForAssignee(
|
private NewMrForAssignee(
|
||||||
|
Long mrId,
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String description,
|
String description,
|
||||||
@ -31,6 +32,7 @@ public class NewMrForAssignee extends NewMrNotify {
|
|||||||
String newAssigneeName
|
String newAssigneeName
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
|
mrId,
|
||||||
title,
|
title,
|
||||||
url,
|
url,
|
||||||
description,
|
description,
|
||||||
|
@ -14,6 +14,7 @@ public class NewMrForReview extends NewMrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewMrForReview(
|
private NewMrForReview(
|
||||||
|
Long mrId,
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String description,
|
String description,
|
||||||
@ -25,6 +26,7 @@ public class NewMrForReview extends NewMrNotify {
|
|||||||
String assignee
|
String assignee
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
|
mrId,
|
||||||
title,
|
title,
|
||||||
url,
|
url,
|
||||||
description,
|
description,
|
||||||
|
@ -14,6 +14,7 @@ public abstract class NewMrNotify extends MrNotify {
|
|||||||
protected final Set<String> labels;
|
protected final Set<String> labels;
|
||||||
|
|
||||||
protected NewMrNotify(
|
protected NewMrNotify(
|
||||||
|
Long mrId,
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String description,
|
String description,
|
||||||
@ -23,7 +24,7 @@ public abstract class NewMrNotify extends MrNotify {
|
|||||||
String sourceBranch,
|
String sourceBranch,
|
||||||
Set<String> labels
|
Set<String> labels
|
||||||
) {
|
) {
|
||||||
super(projectName, title, url);
|
super(mrId, projectName, title, url);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.targetBranch = targetBranch;
|
this.targetBranch = targetBranch;
|
||||||
|
@ -14,13 +14,14 @@ public class StatusMrNotify extends MrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private StatusMrNotify(
|
private StatusMrNotify(
|
||||||
|
Long mrId,
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String projectName,
|
String projectName,
|
||||||
MergeRequestState oldStatus,
|
MergeRequestState oldStatus,
|
||||||
MergeRequestState newStatus
|
MergeRequestState newStatus
|
||||||
) {
|
) {
|
||||||
super(projectName, name, url);
|
super(mrId, projectName, name, url);
|
||||||
this.oldStatus = oldStatus;
|
this.oldStatus = oldStatus;
|
||||||
this.newStatus = newStatus;
|
this.newStatus = newStatus;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class UpdateMrNotify extends MrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private UpdateMrNotify(
|
private UpdateMrNotify(
|
||||||
|
Long mrId,
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String author,
|
String author,
|
||||||
@ -25,7 +26,7 @@ public class UpdateMrNotify extends MrNotify {
|
|||||||
Long personTasks,
|
Long personTasks,
|
||||||
Long personResolvedTasks
|
Long personResolvedTasks
|
||||||
) {
|
) {
|
||||||
super(projectKey, name, url);
|
super(mrId, projectKey, name, url);
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.allTasks = allTasks;
|
this.allTasks = allTasks;
|
||||||
this.allResolvedTasks = allResolvedTasks;
|
this.allResolvedTasks = allResolvedTasks;
|
||||||
|
@ -28,4 +28,6 @@ public interface MergeRequestRepository {
|
|||||||
|
|
||||||
Set<Long> findAllIds();
|
Set<Long> findAllIds();
|
||||||
|
|
||||||
|
void disableNotify(Long mrId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,6 @@ public interface MergeRequestsService {
|
|||||||
|
|
||||||
Set<Long> getAllIds();
|
Set<Long> getAllIds();
|
||||||
|
|
||||||
|
void disableNotify(@NonNull Long mrId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@ public class Icons {
|
|||||||
public static final String LINK = "\uD83D\uDD17";
|
public static final String LINK = "\uD83D\uDD17";
|
||||||
public static final String REVIEWER = "\uD83D\uDD0E";
|
public static final String REVIEWER = "\uD83D\uDD0E";
|
||||||
public static final String PROJECT = "\uD83C\uDFD7";
|
public static final String PROJECT = "\uD83C\uDFD7";
|
||||||
|
public static final String DISABLE_NOTIFY = "\uD83D\uDD15";
|
||||||
|
public static final String YES = "✅";
|
||||||
|
public static final String NO = "❌";
|
||||||
|
|
||||||
private Icons() {
|
private Icons() {
|
||||||
utilityClass();
|
utilityClass();
|
||||||
|
@ -116,6 +116,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
private void sendNotifyNewMrReview(MergeRequest mergeRequest, String projectName) {
|
private void sendNotifyNewMrReview(MergeRequest mergeRequest, String projectName) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
NewMrForReview.builder()
|
NewMrForReview.builder()
|
||||||
|
.mrId(mergeRequest.getId())
|
||||||
.projectName(projectName)
|
.projectName(projectName)
|
||||||
.labels(mergeRequest.getLabels())
|
.labels(mergeRequest.getLabels())
|
||||||
.author(mergeRequest.getAuthor().getName())
|
.author(mergeRequest.getAuthor().getName())
|
||||||
@ -131,6 +132,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
|
|
||||||
private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName, String oldAssigneeName) {
|
private void sendNotifyNewAssignee(MergeRequest mergeRequest, String projectName, String oldAssigneeName) {
|
||||||
final NewMrForAssignee.NewMrForAssigneeBuilder builder = NewMrForAssignee.builder()
|
final NewMrForAssignee.NewMrForAssigneeBuilder builder = NewMrForAssignee.builder()
|
||||||
|
.mrId(mergeRequest.getId())
|
||||||
.projectName(projectName)
|
.projectName(projectName)
|
||||||
.labels(mergeRequest.getLabels())
|
.labels(mergeRequest.getLabels())
|
||||||
.author(mergeRequest.getAuthor().getName())
|
.author(mergeRequest.getAuthor().getName())
|
||||||
@ -264,6 +266,12 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
return repository.findAllIds();
|
return repository.findAllIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void disableNotify(@NonNull Long mrId) {
|
||||||
|
repository.disableNotify(mrId);
|
||||||
|
}
|
||||||
|
|
||||||
private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
||||||
final Long botUserGitlabId = personInformation.getId();
|
final Long botUserGitlabId = personInformation.getId();
|
||||||
|
|
||||||
@ -295,6 +303,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
}
|
}
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
UpdateMrNotify.builder()
|
UpdateMrNotify.builder()
|
||||||
|
.mrId(oldMergeRequest.getId())
|
||||||
.author(oldMergeRequest.getAuthor().getName())
|
.author(oldMergeRequest.getAuthor().getName())
|
||||||
.name(oldMergeRequest.getTitle())
|
.name(oldMergeRequest.getTitle())
|
||||||
.projectKey(project.getName())
|
.projectKey(project.getName())
|
||||||
@ -317,6 +326,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
) {
|
) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
ConflictMrNotify.builder()
|
ConflictMrNotify.builder()
|
||||||
|
.mrId(oldMergeRequest.getId())
|
||||||
.sourceBranch(oldMergeRequest.getSourceBranch())
|
.sourceBranch(oldMergeRequest.getSourceBranch())
|
||||||
.name(mergeRequest.getTitle())
|
.name(mergeRequest.getTitle())
|
||||||
.url(mergeRequest.getWebUrl())
|
.url(mergeRequest.getWebUrl())
|
||||||
@ -336,6 +346,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
) {
|
) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
StatusMrNotify.builder()
|
StatusMrNotify.builder()
|
||||||
|
.mrId(oldMergeRequest.getId())
|
||||||
.name(newMergeRequest.getTitle())
|
.name(newMergeRequest.getTitle())
|
||||||
.url(oldMergeRequest.getWebUrl())
|
.url(oldMergeRequest.getWebUrl())
|
||||||
.projectName(project.getName())
|
.projectName(project.getName())
|
||||||
|
@ -70,4 +70,9 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
|
|||||||
return jpaRepository.findAllIds();
|
return jpaRepository.findAllIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disableNotify(Long mrId) {
|
||||||
|
jpaRepository.disableNotify(mrId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package dev.struchkov.bot.gitlab.data.jpa;
|
|||||||
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
|
import dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr;
|
||||||
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
|
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
|
||||||
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
|
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
|
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
@ -27,4 +28,8 @@ public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<M
|
|||||||
@Query("SELECT mr.id FROM MergeRequest mr")
|
@Query("SELECT mr.id FROM MergeRequest mr")
|
||||||
Set<Long> findAllIds();
|
Set<Long> findAllIds();
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("UPDATE MergeRequest mr SET mr.notification = false WHERE mr.id = :mrId")
|
||||||
|
void disableNotify(@Param("mrId") Long mrId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.telegram.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class AdditionalConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ScheduledExecutorService scheduledExecutorService() {
|
||||||
|
return Executors.newScheduledThreadPool(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,17 @@
|
|||||||
package dev.struchkov.bot.gitlab.telegram.config;
|
package dev.struchkov.bot.gitlab.telegram.config;
|
||||||
|
|
||||||
import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost;
|
import dev.struchkov.bot.gitlab.telegram.service.ReplaceUrlLocalhost;
|
||||||
import dev.struchkov.bot.gitlab.telegram.unit.CommandUnit;
|
|
||||||
import dev.struchkov.bot.gitlab.telegram.unit.MenuConfig;
|
import dev.struchkov.bot.gitlab.telegram.unit.MenuConfig;
|
||||||
|
import dev.struchkov.bot.gitlab.telegram.unit.command.AnswerNoteUnit;
|
||||||
|
import dev.struchkov.bot.gitlab.telegram.unit.command.DeleteMessageUnit;
|
||||||
|
import dev.struchkov.bot.gitlab.telegram.unit.command.DisableNotifyMrUnit;
|
||||||
import dev.struchkov.bot.gitlab.telegram.unit.flow.InitSettingFlow;
|
import dev.struchkov.bot.gitlab.telegram.unit.flow.InitSettingFlow;
|
||||||
|
import dev.struchkov.godfather.main.core.unit.TypeUnit;
|
||||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
import dev.struchkov.godfather.simple.context.service.EventHandler;
|
import dev.struchkov.godfather.simple.context.service.EventHandler;
|
||||||
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
|
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
|
||||||
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
|
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
|
||||||
|
import dev.struchkov.godfather.simple.core.action.cmd.RollBackCmdAction;
|
||||||
import dev.struchkov.godfather.simple.core.provider.StoryLineHandler;
|
import dev.struchkov.godfather.simple.core.provider.StoryLineHandler;
|
||||||
import dev.struchkov.godfather.simple.core.service.PersonSettingServiceImpl;
|
import dev.struchkov.godfather.simple.core.service.PersonSettingServiceImpl;
|
||||||
import dev.struchkov.godfather.simple.core.service.StorylineContextMapImpl;
|
import dev.struchkov.godfather.simple.core.service.StorylineContextMapImpl;
|
||||||
@ -72,9 +76,11 @@ public class TelegramBotConfig {
|
|||||||
|
|
||||||
MenuConfig menuConfig,
|
MenuConfig menuConfig,
|
||||||
InitSettingFlow unitConfig,
|
InitSettingFlow unitConfig,
|
||||||
CommandUnit commandUnit
|
AnswerNoteUnit commandUnit,
|
||||||
|
DeleteMessageUnit deleteMessageUnit,
|
||||||
|
DisableNotifyMrUnit disableNotifyMrUnit
|
||||||
) {
|
) {
|
||||||
final List<Object> config = List.of(menuConfig, unitConfig, commandUnit);
|
final List<Object> config = List.of(menuConfig, unitConfig, commandUnit, deleteMessageUnit, disableNotifyMrUnit);
|
||||||
|
|
||||||
return new StorylineMailService(
|
return new StorylineMailService(
|
||||||
unitPointerService,
|
unitPointerService,
|
||||||
@ -89,11 +95,12 @@ public class TelegramBotConfig {
|
|||||||
TelegramSending sending,
|
TelegramSending sending,
|
||||||
PersonSettingService personSettingService,
|
PersonSettingService personSettingService,
|
||||||
|
|
||||||
StorylineService<Mail> mailStorylineService
|
StorylineService<Mail> storylineService
|
||||||
) {
|
) {
|
||||||
final MailAutoresponderTelegram autoresponder = new MailAutoresponderTelegram(
|
final MailAutoresponderTelegram autoresponder = new MailAutoresponderTelegram(
|
||||||
sending, personSettingService, mailStorylineService
|
sending, personSettingService, storylineService
|
||||||
);
|
);
|
||||||
|
autoresponder.initActionUnit(TypeUnit.BACK_CMD, new RollBackCmdAction<>(storylineService));
|
||||||
autoresponder.setExecutorService(executorService);
|
autoresponder.setExecutorService(executorService);
|
||||||
return autoresponder;
|
return autoresponder;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMATION;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_FALSE;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -59,8 +63,9 @@ public class NewMrForAssigneeNotifyGenerator implements NotifyBoxAnswerGenerator
|
|||||||
notifyMessage,
|
notifyMessage,
|
||||||
inlineKeyBoard(
|
inlineKeyBoard(
|
||||||
simpleLine(
|
simpleLine(
|
||||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||||
urlButton(Icons.LINK, notify.getUrl())
|
urlButton(Icons.LINK, notify.getUrl()),
|
||||||
|
simpleButton(Icons.DISABLE_NOTIFY, "[" + BUTTON_ARG_DISABLE_NOTIFY_MR_ID + ":" + notify.getMrId() + ";" + BUTTON_ARG_CONFIRMATION + ":" + BUTTON_VALUE_FALSE + "]")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -7,6 +7,10 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMATION;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_FALSE;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -52,8 +56,9 @@ public class NewMrForReviewNotifyGenerator implements NotifyBoxAnswerGenerator<N
|
|||||||
notifyMessage,
|
notifyMessage,
|
||||||
inlineKeyBoard(
|
inlineKeyBoard(
|
||||||
simpleLine(
|
simpleLine(
|
||||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||||
urlButton(Icons.LINK, notify.getUrl())
|
urlButton(Icons.LINK, notify.getUrl()),
|
||||||
|
simpleButton(Icons.DISABLE_NOTIFY, "[" + BUTTON_ARG_DISABLE_NOTIFY_MR_ID + ":" + notify.getMrId() + ";" + BUTTON_ARG_CONFIRMATION + ":" + BUTTON_VALUE_FALSE + "]")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -45,7 +46,7 @@ public class PipelineNotifyGenerator implements NotifyBoxAnswerGenerator<Pipelin
|
|||||||
builder.toString(),
|
builder.toString(),
|
||||||
inlineKeyBoard(
|
inlineKeyBoard(
|
||||||
simpleLine(
|
simpleLine(
|
||||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||||
urlButton(Icons.LINK, notify.getWebUrl())
|
urlButton(Icons.LINK, notify.getWebUrl())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,10 @@ import dev.struchkov.bot.gitlab.context.utils.Smile;
|
|||||||
import dev.struchkov.godfather.main.domain.BoxAnswer;
|
import dev.struchkov.godfather.main.domain.BoxAnswer;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMATION;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_FALSE;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
@ -47,8 +51,9 @@ public class UpdatePrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
|
|||||||
notifyMessage,
|
notifyMessage,
|
||||||
inlineKeyBoard(
|
inlineKeyBoard(
|
||||||
simpleLine(
|
simpleLine(
|
||||||
simpleButton(Icons.VIEW, "DELETE_MESSAGE"),
|
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||||
urlButton(Icons.LINK, notify.getUrl())
|
urlButton(Icons.LINK, notify.getUrl()),
|
||||||
|
simpleButton(Icons.DISABLE_NOTIFY, "[" + BUTTON_ARG_DISABLE_NOTIFY_MR_ID + ":" + notify.getMrId() + ";" + BUTTON_ARG_CONFIRMATION + ":" + BUTTON_VALUE_FALSE + "]")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.telegram.unit;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
|
import dev.struchkov.godfather.simple.core.service.StorylineService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.context.event.ContextStartedEvent;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DISABLE_NOTIFY_MR;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LinkService {
|
||||||
|
|
||||||
|
private final StorylineService<Mail> storylineService;
|
||||||
|
|
||||||
|
@EventListener
|
||||||
|
public void link(ContextStartedEvent event) {
|
||||||
|
storylineService.lazyLink(DISABLE_NOTIFY_MR, DISABLE_NOTIFY_MR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package dev.struchkov.bot.gitlab.telegram.unit;
|
package dev.struchkov.bot.gitlab.telegram.unit.command;
|
||||||
|
|
||||||
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
|
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
|
||||||
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
|
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
|
||||||
@ -10,18 +10,15 @@ import dev.struchkov.godfather.main.domain.annotation.Unit;
|
|||||||
import dev.struchkov.godfather.main.domain.content.Attachment;
|
import dev.struchkov.godfather.main.domain.content.Attachment;
|
||||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
import dev.struchkov.godfather.simple.core.unit.AnswerText;
|
import dev.struchkov.godfather.simple.core.unit.AnswerText;
|
||||||
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
|
|
||||||
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
|
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment;
|
||||||
import dev.struchkov.godfather.telegram.domain.attachment.TelegramAttachmentType;
|
import dev.struchkov.godfather.telegram.domain.attachment.TelegramAttachmentType;
|
||||||
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
|
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
|
||||||
import dev.struchkov.haiti.utils.Checker;
|
import dev.struchkov.haiti.utils.Checker;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -30,7 +27,7 @@ import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CommandUnit {
|
public class AnswerNoteUnit {
|
||||||
|
|
||||||
private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$");
|
private static final Pattern NOTE_LINK = Pattern.compile("#note_\\d+$");
|
||||||
|
|
||||||
@ -38,7 +35,6 @@ public class CommandUnit {
|
|||||||
private final AppSettingService settingService;
|
private final AppSettingService settingService;
|
||||||
private final NoteService noteService;
|
private final NoteService noteService;
|
||||||
private final DiscussionService discussionService;
|
private final DiscussionService discussionService;
|
||||||
private final TelegramSending telegramSending;
|
|
||||||
|
|
||||||
@Unit(value = ANSWER_NOTE, main = true)
|
@Unit(value = ANSWER_NOTE, main = true)
|
||||||
public AnswerText<Mail> answerNote() {
|
public AnswerText<Mail> answerNote() {
|
||||||
@ -82,29 +78,4 @@ public class CommandUnit {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Unit(value = "DELETE_MESSAGE", main = true)
|
|
||||||
public AnswerText<Mail> deleteMessage() {
|
|
||||||
return AnswerText.<Mail>builder()
|
|
||||||
.triggerCheck(mail -> {
|
|
||||||
final boolean isAccess = personInformation.getTelegramId().equals(mail.getPersonId());
|
|
||||||
if (isAccess) {
|
|
||||||
final boolean isFirstStart = settingService.isFirstStart();
|
|
||||||
if (!isFirstStart) {
|
|
||||||
final Optional<ButtonClickAttachment> optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
|
|
||||||
if (optButtonClick.isPresent()) {
|
|
||||||
final ButtonClickAttachment buttonClick = optButtonClick.get();
|
|
||||||
final String rawData = buttonClick.getRawCallBackData();
|
|
||||||
return rawData.equals("DELETE_MESSAGE");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
.answer(mail -> {
|
|
||||||
final ButtonClickAttachment clickButton = Attachments.findFirstButtonClick(mail.getAttachments()).orElseThrow();
|
|
||||||
telegramSending.deleteMessage(mail.getPersonId(), clickButton.getMessageId());
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.telegram.unit.command;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
|
||||||
|
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
||||||
|
import dev.struchkov.godfather.main.domain.annotation.Unit;
|
||||||
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
|
import dev.struchkov.godfather.simple.core.unit.AnswerText;
|
||||||
|
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
|
||||||
|
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
|
||||||
|
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DeleteMessageUnit {
|
||||||
|
|
||||||
|
private final TelegramSending telegramSending;
|
||||||
|
private final PersonInformation personInformation;
|
||||||
|
private final AppSettingService settingService;
|
||||||
|
|
||||||
|
@Unit(value = DELETE_MESSAGE, global = true)
|
||||||
|
public AnswerText<Mail> deleteMessage() {
|
||||||
|
return AnswerText.<Mail>builder()
|
||||||
|
.triggerCheck(mail -> {
|
||||||
|
final boolean isAccess = personInformation.getTelegramId().equals(mail.getPersonId());
|
||||||
|
if (isAccess) {
|
||||||
|
final boolean isFirstStart = settingService.isFirstStart();
|
||||||
|
if (!isFirstStart) {
|
||||||
|
final Optional<ButtonClickAttachment> optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
|
||||||
|
if (optButtonClick.isPresent()) {
|
||||||
|
final ButtonClickAttachment buttonClick = optButtonClick.get();
|
||||||
|
final String rawData = buttonClick.getRawCallBackData();
|
||||||
|
return rawData.equals(DELETE_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
.answer(mail -> {
|
||||||
|
final ButtonClickAttachment clickButton = Attachments.findFirstButtonClick(mail.getAttachments()).orElseThrow();
|
||||||
|
telegramSending.deleteMessage(mail.getPersonId(), clickButton.getMessageId());
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.telegram.unit.command;
|
||||||
|
|
||||||
|
import dev.struchkov.bot.gitlab.context.domain.PersonInformation;
|
||||||
|
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
||||||
|
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
|
||||||
|
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||||
|
import dev.struchkov.godfather.main.domain.annotation.Unit;
|
||||||
|
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||||
|
import dev.struchkov.godfather.simple.core.unit.AnswerText;
|
||||||
|
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
|
||||||
|
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment.Arg;
|
||||||
|
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
|
||||||
|
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_CONFIRMATION;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_ARG_DISABLE_NOTIFY_MR_ID;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.Const.BUTTON_VALUE_TRUE;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||||
|
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DISABLE_NOTIFY_MR;
|
||||||
|
import static dev.struchkov.godfather.main.domain.BoxAnswer.replaceBoxAnswer;
|
||||||
|
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||||
|
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||||
|
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class DisableNotifyMrUnit {
|
||||||
|
|
||||||
|
public static final String WARNING_ABOUT_DISABLE_NOTIFY = Icons.DISABLE_NOTIFY + """
|
||||||
|
*Disabling notifications*
|
||||||
|
|
||||||
|
Are you sure you want to stop receiving notifications?
|
||||||
|
-- -- -- -- --
|
||||||
|
There will be no more notifications for this merge request about: status change, conflict, addition/removal from reviewers/responsible.
|
||||||
|
|
||||||
|
Thread notifications will continue to come.
|
||||||
|
""";
|
||||||
|
public static final String SUCCESSFULLY_DISABLED = "Notifications successfully disabled for the given merge request";
|
||||||
|
|
||||||
|
private final MergeRequestsService mergeRequestsService;
|
||||||
|
private final PersonInformation personInformation;
|
||||||
|
private final AppSettingService settingService;
|
||||||
|
private final TelegramSending telegramSending;
|
||||||
|
|
||||||
|
private final ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
|
@Unit(value = DISABLE_NOTIFY_MR, global = true)
|
||||||
|
public AnswerText<Mail> disableNotifyMr() {
|
||||||
|
return AnswerText.<Mail>builder()
|
||||||
|
.triggerCheck(mail -> {
|
||||||
|
final boolean isAccess = personInformation.getTelegramId().equals(mail.getPersonId());
|
||||||
|
if (isAccess) {
|
||||||
|
final boolean isFirstStart = settingService.isFirstStart();
|
||||||
|
if (!isFirstStart) {
|
||||||
|
final Optional<ButtonClickAttachment> optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
|
||||||
|
if (optButtonClick.isPresent()) {
|
||||||
|
final ButtonClickAttachment buttonClick = optButtonClick.get();
|
||||||
|
return buttonClick.getArgByType(BUTTON_ARG_DISABLE_NOTIFY_MR_ID).isPresent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
.answer(mail -> {
|
||||||
|
final ButtonClickAttachment clickButton = Attachments.findFirstButtonClick(mail.getAttachments()).orElseThrow();
|
||||||
|
final boolean confirmation = clickButton.getArgByType(BUTTON_ARG_CONFIRMATION)
|
||||||
|
.map(Arg::getValue)
|
||||||
|
.map(BUTTON_VALUE_TRUE::equals)
|
||||||
|
.orElseThrow();
|
||||||
|
final Long mrId = clickButton.getArgByType(BUTTON_ARG_DISABLE_NOTIFY_MR_ID)
|
||||||
|
.map(Arg::getValue)
|
||||||
|
.map(Long::parseLong)
|
||||||
|
.orElseThrow();
|
||||||
|
|
||||||
|
if (confirmation) {
|
||||||
|
mergeRequestsService.disableNotify(mrId);
|
||||||
|
scheduledExecutorService.schedule(() -> telegramSending.deleteMessage(mail.getPersonId(), clickButton.getMessageId()), 5, TimeUnit.SECONDS);
|
||||||
|
return replaceBoxAnswer(SUCCESSFULLY_DISABLED);
|
||||||
|
} else {
|
||||||
|
return replaceBoxAnswer(
|
||||||
|
WARNING_ABOUT_DISABLE_NOTIFY,
|
||||||
|
inlineKeyBoard(
|
||||||
|
simpleLine(
|
||||||
|
simpleButton(Icons.YES, "[" + BUTTON_ARG_DISABLE_NOTIFY_MR_ID + ":" + mrId + ";" + BUTTON_ARG_CONFIRMATION + ":" + BUTTON_VALUE_TRUE + "]"),
|
||||||
|
simpleButton(Icons.NO, DELETE_MESSAGE)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package dev.struchkov.bot.gitlab.telegram.utils;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class Const {
|
||||||
|
|
||||||
|
public static final String BUTTON_VALUE_FALSE = "f";
|
||||||
|
public static final String BUTTON_VALUE_TRUE = "t";
|
||||||
|
|
||||||
|
public static final String BUTTON_ARG_DISABLE_NOTIFY_MR_ID = "dis_mr_id";
|
||||||
|
public static final String BUTTON_ARG_CONFIRMATION = "conf";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -20,7 +20,10 @@ public final class UnitName {
|
|||||||
public static final String ACCESS_ERROR = "ACCESS_ERROR";
|
public static final String ACCESS_ERROR = "ACCESS_ERROR";
|
||||||
public static final String CHECK_PARSER_PRIVATE_PROJECT_NO = "CHECK_PARSER_PRIVATE_PROJECT_NO";
|
public static final String CHECK_PARSER_PRIVATE_PROJECT_NO = "CHECK_PARSER_PRIVATE_PROJECT_NO";
|
||||||
public static final String CHECK_PARSE_OWNER_PROJECT_NO = "CHECK_PARSE_OWNER_PROJECT_NO";
|
public static final String CHECK_PARSE_OWNER_PROJECT_NO = "CHECK_PARSE_OWNER_PROJECT_NO";
|
||||||
public static final String REPLACE_GENERAL_MENU = "REPLACE_GENERAL_MENU";
|
|
||||||
|
// команды
|
||||||
|
public static final String DELETE_MESSAGE = "DELETE_MESSAGE";
|
||||||
|
public static final String DISABLE_NOTIFY_MR = "DISABLE_NOTIFY_MR";
|
||||||
|
|
||||||
private UnitName() {
|
private UnitName() {
|
||||||
utilityClass();
|
utilityClass();
|
||||||
|
Loading…
Reference in New Issue
Block a user