Compare commits
6 Commits
1b63aa1f43
...
d148e56cd4
Author | SHA1 | Date | |
---|---|---|---|
d148e56cd4 | |||
c53e2cde5e | |||
2ee605119b | |||
d12b8f816b | |||
09e963bae6 | |||
395e45ff32 |
@ -1,10 +1,12 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.comment;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public final class NewCommentNotify implements Notify {
|
||||
|
||||
public static final String TYPE = "NewCommentNotify";
|
||||
|
@ -1,12 +1,16 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class ConflictMrNotify extends MrNotify {
|
||||
|
||||
public static final String TYPE = "ConflictPrNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String sourceBranch;
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class ConflictResolveMrNotify extends MrNotify {
|
||||
|
||||
public static final String TYPE = "ConflictResolveMrNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String sourceBranch;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
@ -7,10 +8,13 @@ import lombok.Singular;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForAssigneeFields.CLASS_NAME;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class NewMrForAssignee extends NewMrNotify {
|
||||
|
||||
public static final String TYPE = "NewMrForAssignee";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final List<String> reviewers;
|
||||
private final String oldAssigneeName;
|
||||
|
@ -1,14 +1,18 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.NewMrForReviewFields.CLASS_NAME;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class NewMrForReview extends NewMrNotify {
|
||||
|
||||
public static final String TYPE = "NewMrForReview";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String assignee;
|
||||
|
||||
|
@ -1,13 +1,17 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.MergeRequestState;
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class StatusMrNotify extends MrNotify {
|
||||
|
||||
public static final String TYPE = "StatusPrNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final MergeRequestState oldStatus;
|
||||
private final MergeRequestState newStatus;
|
||||
|
@ -1,18 +1,23 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.mergerequest;
|
||||
|
||||
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;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class UpdateMrNotify extends MrNotify {
|
||||
|
||||
public static final String TYPE = "UpdatePrNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String author;
|
||||
private final Long allTasks;
|
||||
private final Long allResolvedTasks;
|
||||
private final Long personTasks;
|
||||
private final Long personResolvedTasks;
|
||||
private final String comment;
|
||||
|
||||
@Builder
|
||||
private UpdateMrNotify(
|
||||
@ -20,21 +25,22 @@ public class UpdateMrNotify extends MrNotify {
|
||||
String name,
|
||||
String url,
|
||||
String author,
|
||||
String projectKey,
|
||||
String projectName,
|
||||
Long allTasks,
|
||||
Long allResolvedTasks,
|
||||
Long personTasks,
|
||||
Long personResolvedTasks
|
||||
Long personResolvedTasks,
|
||||
String comment
|
||||
) {
|
||||
super(mrId, projectKey, name, url);
|
||||
super(mrId, projectName, name, url);
|
||||
this.author = author;
|
||||
this.allTasks = allTasks;
|
||||
this.allResolvedTasks = allResolvedTasks;
|
||||
this.personTasks = personTasks;
|
||||
this.personResolvedTasks = personResolvedTasks;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
|
@ -2,18 +2,21 @@ 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.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.pipeline.PipelineNotifyFields.CLASS_NAME;
|
||||
|
||||
/**
|
||||
* @author upagge 17.01.2021
|
||||
*/
|
||||
//TODO [16.12.2022|uPagge]: Нужно реализовать заполнение projectName
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public final class PipelineNotify implements Notify {
|
||||
|
||||
public static final String TYPE = "PipelineNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final Long projectId;
|
||||
private final Long pipelineId;
|
||||
|
@ -1,16 +1,20 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.project;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author upagge 15.01.2021
|
||||
*/
|
||||
@Getter
|
||||
@FieldNames
|
||||
public final class NewProjectNotify implements Notify {
|
||||
|
||||
public static final String TYPE = "NewProjectNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final Long projectId;
|
||||
private final String projectName;
|
||||
|
@ -1,19 +1,23 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.task;
|
||||
|
||||
import dev.struchkov.haiti.utils.container.Pair;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotifyFields.CLASS_NAME;
|
||||
|
||||
/**
|
||||
* @author upagge 10.09.2020
|
||||
*/
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class DiscussionNewNotify extends TaskNotify {
|
||||
|
||||
public static final String TYPE = "DiscussionNewNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String threadId;
|
||||
private final String mrName;
|
||||
|
@ -1,15 +1,19 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.task;
|
||||
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.task.TaskCloseNotifyFields.CLASS_NAME;
|
||||
|
||||
/**
|
||||
* @author upagge 10.09.2020
|
||||
*/
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class TaskCloseNotify extends TaskNotify {
|
||||
|
||||
public static final String TYPE = "TaskCloseNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final Long personTasks;
|
||||
private final Long personResolvedTasks;
|
||||
|
@ -373,6 +373,7 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
|
||||
final MergeRequestForDiscussion mergeRequest = discussion.getMergeRequest();
|
||||
DiscussionNewNotify.DiscussionNewNotifyBuilder messageBuilder = DiscussionNewNotify.builder()
|
||||
.url(firstNote.getWebUrl())
|
||||
.threadId(discussion.getId())
|
||||
.mrName(mergeRequest.getTitle())
|
||||
.authorName(firstNote.getAuthor().getName());
|
||||
@ -381,8 +382,7 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
final List<Note> notes = discussion.getNotes();
|
||||
|
||||
messageBuilder
|
||||
.discussionMessage(firstNote.getBody())
|
||||
.url(firstNote.getWebUrl());
|
||||
.discussionMessage(firstNote.getBody());
|
||||
|
||||
if (notes.size() > 1) {
|
||||
for (int i = 1; i < notes.size(); i++) {
|
||||
|
@ -283,17 +283,17 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
||||
|
||||
private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
||||
final Long botUserGitlabId = personInformation.getId();
|
||||
|
||||
if (
|
||||
!botUserGitlabId.equals(mergeRequest.getAuthor().getId()) // Автор MR не пользователь приложения
|
||||
&& !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit()) // Изменилась дата последнего коммита
|
||||
&& !mergeRequest.isConflict() // MR не находится в состоянии конфликта
|
||||
&& !botUserGitlabId.equals(oldMergeRequest.getAuthor().getId()) // и MR создан НЕ пользователем бота
|
||||
) {
|
||||
|
||||
long allTask = 0;
|
||||
long resolvedTask = 0;
|
||||
long allYouTasks = 0;
|
||||
long resolvedYouTask = 0;
|
||||
|
||||
final List<Discussion> discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId());
|
||||
for (Discussion discussion : discussions) {
|
||||
if (checkNotNull(discussion.getResponsible())) {
|
||||
@ -310,19 +310,23 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyService.send(
|
||||
UpdateMrNotify.builder()
|
||||
.mrId(oldMergeRequest.getId())
|
||||
.author(oldMergeRequest.getAuthor().getName())
|
||||
.name(oldMergeRequest.getTitle())
|
||||
.projectKey(project.getName())
|
||||
.url(oldMergeRequest.getWebUrl())
|
||||
.allTasks(allTask)
|
||||
.allResolvedTasks(resolvedTask)
|
||||
.personTasks(allYouTasks)
|
||||
.personResolvedTasks(resolvedYouTask)
|
||||
.build()
|
||||
);
|
||||
|
||||
final UpdateMrNotify.UpdateMrNotifyBuilder notifyBuilder = UpdateMrNotify.builder()
|
||||
.mrId(oldMergeRequest.getId())
|
||||
.author(oldMergeRequest.getAuthor().getName())
|
||||
.name(oldMergeRequest.getTitle())
|
||||
.projectName(project.getName())
|
||||
.url(oldMergeRequest.getWebUrl())
|
||||
.allTasks(allTask)
|
||||
.allResolvedTasks(resolvedTask)
|
||||
.personTasks(allYouTasks)
|
||||
.personResolvedTasks(resolvedYouTask);
|
||||
|
||||
if (oldMergeRequest.isConflict() && !mergeRequest.isConflict()) {
|
||||
notifyBuilder.comment("The conflict has been resolved");
|
||||
}
|
||||
|
||||
notifyService.send(notifyBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,13 @@ logging:
|
||||
level:
|
||||
"dev.struchkov": ${LOG_LEVEL:info}
|
||||
|
||||
telegram-bot:
|
||||
bot-username: ${TELEGRAM_BOT_USERNAME}
|
||||
bot-token: ${TELEGRAM_BOT_TOKEN}
|
||||
proxy-config:
|
||||
telegram:
|
||||
bot:
|
||||
username: ${TELEGRAM_BOT_USERNAME}
|
||||
token: ${TELEGRAM_BOT_TOKEN}
|
||||
autoresponder:
|
||||
threads: ${AUTORESPONDER_THREADS:8}
|
||||
proxy:
|
||||
enable: ${PROXY_ENABLE:false}
|
||||
host: ${PROXY_HOST:}
|
||||
port: ${PROXY_PORT:}
|
||||
|
4
pom.xml
4
pom.xml
@ -45,8 +45,8 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<godfather.telegram.version>0.0.50-SNAPSHOT</godfather.telegram.version>
|
||||
<haiti.utils.version>2.6.0</haiti.utils.version>
|
||||
<haiti.utils.fields.version>0.0.9</haiti.utils.fields.version>
|
||||
<haiti.utils.version>2.7.2</haiti.utils.version>
|
||||
<haiti.utils.fields.version>0.0.11</haiti.utils.fields.version>
|
||||
<haiti.filter.version>0.0.5</haiti.filter.version>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api -->
|
||||
|
@ -1,17 +1,19 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.bot.gitlab.core.config.properties.AppProperty;
|
||||
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload;
|
||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.DELETE_MESSAGE;
|
||||
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW;
|
||||
|
||||
/**
|
||||
* @author upagge 19.01.2021
|
||||
@ -39,10 +41,11 @@ public class StartNotify {
|
||||
)
|
||||
.keyBoard(
|
||||
inlineKeyBoard(
|
||||
simpleButton("Open General Menu", "/start")
|
||||
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||
simpleButton("Open Menu", "/start")
|
||||
)
|
||||
)
|
||||
.payload(BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW, true)
|
||||
.payload(DISABLE_WEB_PAGE_PREVIEW, true)
|
||||
.build();
|
||||
sending.send(boxAnswer);
|
||||
}
|
||||
|
@ -5,7 +5,15 @@ import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
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.keyboard.button.SimpleButton.simpleButton;
|
||||
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
|
||||
import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
@ -16,13 +24,23 @@ public class StatusMrNotifyGenerator implements NotifyBoxAnswerGenerator<StatusM
|
||||
|
||||
final StringBuilder builder = new StringBuilder(Icons.PEN).append(" *MergeRequest status changed*")
|
||||
.append(Icons.HR)
|
||||
.append(escapeMarkdown(notify.getTitle()))
|
||||
.append(escapeMarkdown(notify.getTitle())).append("\n\n")
|
||||
.append(notify.getOldStatus().name()).append(Icons.ARROW).append(notify.getNewStatus().name())
|
||||
.append(Icons.HR)
|
||||
.append(notify.getOldStatus().name()).append(Icons.ARROW).append(notify.getNewStatus().name());
|
||||
.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName()));
|
||||
|
||||
final String notifyMessage = builder.toString();
|
||||
|
||||
return boxAnswer(notifyMessage);
|
||||
return boxAnswer(
|
||||
notifyMessage,
|
||||
inlineKeyBoard(
|
||||
simpleLine(
|
||||
simpleButton(Icons.VIEW, DELETE_MESSAGE),
|
||||
urlButton(Icons.LINK, notify.getUrl()),
|
||||
simpleButton(Icons.DISABLE_NOTIFY, "[" + BUTTON_ARG_DISABLE_NOTIFY_MR_ID + ":" + notify.getMrId() + ";" + BUTTON_ARG_CONFIRMATION + ":" + BUTTON_VALUE_FALSE + "]")
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoard
|
||||
import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@ -27,11 +28,16 @@ public class UpdateMrNotifyGenerator implements NotifyBoxAnswerGenerator<UpdateM
|
||||
.append(Icons.HR)
|
||||
.append(notify.getTitle());
|
||||
|
||||
if (notify.getAllTasks() > 0) {
|
||||
if (checkNotBlank(notify.getComment())) {
|
||||
builder.append(Icons.HR)
|
||||
.append(notify.getComment());
|
||||
}
|
||||
|
||||
if (checkNotNull(notify.getAllTasks()) && notify.getAllTasks() > 0) {
|
||||
builder.append(Icons.HR)
|
||||
.append("All tasks: ").append(notify.getAllResolvedTasks()).append("/").append(notify.getAllTasks());
|
||||
|
||||
if (notify.getPersonTasks() > 0) {
|
||||
if (checkNotNull(notify.getPersonTasks()) && notify.getPersonTasks() > 0) {
|
||||
builder.append("\nYour tasks: ").append(notify.getPersonResolvedTasks()).append("/").append(notify.getPersonTasks());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user