diff --git a/bot-app/src/main/resources/application.yaml b/bot-app/src/main/resources/application.yaml index 547d4a2..67a1e09 100644 --- a/bot-app/src/main/resources/application.yaml +++ b/bot-app/src/main/resources/application.yaml @@ -33,10 +33,10 @@ gitlab-bot: token: ${GITLAB_PERSONAL_TOKEN} gitlab: url-project: ${GITLAB_URL}/api/v4/projects?page={0}&per_page=100 - url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened + url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened&page={1}&per_page=100 url-pull-request-close: ${GITLAB_URL} - url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/19/merge_requests/8/notes - url-pull-request: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1} + url-pull-request-comment: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}/notes + url-pull-request: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests/{1}?page={2}&per_page=100 user-url: ${GITLAB_URL}/api/v4/user users-url: ${GITLAB_URL}/api/v4/users teamcity: diff --git a/bot-app/src/main/resources/messages_en.properties b/bot-app/src/main/resources/messages_en.properties index 654e31f..f5abb55 100644 --- a/bot-app/src/main/resources/messages_en.properties +++ b/bot-app/src/main/resources/messages_en.properties @@ -4,4 +4,22 @@ ui.lang_changed=Language changed successfully ui.monitor_private_projects=Start tracking private projects? ui.monitor_project_private_success=Projects have been successfully added to tracking ui.monitor_owner_projects=Start tracking public projects that you own? -ui.setup_finished=Configuration completed successfully \ No newline at end of file +ui.setup_finished=Configuration completed successfully +ui.menu.header=This is the bot menu, select a new item +ui.menu.task=My tasks +ui.menu.mr=Merge Request +ui.menu.setting=Settings +ui.menu.add_mr=Add project +ui.menu.setting.text=This is the settings menu +ui.menu.setting.language=Language settings +ui.menu.setting.language.text=Choose your language +notify.pr.new={0} *New PullRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8} +notify.pr.forgotten={0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2}) +notify.pr.conflict={0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3}) +notify.pr.smart={0} *MergeRequest Reminder | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5} +notify.pr.state={0} *MergeRequest status changed | {7}*{1}[{2}]({3}){1}{4} {5} {6} +notify.pr.update={0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5} +notify.task.close={0} *Closed [task]({1}){2}*{3}*: {4} +notify.task.new={0} *New [task]({1}) assigned{2}*{3}*: {4} +notify.project.new={0} *New project*{1}[{2}]({3}){1}{4}{5}: {6} +notify.comment.bell={0} *New mention* | [MR]({1}){2}*{3}*: {4} \ No newline at end of file diff --git a/bot-app/src/main/resources/messages_ru.properties b/bot-app/src/main/resources/messages_ru.properties index 6c85b8f..17fb883 100644 --- a/bot-app/src/main/resources/messages_ru.properties +++ b/bot-app/src/main/resources/messages_ru.properties @@ -4,4 +4,22 @@ ui.lang_changed=Язык успешно изменен ui.monitor_private_projects=Начать отслеживать приватные проекты? ui.monitor_project_private_success=Проекты успешно добавлены в отслеживание ui.monitor_owner_projects=Начать отслеживать публичные проекты, владельцем которых вы являетесь? -ui.setup_finished=Настройка успешно завершена \ No newline at end of file +ui.setup_finished=Настройка успешно завершена +ui.menu.header=Это меню бота, выберите новый пункт +ui.menu.task=Мои задачи +ui.menu.mr=Merge Request +ui.menu.setting=Настройки +ui.menu.add_mr=Добавить проект +ui.menu.setting.text=Это меню настроек +ui.menu.setting.language=Настройки языка +ui.menu.setting.language.text=Выберете язык +notify.pr.new={0} *Новый PullRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8} +notify.pr.forgotten={0} *Напоминание о просмотре PullRequest | {4}*{3}[{1}]({2}) +notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3}) +notify.pr.smart={0} *Напоминание о MergeRequest | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5} +notify.pr.state={0} *Изменился статус MergeRequest | {7}*{1}[{2}]({3}){1}{4} {5} {6} +notify.pr.update={0} *Обновление MergeRequest | {6}*{3}[{1}]({2}){3}{4}: {5} +notify.task.close={0} *Закрыта* [задача]({1}){2}*{3}*: {4} +notify.task.new={0} *Назначена новая* [задача]({1}){2}*{3}*: {4} +notify.project.new={0} *Новый Проект*{1}[{2}]({3}){1}{4}{5}: {6} +notify.comment.bell={0} *Новое упоминание* | [MR]({1}){2}*{3}*: {4} \ No newline at end of file diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java index eadfee8..ea892a3 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java @@ -6,8 +6,12 @@ import lombok.Setter; import org.sadtech.haiti.context.domain.BasicEntity; import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @@ -18,6 +22,9 @@ import java.time.LocalDateTime; @Entity @Table(name = "note") @EqualsAndHashCode(onlyExplicitlyIncluded = true) +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type") +@DiscriminatorValue("null") public class Note implements BasicEntity { @Id diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Task.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Task.java index a2efed1..f8de498 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Task.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Task.java @@ -1,72 +1,12 @@ package org.sadtech.bot.gitlab.context.domain.entity; -import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.sadtech.bot.gitlab.context.domain.TaskStatus; -import org.sadtech.haiti.context.domain.BasicEntity; - -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import java.time.LocalDateTime; -import java.util.HashSet; -import java.util.Set; //@Entity @Getter @Setter //@Table(name = "task") -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Task implements BasicEntity { - - @Id - @Column(name = "id") - @EqualsAndHashCode.Include - private Long id; - - /** - * Описание задачи - */ - @Column(name = "description") - private String description; - - @Enumerated(EnumType.STRING) - @Column(name = "status") - private TaskStatus status; - - @Column(name = "create_date") - private LocalDateTime createDate; - - @Column(name = "pull_request_id") - private Long pullRequestId; - - @Column(name = "url") - private String url; - - @Column(name = "url_api") - private String urlApi; - - /** - * Версия объекта в битбакет - */ - @Column(name = "bitbucket_version") - private Integer bitbucketVersion; - - @Column(name = "author_login") - private String author; - - @Column(name = "responsible_login") - private String responsible; - - @ElementCollection(fetch = FetchType.EAGER) - @CollectionTable(name = "task_comments", joinColumns = @JoinColumn(name = "task_id")) - @Column(name = "comment_id") - private Set answers = new HashSet<>(); +public class Task extends Note { } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java index d3341d9..62c7539 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java @@ -3,6 +3,7 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.MessageUtils; import org.sadtech.bot.gitlab.context.utils.Smile; import org.sadtech.bot.gitlab.context.utils.UpdateDataComparator; @@ -38,7 +39,7 @@ public class GoodMorningNotify extends Notify { } @Override - public String generateMessage() { + public String generateMessage(AppSettingService settingService) { StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR); if (!mergeRequestsReviews.isEmpty()) { message.append("Необходимо проверить ").append(mergeRequestsReviews.size()).append(" ПР:").append(Smile.BR); diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/NewProjectNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/NewProjectNotify.java index 8a8857b..3efdd30 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/NewProjectNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/NewProjectNotify.java @@ -1,10 +1,9 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Builder; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - /** * // TODO: 15.01.2021 Добавить описание. * @@ -26,15 +25,12 @@ public class NewProjectNotify extends Notify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Новый Проект*{1}" + - "[{2}]({3}){1}" + - "{4}" + - "{5}: {6}\n\n", - Smile.FUN, Smile.HR, projectName, projectUrl, + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.project.new", + Smile.FUN.getValue(), Smile.HR.getValue(), projectName, projectUrl, (projectDescription != null && !"".equals(projectDescription)) ? escapeMarkdown(projectDescription) + Smile.HR : "", - Smile.AUTHOR, authorName + Smile.AUTHOR.getValue(), authorName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java index 9faa899..22054db 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java @@ -3,6 +3,7 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Getter; import lombok.NonNull; import lombok.Setter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import java.util.Set; import java.util.stream.Collectors; @@ -12,11 +13,11 @@ import java.util.stream.Stream; @Setter public abstract class Notify { - public static final Set FORBIDDEN_SYMBOLS = Stream.of( + protected static final Set FORBIDDEN_SYMBOLS = Stream.of( '\\', '+', '`', '[', ']', '\"', '~', '*', '#', '=', '_', '>', '<' ).collect(Collectors.toSet()); - public abstract String generateMessage(); + public abstract String generateMessage(AppSettingService appSettingService); public static String escapeMarkdown(@NonNull String s) { StringBuilder sb = new StringBuilder(); diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java index 066f875..d481741 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java @@ -2,6 +2,7 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; /** * // TODO: 20.09.2020 Добавить описание. @@ -19,7 +20,7 @@ public class SimpleTextNotify extends Notify { } @Override - public String generateMessage() { + public String generateMessage(AppSettingService appSettingService) { return message; } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java index 6a9c609..c2734f7 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.Answer; import org.sadtech.bot.gitlab.context.domain.notify.Notify; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; @@ -29,7 +30,7 @@ public class AnswerCommentNotify extends Notify { } @Override - public String generateMessage() { + public String generateMessage(AppSettingService settingService) { final String answerText = answers.stream() .map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500))) .collect(Collectors.joining("\n\n")); diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java index 8bd30ae..233f043 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java @@ -3,10 +3,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.comment; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.notify.Notify; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - @Getter public class CommentNotify extends Notify { @@ -26,11 +25,10 @@ public class CommentNotify extends Notify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Новое упоминание* | [ПР]({1}){2}" + - "*{3}*: {4}", - Smile.COMMENT, url, Smile.HR, authorName, escapeMarkdown(message) + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.comment.bell", + Smile.COMMENT.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(message) ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java index 15773a9..9233925 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java @@ -2,10 +2,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - @Getter public class ConflictPrNotify extends PrNotify { @@ -19,12 +18,10 @@ public class ConflictPrNotify extends PrNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Внимание конфликт в ПР | {4}*" + - "{1}" + - "[{2}]({3})\n\n", - Smile.DANGEROUS, Smile.HR, title, url, projectName + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.pr.conflict", + Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java index 1b213c1..20958d5 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java @@ -2,10 +2,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - /** * // TODO: 11.10.2020 Добавить описание. * @@ -25,11 +24,10 @@ public class ForgottenSmartPrNotify extends PrNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Напоминание о просмотре PullRequest | {4}*" + - "{3}[{1}]({2})", - Smile.SMART, title, url, Smile.HR, projectName + public String generateMessage(AppSettingService appSettingService) { + return appSettingService.getMessage( + "notify.pr.forgotten", + Smile.SMART.getValue(), title, url, Smile.HR.getValue(), projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java index 41f41b4..e29f7be 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java @@ -2,9 +2,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; import java.util.Set; import java.util.stream.Collectors; @@ -37,21 +37,28 @@ public class NewPrNotify extends PrNotify { } @Override - public String generateMessage() { + public String generateMessage(AppSettingService settingService) { String labelText = labels.stream() .map(label -> "#" + label) .collect(Collectors.joining(" ")); if (!labelText.isEmpty()) { labelText = "\n\n" + labelText; } - return MessageFormat.format( - "{0} *Новый PullRequest | {1}*{2}" + - "[{3}]({4})" + - "{5}" + - "{2}{9}: {10} {12} {11}\n{7}: {8}", - Smile.FUN, projectName, Smile.HR, title, url, labelText, + return settingService.getMessage( + "notify.pr.new", + Smile.FUN.getValue(), + projectName, + Smile.HR.getValue(), + title, + url, + labelText, (description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "", - Smile.AUTHOR, author, Smile.TREE, sourceBranch, targetBranch, Smile.ARROW + Smile.AUTHOR.getValue(), + author, + Smile.TREE.getValue(), + sourceBranch, + targetBranch, + Smile.ARROW.getValue() ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java index 2f263ca..b9a8709 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java @@ -3,10 +3,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.entity.Reviewer; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - /** * // TODO: 11.10.2020 Добавить описание. * @@ -30,13 +29,10 @@ public class SmartPrNotify extends PrNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Напоминание о PullRequest | {6}*" + - "{3}[{1}]({2})" + - "{3}" + - "{4} изменил свое решение на {5}\n\n", - Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(), + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.pr.smart", + Smile.SMART.getValue(), title, url, Smile.HR.getValue(), reviewerTriggered.getPersonLogin(), projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java index 9f23094..5365808 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java @@ -3,10 +3,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.MergeRequestState; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - @Getter public class StatusPrNotify extends PrNotify { @@ -27,12 +26,10 @@ public class StatusPrNotify extends PrNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Изменился статус PullRequest | {7}*{1}" + - "[{2}]({3}){1}" + - "{4} {5} {6}\n\n", - Smile.PEN, Smile.HR, title, url, oldStatus.name(), Smile.ARROW, newStatus.name(), projectName + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.pr.state", + Smile.PEN.getValue(), Smile.HR.getValue(), title, url, oldStatus.name(), Smile.ARROW.getValue(), newStatus.name(), projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java index ea4975d..87563fb 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java @@ -2,10 +2,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - @Getter public class UpdatePrNotify extends PrNotify { @@ -23,13 +22,10 @@ public class UpdatePrNotify extends PrNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Обновление PullRequest | {6}*{3}" + - "[{1}]({2})" + - "{3}" + - "{4}: {5}\n\n", - Smile.UPDATE, title, url, Smile.HR, Smile.AUTHOR, author, projectName + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.pr.update", + Smile.UPDATE.getValue(), title, url, Smile.HR.getValue(), Smile.AUTHOR.getValue(), author, projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java index 2851040..cedd95f 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java @@ -1,10 +1,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.task; import lombok.Builder; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - /** * // TODO: 10.09.2020 Добавить описание. * @@ -22,11 +21,10 @@ public class TaskCloseNotify extends TaskNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Закрыта* [задача]({1}){2}" + - "*{3}*: {4}", - Smile.TASK, url, Smile.HR, authorName, escapeMarkdown(messageTask) + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.task.close", + Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask) ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java index b8e87c9..b37cc0d 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java @@ -2,10 +2,9 @@ package org.sadtech.bot.gitlab.context.domain.notify.task; import lombok.Builder; import lombok.Getter; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; -import java.text.MessageFormat; - /** * // TODO: 10.09.2020 Добавить описание. * @@ -24,11 +23,10 @@ public class TaskNewNotify extends TaskNotify { } @Override - public String generateMessage() { - return MessageFormat.format( - "{0} *Назначена новая* [задача]({1}){2}" + - "*{3}*: {4}", - Smile.TASK, url, Smile.HR, authorName, escapeMarkdown(messageTask) + public String generateMessage(AppSettingService settingService) { + return settingService.getMessage( + "notify.task.new", + Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask) ); } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index 8a7c3be..c983652 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -67,9 +67,9 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService implements TaskService { - - private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); - - private final TaskRepository taskRepository; - - private final MergeRequestsService mergeRequestsService; - private final NotifyService notifyService; - private final NoteService noteService; - - private final ConversionService conversionService; - - public TaskServiceImpl( - TaskRepository taskRepository, - MergeRequestsService mergeRequestsService, - NotifyService notifyService, - NoteService noteService, - ConversionService conversionService - ) { - super(taskRepository); - this.taskRepository = taskRepository; - this.mergeRequestsService = mergeRequestsService; - this.notifyService = notifyService; - this.noteService = noteService; - this.conversionService = conversionService; - } - - @Override - public Task create(@NonNull Task task) { - Assert.isNotNull(task.getId(), "При создании объекта должен быть установлен идентификатор"); - task.getAnswers().clear(); - final Task newTask = taskRepository.save(task); - notifyNewTask(task); - notificationPersonal(task); - return newTask; - } - - @Override - public Task update(@NonNull Task task) { - final Task oldTask = taskRepository.findById(task.getId()) - .orElseThrow(() -> new NotFoundException("Задача не найдена")); - - if (!task.getBitbucketVersion().equals(oldTask.getBitbucketVersion())) { - oldTask.setDescription(task.getDescription()); - oldTask.setBitbucketVersion(task.getBitbucketVersion()); - } - updateAnswer(oldTask, task); - updateStatus(oldTask, task); - oldTask.setStatus(task.getStatus()); - return taskRepository.save(oldTask); - } - - private void updateStatus(Task oldTask, Task task) { - final TaskStatus oldStatus = oldTask.getStatus(); - final TaskStatus newStatus = task.getStatus(); - if (!oldStatus.equals(newStatus)) { - switch (newStatus) { - case OPEN: - notifyService.send( - TaskNewNotify.builder() - .messageTask(task.getDescription()) - .authorName(oldTask.getAuthor()) - .url(oldTask.getUrl()) - .build() - ); - break; - case RESOLVED: - notifyService.send( - TaskCloseNotify.builder() - .messageTask(oldTask.getDescription()) - .authorName(oldTask.getAuthor()) - .url(oldTask.getUrl()) - .build() - ); - break; - default: - throw new NotFoundException("Обработчика типа не существует"); - } - oldTask.setStatus(newStatus); - } - } - - private void updateAnswer(Task oldTask, Task task) { -// final Set oldAnswerIds = oldTask.getAnswers(); -// final Set newAnswerIds = task.getAnswers(); -// if (!oldAnswerIds.equals(newAnswerIds)) { -// final Set existsNewAnswersIds = noteService.existsById(newAnswerIds); -// final List newAnswers = noteService.getAllById(existsNewAnswersIds).stream() -// .filter(comment -> !oldAnswerIds.contains(comment.getId())) -// .collect(Collectors.toList()); -// oldTask.getAnswers().clear(); -// oldTask.setAnswers(existsNewAnswersIds); -// if (!newAnswers.isEmpty()) { -// notifyService.send( -// AnswerCommentNotify.builder() -// .url(oldTask.getUrl()) -// .youMessage(oldTask.getDescription()) -// .answers( -// newAnswers.stream() -// .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage())) -// .collect(Collectors.toList()) -// ) -// .build() -// ); -// } +//public class TaskServiceImpl extends AbstractSimpleManagerService implements TaskService { +// +// private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); +// +// private final TaskRepository taskRepository; +// +// private final MergeRequestsService mergeRequestsService; +// private final NotifyService notifyService; +// private final NoteService noteService; +// +// private final ConversionService conversionService; +// +// public TaskServiceImpl( +// TaskRepository taskRepository, +// MergeRequestsService mergeRequestsService, +// NotifyService notifyService, +// NoteService noteService, +// ConversionService conversionService +// ) { +// super(taskRepository); +// this.taskRepository = taskRepository; +// this.mergeRequestsService = mergeRequestsService; +// this.notifyService = notifyService; +// this.noteService = noteService; +// this.conversionService = conversionService; +// } +// +// @Override +// public Task create(@NonNull Task task) { +// Assert.isNotNull(task.getId(), "При создании объекта должен быть установлен идентификатор"); +// task.getAnswers().clear(); +// final Task newTask = taskRepository.save(task); +// notifyNewTask(task); +// notificationPersonal(task); +// return newTask; +// } +// +// @Override +// public Task update(@NonNull Task task) { +// final Task oldTask = taskRepository.findById(task.getId()) +// .orElseThrow(() -> new NotFoundException("Задача не найдена")); +// +// if (!task.getBitbucketVersion().equals(oldTask.getBitbucketVersion())) { +// oldTask.setDescription(task.getDescription()); +// oldTask.setBitbucketVersion(task.getBitbucketVersion()); // } - } - - @Override - public Long getLastTaskId() { - return taskRepository.findFirstByOrderByIdDesc().map(Task::getId).orElse(0L); - } - - @Override - public Task convert(@NonNull Note note) { - noteService.deleteById(note.getId()); - final Task task = conversionService.convert(note, Task.class); - final Task newTask = taskRepository.save(task); - notifyNewTask(newTask); - return newTask; - } - - @Override - public List getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { - return taskRepository.findByCreateDateBetween(dateFrom, dateTo); - } - - @Override - public List getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus status) { - return taskRepository.findAllByResponsibleAndStatus(login, status); - } - - private void notifyNewTask(Task task) { - final MergeRequest mergeRequest = mergeRequestsService.getById(task.getPullRequestId()) - .orElseThrow(() -> new NotFoundException("ПР не найден")); - - notifyService.send( - TaskNewNotify.builder() - .authorName(task.getAuthor()) - .messageTask(task.getDescription()) - .url(task.getUrl()) -// .recipients(Collections.singleton(mergeRequest.getAuthor().getId())) - .build() - ); - } - - private void notificationPersonal(@NonNull Task task) { - Matcher matcher = PATTERN.matcher(task.getDescription()); - Set recipientsLogins = new HashSet<>(); - while (matcher.find()) { - final String login = matcher.group(0).replace("@", ""); - recipientsLogins.add(login); - } - notifyService.send( - CommentNotify.builder() - .authorName(task.getAuthor()) - .url(task.getUrl()) - .message(task.getDescription()) - .build() - ); - } - - @Override - public void deleteById(@NonNull Long id) { - super.deleteById(id); - } - - @Override - public ExistsContainer existsById(@NonNull Collection collection) { - return null; - } - -} +// updateAnswer(oldTask, task); +// updateStatus(oldTask, task); +// oldTask.setStatus(task.getStatus()); +// return taskRepository.save(oldTask); +// } +// +// private void updateStatus(Task oldTask, Task task) { +// final TaskStatus oldStatus = oldTask.getStatus(); +// final TaskStatus newStatus = task.getStatus(); +// if (!oldStatus.equals(newStatus)) { +// switch (newStatus) { +// case OPEN: +// notifyService.send( +// TaskNewNotify.builder() +// .messageTask(task.getDescription()) +// .authorName(oldTask.getAuthor()) +// .url(oldTask.getUrl()) +// .build() +// ); +// break; +// case RESOLVED: +// notifyService.send( +// TaskCloseNotify.builder() +// .messageTask(oldTask.getDescription()) +// .authorName(oldTask.getAuthor()) +// .url(oldTask.getUrl()) +// .build() +// ); +// break; +// default: +// throw new NotFoundException("Обработчика типа не существует"); +// } +// oldTask.setStatus(newStatus); +// } +// } +// +// private void updateAnswer(Task oldTask, Task task) { +//// final Set oldAnswerIds = oldTask.getAnswers(); +//// final Set newAnswerIds = task.getAnswers(); +//// if (!oldAnswerIds.equals(newAnswerIds)) { +//// final Set existsNewAnswersIds = noteService.existsById(newAnswerIds); +//// final List newAnswers = noteService.getAllById(existsNewAnswersIds).stream() +//// .filter(comment -> !oldAnswerIds.contains(comment.getId())) +//// .collect(Collectors.toList()); +//// oldTask.getAnswers().clear(); +//// oldTask.setAnswers(existsNewAnswersIds); +//// if (!newAnswers.isEmpty()) { +//// notifyService.send( +//// AnswerCommentNotify.builder() +//// .url(oldTask.getUrl()) +//// .youMessage(oldTask.getDescription()) +//// .answers( +//// newAnswers.stream() +//// .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage())) +//// .collect(Collectors.toList()) +//// ) +//// .build() +//// ); +//// } +//// } +// } +// +// @Override +// public Long getLastTaskId() { +// return taskRepository.findFirstByOrderByIdDesc().map(Task::getId).orElse(0L); +// } +// +// @Override +// public Task convert(@NonNull Note note) { +// noteService.deleteById(note.getId()); +// final Task task = conversionService.convert(note, Task.class); +// final Task newTask = taskRepository.save(task); +// notifyNewTask(newTask); +// return newTask; +// } +// +// @Override +// public List getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) { +// return taskRepository.findByCreateDateBetween(dateFrom, dateTo); +// } +// +// @Override +// public List getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus status) { +// return taskRepository.findAllByResponsibleAndStatus(login, status); +// } +// +// private void notifyNewTask(Task task) { +// final MergeRequest mergeRequest = mergeRequestsService.getById(task.getPullRequestId()) +// .orElseThrow(() -> new NotFoundException("ПР не найден")); +// +// notifyService.send( +// TaskNewNotify.builder() +// .authorName(task.getAuthor()) +// .messageTask(task.getDescription()) +// .url(task.getUrl()) +//// .recipients(Collections.singleton(mergeRequest.getAuthor().getId())) +// .build() +// ); +// } +// +// private void notificationPersonal(@NonNull Task task) { +// Matcher matcher = PATTERN.matcher(task.getDescription()); +// Set recipientsLogins = new HashSet<>(); +// while (matcher.find()) { +// final String login = matcher.group(0).replace("@", ""); +// recipientsLogins.add(login); +// } +// notifyService.send( +// CommentNotify.builder() +// .authorName(task.getAuthor()) +// .url(task.getUrl()) +// .message(task.getDescription()) +// .build() +// ); +// } +// +// @Override +// public void deleteById(@NonNull Long id) { +// super.deleteById(id); +// } +// +// @Override +// public ExistsContainer existsById(@NonNull Collection collection) { +// return null; +// } +// +//} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java index b802898..5f4d63e 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/MergeRequestParser.java @@ -65,40 +65,48 @@ public class MergeRequestParser { public void parsingNewMergeRequest() { int page = 0; - Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); + while (projectSheet.hasContent()) { final List projects = projectSheet.getContent(); for (Project project : projects) { - final List mergeRequestJsons = HttpParse.request( - MessageFormat.format(gitlabProperty.getUrlPullRequestOpen(), project.getId()) - ) - .header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken())) - .header(ACCEPT) - .executeList(MergeRequestJson.class); - - if (!mergeRequestJsons.isEmpty()) { - - final Set jsonIds = mergeRequestJsons.stream() - .map(MergeRequestJson::getId) - .collect(Collectors.toSet()); - - final ExistsContainer existsContainer = mergeRequestsService.existsById(jsonIds); - if (!existsContainer.isAllFound()) { - final List newMergeRequests = mergeRequestJsons.stream() - .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) - .map(json -> conversionService.convert(json, MergeRequest.class)) - .collect(Collectors.toList()); - mergeRequestsService.createAll(newMergeRequests); - } - } + projectProcessing(project); } projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT)); } + } + private void projectProcessing(Project project) { + int page = 1; + List mergeRequestJsons = getMergeRequestJsons(project, page); + + while (!mergeRequestJsons.isEmpty()) { + + final Set jsonIds = mergeRequestJsons.stream() + .map(MergeRequestJson::getId) + .collect(Collectors.toSet()); + + final ExistsContainer existsContainer = mergeRequestsService.existsById(jsonIds); + if (!existsContainer.isAllFound()) { + final List newMergeRequests = mergeRequestJsons.stream() + .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .map(json -> conversionService.convert(json, MergeRequest.class)) + .collect(Collectors.toList()); + mergeRequestsService.createAll(newMergeRequests); + } + + mergeRequestJsons = getMergeRequestJsons(project, page++); + } + } + + private List getMergeRequestJsons(Project project, int page) { + return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestOpen(), project.getId(), page)) + .header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken())) + .header(ACCEPT) + .executeList(MergeRequestJson.class); } } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java index b6aba65..6ee857a 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java @@ -15,6 +15,7 @@ import org.springframework.core.convert.ConversionService; import java.text.MessageFormat; import java.util.List; +import java.util.stream.Collectors; import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT; import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION; @@ -62,7 +63,10 @@ public class NoteParser { final List noteJsons = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequestComment(), mergeRequest.getProjectId(), mergeRequest.getTwoId())) .header(ACCEPT) .header(AUTHORIZATION, BEARER + personProperty.getToken()) - .executeList(NoteJson.class); + .executeList(NoteJson.class) + .stream() + .filter(noteJson -> !noteJson.isSystem()) + .collect(Collectors.toList()); } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/ProjectParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/ProjectParser.java index 275d228..372e5bb 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/ProjectParser.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/ProjectParser.java @@ -57,7 +57,7 @@ public class ProjectParser { } private void parseProjects(String param) { - int page = 0; + int page = 1; List projectJsons = getProjectJsons(page, param); while (!projectJsons.isEmpty()) { diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java index 18f8ea7..8ef1736 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java @@ -3,6 +3,7 @@ package org.sadtech.bot.gitlab.teamcity.core.domain; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.notify.Notify; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.utils.Smile; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.BuildShort; import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus; @@ -25,7 +26,7 @@ public class TeamcityBuildNotify extends Notify { } @Override - public String generateMessage() { + public String generateMessage(AppSettingService appSettingService) { return MessageFormat.format( "{0} *Сборка* | {1,number,#}:{2,number,#} | {3}" + "{4} [{5}]({6}) {4}" + diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/MessageSendTelegramService.java index 7033da0..63125e5 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -4,6 +4,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.PersonInformation; import org.sadtech.bot.gitlab.context.domain.notify.Notify; +import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.service.MessageSendService; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.service.sender.Sending; @@ -21,10 +22,11 @@ public class MessageSendTelegramService implements MessageSendService { private final Sending sending; private final PersonInformation personInformation; + private final AppSettingService settingService; @Override public void send(@NonNull Notify notify) { - sending.send(personInformation.getTelegramId(), BoxAnswer.of(notify.generateMessage())); + sending.send(personInformation.getTelegramId(), BoxAnswer.of(notify.generateMessage(settingService))); } } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java index e00f61b..8c1c394 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/TaskProcessing.java @@ -7,8 +7,6 @@ import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.ProcessingData; import org.sadtech.social.core.domain.content.Message; -import java.text.MessageFormat; - /** * // TODO: 17.09.2020 Добавить описание. * @@ -42,10 +40,11 @@ public class TaskProcessing implements ProcessingData { } private String createTaskString(Task task) { - return MessageFormat.format( - "- [{0}]({1})", - task.getDescription(), task.getUrl() - ); +// return MessageFormat.format( +// "- [{0}]({1})", +// task.getDescription(), task.getUrl() +// ); + return null; } } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java new file mode 100644 index 0000000..3954596 --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/MenuConfig.java @@ -0,0 +1,114 @@ +package org.sadtech.bot.gitlab.telegram.unit; + +import org.sadtech.bot.gitlab.context.domain.AppLocale; +import org.sadtech.bot.gitlab.context.service.AppSettingService; +import org.sadtech.social.bot.domain.unit.AnswerText; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.keyboard.KeyBoard; +import org.sadtech.social.core.domain.keyboard.KeyBoardLine; +import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText; +import org.sadtech.social.core.utils.KeyBoards; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * // TODO: 16.01.2021 Добавить описание. + * + * @author upagge 16.01.2021 + */ +@Configuration +public class MenuConfig { + + @Bean + public AnswerText menu( + AppSettingService settingService, + AnswerText settings + ) { + return AnswerText.builder() + .boxAnswer(message -> + { + + final KeyBoardButtonText newMr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.add_mr")).build(); + final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.task")).build(); + final KeyBoardButtonText pr = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.mr")).build(); + final KeyBoardButtonText settingsKeyBoard = KeyBoardButtonText.builder().label(settingService.getMessage("ui.menu.setting")).build(); + + final KeyBoardLine oneLine = KeyBoardLine.builder() + .buttonKeyBoard(newMr) + .build(); + + final KeyBoardLine twoLine = KeyBoardLine.builder() + .buttonKeyBoard(tasks) + .buttonKeyBoard(pr) + .build(); + + final KeyBoardLine threeLine = KeyBoardLine.builder() + .buttonKeyBoard(settingsKeyBoard) + .build(); + + final KeyBoard keyBoard = KeyBoard.builder() + .lineKeyBoard(oneLine) + .lineKeyBoard(twoLine) + .lineKeyBoard(threeLine) + .build(); + + return BoxAnswer.builder() + .message(settingService.getMessage("ui.menu.header")) + .keyBoard(keyBoard) + .build(); + } + ) + .nextUnit(settings) + .build(); + } + + @Bean + public AnswerText settings( + AppSettingService settingService, + AnswerText settingsLanguage + ) { + return AnswerText.builder() + .boxAnswer(message -> + BoxAnswer.builder() + .message(settingService.getMessage("ui.menu.setting.text")) + .keyBoard(KeyBoards.verticalMenuString(settingService.getMessage("ui.menu.setting.language"))) + .build()) + .phrase(settingService.getMessage("ui.menu.setting")) + .nextUnit(settingsLanguage) + .build(); + } + + @Bean + public AnswerText settingsLanguage( + AppSettingService settingService, + AnswerText setLanguage + ) { + return AnswerText.builder() + .boxAnswer(message -> + BoxAnswer.builder() + .message(settingService.getMessage("ui.menu.setting.language.text")) + .keyBoard(KeyBoards.verticalDuoMenuString("Русский", "English")) + .build()) + .nextUnit(setLanguage) + .phrase(settingService.getMessage("ui.menu.setting.language")) + .build(); + } + + @Bean + public AnswerText setLanguage( + AppSettingService settingService + ) { + return AnswerText.builder() + .boxAnswer( + message -> { + final AppLocale appLocale = AppLocale.of(message.getText()); + settingService.setLocale(appLocale); + return BoxAnswer.of( + settingService.getMessage("ui.lang_changed") + ); + } + ) + .build(); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/NotifySettingUnit.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/NotifySettingUnit.java deleted file mode 100644 index ff9fb66..0000000 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/NotifySettingUnit.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.sadtech.bot.gitlab.telegram.unit; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.springframework.context.annotation.Configuration; - -/** - * // TODO: 20.09.2020 Добавить описание. - * - * @author upagge 20.09.2020 - */ -@Configuration -@RequiredArgsConstructor -public class NotifySettingUnit { - - private final NotifyService notifyService; - -// @Bean -// public AnswerText notifySetting( -// AnswerProcessing disableNotifications -// ) { -// return AnswerText.builder() -// .boxAnswer( -// BoxAnswer.builder() -// .message("Вы можете полностью остановить уведомления от бота") -// .keyBoard( -// KeyBoards.verticalDuoMenuString( -// Arrays.stream(DisableMenu.values()) -// .map(DisableMenu::getName) -// .collect(Collectors.toList()) -// ) -// ) -// .build() -// ) -// .phrase("Уведомления") -// .nextUnit(disableNotifications) -// .build(); -// } - -// @Bean -// public AnswerProcessing disableNotifications() { -// return AnswerProcessing.builder() -// .processingData( -// message -> { -// final Person person = personService.getByTelegramId(message.getPersonId()) -// .orElseThrow(() -> new NotFoundException("Не найдено")); -// final NotifySetting notifySetting = notifyService.getSetting(person.getLogin()) -// .orElseThrow(() -> new NotFoundException("Не найдено")); -// notifySetting.setStartReceiving( -// LocalDateTime.now().plusMinutes(DisableMenu.from(message.getText()).getMinutes()) -// ); -// notifyService.saveSettings(notifySetting); -// return BoxAnswer.of("Настройки сохранены"); -// return null; -// } -// ) -// .build(); -// } - -// @Getter -// @RequiredArgsConstructor -// private enum DisableMenu { -// -// TURN_ON("Включить", 0), -// TURN_OFF("Выключить", 525600), -// DISABLE_15_MIN("15 мин", 15), -// DISABLE_2_HOUR("2 часа", 120), -// DISABLE_30_MIN("30 мин", 30), -// DISABLE_4_HOUR("4 часа", 240), -// DISABLE_60_MIN("60 мин", 60), -// DISABLE_8_HOUR("8 часов", 480); -// -// private final String name; -// private final int minutes; -// -// public static DisableMenu from(@NonNull String name) { -// return Arrays.stream(DisableMenu.values()) -// .filter(disableMenu -> disableMenu.getName().equals(name)) -// .findFirst() -// .orElseThrow(() -> new NotFoundException("Не найдено")); -// } -// -// } - -} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java index 32ab06f..1907cc3 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java @@ -25,12 +25,14 @@ public class UnitConfig { @Bean public AnswerCheck checkFirstStart( AppSettingService settingService, - AnswerText textCheckLanguage + AnswerText textCheckLanguage, + AnswerText menu ) { return AnswerCheck.builder() .check( message -> settingService.isFirstStart() ) + .unitFalse(menu) .unitTrue(textCheckLanguage) .build(); } diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java index 986e256..8eb7ec5 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/utils/GeneratorKeyBoards.java @@ -1,43 +1,14 @@ package org.sadtech.bot.gitlab.telegram.utils; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.sadtech.social.core.domain.keyboard.KeyBoard; -import org.sadtech.social.core.domain.keyboard.KeyBoardLine; -import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText; +import org.springframework.context.annotation.Configuration; /** * // TODO: 20.09.2020 Добавить описание. * * @author upagge 20.09.2020 */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) +@Configuration public class GeneratorKeyBoards { - public static KeyBoard menu() { - final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label("Мои задачи").build(); - final KeyBoardButtonText pr = KeyBoardButtonText.builder().label("Pull Requests").build(); - final KeyBoardButtonText top = KeyBoardButtonText.builder().label("\uD83C\uDF1F Таблица рейтинга \uD83C\uDF1F").build(); - final KeyBoardButtonText settings = KeyBoardButtonText.builder().label("Настройки").build(); - - final KeyBoardLine oneLine = KeyBoardLine.builder() - .buttonKeyBoard(tasks) - .buttonKeyBoard(pr) - .build(); - - final KeyBoardLine twoLine = KeyBoardLine.builder() - .buttonKeyBoard(top) - .build(); - - final KeyBoardLine threeLine = KeyBoardLine.builder() - .buttonKeyBoard(settings) - .build(); - - return KeyBoard.builder() - .lineKeyBoard(oneLine) - .lineKeyBoard(twoLine) - .lineKeyBoard(threeLine) - .build(); - } }