From 8b0fadc1f7c21a59e2ff7b8a97a20fc6dd575c80 Mon Sep 17 00:00:00 2001 From: upagge Date: Fri, 18 Sep 2020 08:34:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bitbucket-app/pom.xml | 3 + .../{ => app}/BitbucketbotApplication.java | 2 +- .../exception/BitbucketAppException.java | 2 +- .../{ => app}/exception/ConvertException.java | 2 +- .../scheduler/CommentAndTaskScheduler.java | 4 +- .../{ => app}/scheduler/PersonScheduler.java | 4 +- .../scheduler/PullRequestParserScheduler.java | 2 +- .../service/CommentAndTaskParser.java | 4 +- .../{ => app}/service/ExecutorScanner.java | 8 +-- .../converter/CommentJsonToComment.java | 2 +- .../converter/CommentJsonToTaskConvert.java | 4 +- .../converter/PullRequestJsonConverter.java | 4 +- .../service/converter/UserJsonConverter.java | 2 +- .../{ => app}/service/executor/DataScan.java | 2 +- .../{ => app}/service/executor/Executor.java | 2 +- .../service/executor/ResultScan.java | 2 +- .../{ => app}/service/executor/Seeker.java | 2 +- .../service/parser/PersonBitbucketParser.java | 2 +- .../parser/PullRequestBitbucketParser.java | 2 +- .../bitbucket/{ => app}/utils/Converter.java | 2 +- .../src/main/resources/application-dev.yaml | 8 +-- .../src/main/resources/application-prod.yaml | 8 +-- .../src/main/resources/application.yaml | 4 +- bitbucket-app/src/main/resources/logback.xml | 2 +- .../bot/vcs/core/domain/ReviewerStatus.java | 8 +-- .../change/pullrequest/NewPrChange.java | 10 ++- .../change/pullrequest/StatusPrChange.java | 6 +- .../vcs/core/repository/PersonRepository.java | 2 + .../vcs/core/repository/TaskRepository.java | 4 ++ .../repository/impl/PersonRepositoryImpl.java | 5 ++ .../repository/impl/TaskRepositoryImpl.java | 7 ++ .../repository/jpa/PersonJpaRepository.java | 3 + .../repository/jpa/TaskRepositoryJpa.java | 3 + .../bot/vcs/core/service/PersonService.java | 4 ++ .../vcs/core/service/PullRequestsService.java | 8 ++- .../bot/vcs/core/service/TaskService.java | 3 + .../core/service/impl/PersonServiceImpl.java | 10 +++ .../core/service/impl/TaskServiceImpl.java | 5 ++ .../org/sadtech/bot/vcs/core/utils/Smile.java | 2 +- .../telegram/config/TelegramBotConfig.java | 16 +++-- .../service/MessageSendTelegramService.java | 3 +- .../service/MessageSendTestService.java | 3 +- .../telegram/service/ReplaceUrlLocalhost.java | 19 ++++++ .../service/unit/PullRequestProcessing.java | 62 +++++++++++++++++ .../telegram/service/unit/TaskProcessing.java | 58 ++++++++++++++++ .../bot/vcs/telegram/unit/UnitConfig.java | 67 ++++++++++++++++++- 46 files changed, 322 insertions(+), 65 deletions(-) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/BitbucketbotApplication.java (93%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/exception/BitbucketAppException.java (82%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/exception/ConvertException.java (81%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/scheduler/CommentAndTaskScheduler.java (84%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/scheduler/PersonScheduler.java (76%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/scheduler/PullRequestParserScheduler.java (93%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/CommentAndTaskParser.java (98%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/ExecutorScanner.java (88%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/converter/CommentJsonToComment.java (95%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/converter/CommentJsonToTaskConvert.java (92%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/converter/PullRequestJsonConverter.java (96%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/converter/UserJsonConverter.java (89%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/executor/DataScan.java (68%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/executor/Executor.java (73%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/executor/ResultScan.java (83%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/executor/Seeker.java (93%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/parser/PersonBitbucketParser.java (97%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/service/parser/PullRequestBitbucketParser.java (99%) rename bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/{ => app}/utils/Converter.java (93%) create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/ReplaceUrlLocalhost.java create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/TaskProcessing.java diff --git a/bitbucket-app/pom.xml b/bitbucket-app/pom.xml index 3756a8e..f09c5fc 100644 --- a/bitbucket-app/pom.xml +++ b/bitbucket-app/pom.xml @@ -59,6 +59,9 @@ org.springframework.boot spring-boot-maven-plugin + + bitbucketbot + diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/BitbucketbotApplication.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java similarity index 93% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/BitbucketbotApplication.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java index d6392e5..cae8a5f 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/BitbucketbotApplication.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket; +package org.sadtech.bot.vcs.bitbucket.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/BitbucketAppException.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/BitbucketAppException.java similarity index 82% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/BitbucketAppException.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/BitbucketAppException.java index 65a1a72..1804b47 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/BitbucketAppException.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/BitbucketAppException.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.exception; +package org.sadtech.bot.vcs.bitbucket.app.exception; /** * // TODO: 16.09.2020 Добавить описание. diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/ConvertException.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/ConvertException.java similarity index 81% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/ConvertException.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/ConvertException.java index 75d0591..240796a 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/exception/ConvertException.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/exception/ConvertException.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.exception; +package org.sadtech.bot.vcs.bitbucket.app.exception; /** * // TODO: 16.09.2020 Добавить описание. diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/CommentAndTaskScheduler.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java similarity index 84% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/CommentAndTaskScheduler.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java index 14facbf..ac59a96 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/CommentAndTaskScheduler.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java @@ -1,7 +1,7 @@ -package org.sadtech.bot.vcs.bitbucket.scheduler; +package org.sadtech.bot.vcs.bitbucket.app.scheduler; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.bitbucket.service.CommentAndTaskParser; +import org.sadtech.bot.vcs.bitbucket.app.service.CommentAndTaskParser; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PersonScheduler.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java similarity index 76% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PersonScheduler.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java index e0d797d..667f3e1 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PersonScheduler.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java @@ -1,7 +1,7 @@ -package org.sadtech.bot.vcs.bitbucket.scheduler; +package org.sadtech.bot.vcs.bitbucket.app.scheduler; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.bitbucket.service.parser.PersonBitbucketParser; +import org.sadtech.bot.vcs.bitbucket.app.service.parser.PersonBitbucketParser; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PullRequestParserScheduler.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java similarity index 93% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PullRequestParserScheduler.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java index de4a84b..e8d40a9 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/scheduler/PullRequestParserScheduler.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.scheduler; +package org.sadtech.bot.vcs.bitbucket.app.scheduler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/CommentAndTaskParser.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java similarity index 98% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/CommentAndTaskParser.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java index df997c0..911e2c7 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/CommentAndTaskParser.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java @@ -1,12 +1,12 @@ -package org.sadtech.bot.vcs.bitbucket.service; +package org.sadtech.bot.vcs.bitbucket.app.service; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.sadtech.basic.context.page.Sheet; import org.sadtech.basic.core.page.PaginationImpl; +import org.sadtech.bot.vcs.bitbucket.app.service.executor.DataScan; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; -import org.sadtech.bot.vcs.bitbucket.service.executor.DataScan; import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty; import org.sadtech.bot.vcs.core.config.properties.CommentSchedulerProperty; import org.sadtech.bot.vcs.core.config.properties.InitProperty; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/ExecutorScanner.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java similarity index 88% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/ExecutorScanner.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java index 4d78e30..da62712 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/ExecutorScanner.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java @@ -1,12 +1,12 @@ -package org.sadtech.bot.vcs.bitbucket.service; +package org.sadtech.bot.vcs.bitbucket.app.service; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.sadtech.bot.vcs.bitbucket.app.service.executor.DataScan; +import org.sadtech.bot.vcs.bitbucket.app.service.executor.Executor; +import org.sadtech.bot.vcs.bitbucket.app.service.executor.Seeker; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; -import org.sadtech.bot.vcs.bitbucket.service.executor.DataScan; -import org.sadtech.bot.vcs.bitbucket.service.executor.Executor; -import org.sadtech.bot.vcs.bitbucket.service.executor.Seeker; import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty; import org.springframework.stereotype.Service; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToComment.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToComment.java similarity index 95% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToComment.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToComment.java index 9c82295..5f37c89 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToComment.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToComment.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.converter; +package org.sadtech.bot.vcs.bitbucket.app.service.converter; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToTaskConvert.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToTaskConvert.java similarity index 92% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToTaskConvert.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToTaskConvert.java index 3b167c8..60da80a 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/CommentJsonToTaskConvert.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/CommentJsonToTaskConvert.java @@ -1,6 +1,6 @@ -package org.sadtech.bot.vcs.bitbucket.service.converter; +package org.sadtech.bot.vcs.bitbucket.app.service.converter; -import org.sadtech.bot.vcs.bitbucket.exception.ConvertException; +import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/PullRequestJsonConverter.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/PullRequestJsonConverter.java similarity index 96% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/PullRequestJsonConverter.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/PullRequestJsonConverter.java index 4a67a97..92e7c1c 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/PullRequestJsonConverter.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/PullRequestJsonConverter.java @@ -1,7 +1,7 @@ -package org.sadtech.bot.vcs.bitbucket.service.converter; +package org.sadtech.bot.vcs.bitbucket.app.service.converter; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.bitbucket.exception.ConvertException; +import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Outcome; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Properties; import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/UserJsonConverter.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/UserJsonConverter.java similarity index 89% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/UserJsonConverter.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/UserJsonConverter.java index e8846c0..aa08972 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/converter/UserJsonConverter.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/converter/UserJsonConverter.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.converter; +package org.sadtech.bot.vcs.bitbucket.app.service.converter; import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson; import org.sadtech.bot.vcs.core.domain.entity.Person; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/DataScan.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java similarity index 68% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/DataScan.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java index 7429399..1a32fbd 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/DataScan.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.executor; +package org.sadtech.bot.vcs.bitbucket.app.service.executor; import lombok.Data; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Executor.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java similarity index 73% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Executor.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java index 4bf8692..894c22f 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Executor.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.executor; +package org.sadtech.bot.vcs.bitbucket.app.service.executor; import lombok.NonNull; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/ResultScan.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java similarity index 83% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/ResultScan.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java index 8468cf6..fafadaa 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/ResultScan.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.executor; +package org.sadtech.bot.vcs.bitbucket.app.service.executor; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Seeker.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java similarity index 93% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Seeker.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java index 82e27dd..a9fc1a8 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/executor/Seeker.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.executor; +package org.sadtech.bot.vcs.bitbucket.app.service.executor; import lombok.RequiredArgsConstructor; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PersonBitbucketParser.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java similarity index 97% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PersonBitbucketParser.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java index 1a57e4e..6194617 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PersonBitbucketParser.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.parser; +package org.sadtech.bot.vcs.bitbucket.app.service.parser; import lombok.RequiredArgsConstructor; import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PullRequestBitbucketParser.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java similarity index 99% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PullRequestBitbucketParser.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java index 7f6d226..f3b9003 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/service/parser/PullRequestBitbucketParser.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.service.parser; +package org.sadtech.bot.vcs.bitbucket.app.service.parser; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/utils/Converter.java b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/utils/Converter.java similarity index 93% rename from bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/utils/Converter.java rename to bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/utils/Converter.java index 4d272be..486d498 100644 --- a/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/utils/Converter.java +++ b/bitbucket-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/utils/Converter.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.utils; +package org.sadtech.bot.vcs.bitbucket.app.utils; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/bitbucket-app/src/main/resources/application-dev.yaml b/bitbucket-app/src/main/resources/application-dev.yaml index 242ebbe..bf3e7ab 100644 --- a/bitbucket-app/src/main/resources/application-dev.yaml +++ b/bitbucket-app/src/main/resources/application-dev.yaml @@ -24,12 +24,10 @@ bitbucketbot: no-comment-count: 20 comment-count: 100 init: - start-comment-id: 7807 - use: true - server-send: - url: http://188.225.35.149:8080/api/send + start-comment-id: 7914 + use: false bitbucket: - token: Nzg5NjUyNDQwMzk2OlA+6naQz02+GxOG0Q9li/jnsn7E + token: ${BITBUCKET_ADMIN_TOKEN} url-pull-request-open: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN url-pull-request-close: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 url-pull-request-comment: http://192.168.236.164:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} diff --git a/bitbucket-app/src/main/resources/application-prod.yaml b/bitbucket-app/src/main/resources/application-prod.yaml index 3e87a56..00a8b35 100644 --- a/bitbucket-app/src/main/resources/application-prod.yaml +++ b/bitbucket-app/src/main/resources/application-prod.yaml @@ -18,18 +18,16 @@ spring: non_contextual_creation: true bitbucketbot: scheduler: - person: 0 */1 * * * * + person: 0 0 0 */1 * * comment: settings: no-comment-count: 20 comment-count: 100 init: start-comment-id: 7807 - use: true - server-send: - url: http://188.225.35.149:8080/api/send + use: false bitbucket: - token: Nzg5NjUyNDQwMzk2OlA+6naQz02+GxOG0Q9li/jnsn7E + token: ${BITBUCKET_ADMIN_TOKEN} url-pull-request-open: http://localhost:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN url-pull-request-close: http://localhost:7990/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 url-pull-request-comment: http://localhost:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} diff --git a/bitbucket-app/src/main/resources/application.yaml b/bitbucket-app/src/main/resources/application.yaml index d43e964..7ccb652 100644 --- a/bitbucket-app/src/main/resources/application.yaml +++ b/bitbucket-app/src/main/resources/application.yaml @@ -1,5 +1,5 @@ server: port: 8018 telegram-config: - bot-username: tsc_test_two_bot - bot-token: 1304335862:AAFXGxRkTZBiL9Gjce_oFoP2cOn7j8qEwDI \ No newline at end of file + bot-username: ${TELEGRAM_BOT_USERNAME} + bot-token: ${TELEGRAM_BOT_TOKEN} \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/logback.xml b/bitbucket-app/src/main/resources/logback.xml index e106cf3..0335154 100644 --- a/bitbucket-app/src/main/resources/logback.xml +++ b/bitbucket-app/src/main/resources/logback.xml @@ -18,7 +18,7 @@ - + \ No newline at end of file diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/ReviewerStatus.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/ReviewerStatus.java index cb96db2..f9b4c14 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/ReviewerStatus.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/ReviewerStatus.java @@ -10,11 +10,11 @@ import lombok.Getter; @Getter public enum ReviewerStatus { - NEEDS_WORK("'NEEDS WORK'"), - APPROVED("'APPROVED'"), - UNAPPROVED("'UNAPPROVED'"); + NEEDS_WORK("NEEDS WORK"), + APPROVED("APPROVED"), + UNAPPROVED("UNAPPROVED"); - private String value; + private final String value; ReviewerStatus(String value) { this.value = value; diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/NewPrChange.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/NewPrChange.java index 9133201..9a5f2b1 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/NewPrChange.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/NewPrChange.java @@ -31,12 +31,10 @@ public class NewPrChange extends PrChange { @Override public String generateMessage() { return MessageFormat.format( - "{0} *Новый Pull Request*\n" + - "[{1}]({2})" + - "{3}\n" + - "{4}" + - "{5}: {6}\n\n", - Smile.FUN, title, url, Smile.HR, + "{0} *Новый Pull Request*{1}" + + "[{2}]({3})" + + "{4}{5}{6}: {7}\n\n", + Smile.FUN, Smile.HR, title, url, Smile.HR, (description != null && !"".equals(description)) ? description + Smile.HR : "", Smile.AUTHOR, author ); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/StatusPrChange.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/StatusPrChange.java index 5ee5572..8e8a1db 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/StatusPrChange.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/change/pullrequest/StatusPrChange.java @@ -33,9 +33,9 @@ public class StatusPrChange extends PrChange { public String generateMessage() { return MessageFormat.format( "{0} *Изменился статус вашего ПР*{1}" + - "[{2}]({3})\n" + - "{4} -> {5}\n\n", - Smile.PEN, Smile.HR, title, url, oldStatus.name(), newStatus.name() + "[{2}]({3}){4}" + + "{5} -> {6}\n\n", + Smile.PEN, Smile.HR, title, url, Smile.HR, oldStatus.name(), newStatus.name() ); } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/PersonRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/PersonRepository.java index 0b1850b..9f12541 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/PersonRepository.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/PersonRepository.java @@ -28,4 +28,6 @@ public interface PersonRepository { Optional findByLogin(@NonNull String login); + Optional findByTelegramId(@NonNull Long telegramId); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/TaskRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/TaskRepository.java index 910d11c..afd0518 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/TaskRepository.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/TaskRepository.java @@ -1,6 +1,8 @@ package org.sadtech.bot.vcs.core.repository; +import lombok.NonNull; import org.sadtech.basic.context.repository.SimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.entity.Task; import java.time.LocalDateTime; @@ -13,4 +15,6 @@ public interface TaskRepository extends SimpleManagerRepository { List findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo); + List findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/PersonRepositoryImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/PersonRepositoryImpl.java index 3ead285..6888703 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/PersonRepositoryImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/PersonRepositoryImpl.java @@ -71,4 +71,9 @@ public class PersonRepositoryImpl implements PersonRepository { return jpaRepository.findById(login); } + @Override + public Optional findByTelegramId(@NonNull Long telegramId) { + return jpaRepository.findByTelegramId(telegramId); + } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/TaskRepositoryImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/TaskRepositoryImpl.java index 3a465b4..dd7a3ad 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/TaskRepositoryImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/impl/TaskRepositoryImpl.java @@ -1,6 +1,8 @@ package org.sadtech.bot.vcs.core.repository.impl; +import lombok.NonNull; import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository; +import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.repository.TaskRepository; import org.sadtech.bot.vcs.core.repository.jpa.TaskRepositoryJpa; @@ -30,4 +32,9 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status) { + return taskRepositoryJpa.findAllByResponsibleAndStatus(responsibleLogin, status); + } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/PersonJpaRepository.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/PersonJpaRepository.java index 54bf16f..7d1b02c 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/PersonJpaRepository.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/PersonJpaRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; import java.util.Set; /** @@ -28,4 +29,6 @@ public interface PersonJpaRepository extends JpaRepository { @Query("SELECT u.telegramId FROM Person u WHERE u.login IN :logins AND u.telegramId IS NOT NULL") Set findAllTelegramIdByLogin(Set logins); + Optional findByTelegramId(Long telegramId); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/TaskRepositoryJpa.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/TaskRepositoryJpa.java index 85ee04a..90c9a1f 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/TaskRepositoryJpa.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/repository/jpa/TaskRepositoryJpa.java @@ -1,6 +1,7 @@ package org.sadtech.bot.vcs.core.repository.jpa; import lombok.NonNull; +import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.entity.Task; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,4 +15,6 @@ public interface TaskRepositoryJpa extends JpaRepository { List findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List findAllByResponsibleAndStatus(String login, TaskStatus taskStatus); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PersonService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PersonService.java index 0fa5f42..84d2172 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PersonService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PersonService.java @@ -28,4 +28,8 @@ public interface PersonService { List createAll(Collection newUsers); + boolean existsByTelegram(Long telegramId); + + Optional getByTelegramId(@NonNull Long telegramId); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java index d12992e..2b66e29 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java @@ -16,7 +16,13 @@ import java.util.Set; public interface PullRequestsService extends SimpleManagerService, FilterService { - @NonNull + /** + * Получить все пулреквесты ревьювера с определенным статусом. + * + * @param login Логин ревьювера + * @param reviewerStatus Статус ревьювера в ПР + * @param pullRequestStatuses Статус ПР + */ List getAllByReviewerAndStatuses(@NonNull String login, @NonNull ReviewerStatus reviewerStatus, @NonNull Set pullRequestStatuses); List getAllByAuthorAndReviewerStatus(@NonNull String login, @NonNull ReviewerStatus status); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/TaskService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/TaskService.java index 1605b27..c1262e4 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/TaskService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/TaskService.java @@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.service; import lombok.NonNull; import org.sadtech.basic.context.service.SimpleManagerService; +import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.entity.Comment; import org.sadtech.bot.vcs.core.domain.entity.Task; @@ -16,4 +17,6 @@ public interface TaskService extends SimpleManagerService { List getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo); + List getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus open); + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java index d537b5f..368ec8e 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PersonServiceImpl.java @@ -89,4 +89,14 @@ public class PersonServiceImpl implements PersonService { return newPersons.stream().map(this::create).collect(Collectors.toList()); } + @Override + public boolean existsByTelegram(Long telegramId) { + return personRepository.existsByTelegramId(telegramId); + } + + @Override + public Optional getByTelegramId(@NonNull Long telegramId) { + return personRepository.findByTelegramId(telegramId); + } + } diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java index a551091..5d335ff 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/TaskServiceImpl.java @@ -169,6 +169,11 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im 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 PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId()) .orElseThrow(() -> new NotFoundException("ПР не найден")); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Smile.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Smile.java index f0b50b7..2af8b6a 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Smile.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/utils/Smile.java @@ -26,7 +26,7 @@ public enum Smile { DAY_3("\uD83C\uDF18"), DAY_4("\uD83C\uDF11"), DAY_5("\uD83C\uDF1A"), - TASK("\uD83E\uDD39\uD83C\uDFFB\u200D♂️"), + TASK("\uD83D\uDCBC"), MEGA_FUN("\uD83D\uDE02"), DANGEROUS("⚠️"), BELL("\uD83D\uDECE"), diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/config/TelegramBotConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/config/TelegramBotConfig.java index 3122411..3221cbc 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/config/TelegramBotConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/config/TelegramBotConfig.java @@ -2,7 +2,8 @@ package org.sadtech.bot.vcs.telegram.config; import org.sadtech.autoresponder.repository.UnitPointerRepository; import org.sadtech.autoresponder.repository.UnitPointerRepositoryMap; -import org.sadtech.social.bot.domain.unit.AnswerProcessing; +import org.sadtech.bot.vcs.telegram.service.ReplaceUrlLocalhost; +import org.sadtech.social.bot.domain.unit.AnswerCheck; import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.repository.impl.local.MailRepositoryList; import org.sadtech.social.core.service.MailService; @@ -43,13 +44,13 @@ public class TelegramBotConfig { @Bean public MessageAutoresponderTelegram messageAutoresponderTelegram( - AnswerProcessing menu, + AnswerCheck regCheck, Sending sending, MessageService messageService, UnitPointerRepository unitPointerRepository ) { return new MessageAutoresponderTelegram( - Collections.singleton(menu), + Collections.singleton(regCheck), sending, messageService, unitPointerRepository @@ -57,8 +58,13 @@ public class TelegramBotConfig { } @Bean - public Sending sending(TelegramConnect telegramConnect) { - return new TelegramSender(telegramConnect); + public Sending sending( + TelegramConnect telegramConnect, + ReplaceUrlLocalhost replaceUrlLocalhost + ) { + final TelegramSender telegramSender = new TelegramSender(telegramConnect); + telegramSender.setSendPreProcessing(replaceUrlLocalhost); + return telegramSender; } @Bean diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java index 4a1efcf..5ff127c 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTelegramService.java @@ -6,7 +6,6 @@ import org.sadtech.bot.vcs.core.domain.MessageSend; import org.sadtech.bot.vcs.core.service.MessageSendService; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.service.sender.Sending; -import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; /** @@ -14,7 +13,7 @@ import org.springframework.stereotype.Service; * * @author upagge 17.09.2020 */ -@Profile("prod") +//@Profile("prod") @Service @RequiredArgsConstructor public class MessageSendTelegramService implements MessageSendService { diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java index 2d5891f..eff2258 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/MessageSendTestService.java @@ -4,14 +4,13 @@ import lombok.NonNull; import org.sadtech.bot.vcs.core.domain.MessageSend; import org.sadtech.bot.vcs.core.service.MessageSendService; import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Service; /** * // TODO: 17.09.2020 Добавить описание. * * @author upagge 17.09.2020 */ -@Service +//@Service @Profile("dev") public class MessageSendTestService implements MessageSendService { diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/ReplaceUrlLocalhost.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/ReplaceUrlLocalhost.java new file mode 100644 index 0000000..594e4e6 --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/ReplaceUrlLocalhost.java @@ -0,0 +1,19 @@ +package org.sadtech.bot.vcs.telegram.service; + +import org.sadtech.telegram.bot.service.SendPreProcessing; +import org.springframework.stereotype.Component; + +/** + * // TODO: 18.09.2020 Добавить описание. + * + * @author upagge 18.09.2020 + */ +@Component +public class ReplaceUrlLocalhost implements SendPreProcessing { + + @Override + public String pretreatment(String s) { + return s.replace("localhost", "192.168.236.164"); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java new file mode 100644 index 0000000..081286c --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java @@ -0,0 +1,62 @@ +package org.sadtech.bot.vcs.telegram.service.unit; + +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.domain.PullRequestStatus; +import org.sadtech.bot.vcs.core.domain.ReviewerStatus; +import org.sadtech.bot.vcs.core.domain.entity.Person; +import org.sadtech.bot.vcs.core.domain.entity.PullRequest; +import org.sadtech.bot.vcs.core.exception.NotFoundException; +import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.core.service.PullRequestsService; +import org.sadtech.bot.vcs.core.utils.Smile; +import org.sadtech.social.bot.service.usercode.ProcessingData; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.content.Message; +import org.springframework.stereotype.Component; + +import java.text.MessageFormat; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * // TODO: 17.09.2020 Добавить описание. + * + * @author upagge 17.09.2020 + */ +@Component +@RequiredArgsConstructor +public class PullRequestProcessing implements ProcessingData { + + private final PersonService personService; + private final PullRequestsService pullRequestsService; + + @Override + public BoxAnswer processing(Message message) { + final Person person = personService.getByTelegramId(message.getPersonId()) + .orElseThrow(() -> new NotFoundException("Пользователь не найден")); + final List pullRequests = pullRequestsService.getAllByReviewerAndStatuses(person.getLogin(), ReviewerStatus.NEEDS_WORK, Collections.singleton(PullRequestStatus.OPEN)); + String messageAnswer; + if (pullRequests.isEmpty()) { + messageAnswer = "Все ПР проверены :)"; + } else { + final String prAnswer = pullRequests.stream() + .map(this::convert) + .collect(Collectors.joining("\n")); + messageAnswer = MessageFormat.format( + "Вам необходимо посмотреть следующие ПР:{0}{1}", + Smile.HR, prAnswer + ); + } + return BoxAnswer.of(messageAnswer); + } + + private String convert(PullRequest pullRequest) { + return MessageFormat.format( + "- [{0}]({1})", + pullRequest.getTitle(), + pullRequest.getUrl() + ); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/TaskProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/TaskProcessing.java new file mode 100644 index 0000000..3b56a2f --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/TaskProcessing.java @@ -0,0 +1,58 @@ +package org.sadtech.bot.vcs.telegram.service.unit; + +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.domain.TaskStatus; +import org.sadtech.bot.vcs.core.domain.entity.Person; +import org.sadtech.bot.vcs.core.domain.entity.Task; +import org.sadtech.bot.vcs.core.exception.NotFoundException; +import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.core.service.TaskService; +import org.sadtech.social.bot.service.usercode.ProcessingData; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.content.Message; +import org.springframework.stereotype.Component; + +import java.text.MessageFormat; +import java.util.List; +import java.util.stream.Collectors; + +/** + * // TODO: 17.09.2020 Добавить описание. + * + * @author upagge 17.09.2020 + */ +@Component +@RequiredArgsConstructor +public class TaskProcessing implements ProcessingData { + + private final PersonService personService; + private final TaskService taskService; + + @Override + public BoxAnswer processing(Message message) { + final Person person = personService.getByTelegramId(message.getPersonId()) + .orElseThrow(() -> new NotFoundException("Ошибочка")); + final List tasks = taskService.getAllByResponsibleAndStatus(person.getLogin(), TaskStatus.OPEN); + String messageText; + if (tasks.isEmpty()) { + messageText = "Задач нет"; + } else { + final String tasksString = tasks.stream() + .map(this::createTaskString) + .collect(Collectors.joining("\n")); + messageText = MessageFormat.format( + "Список ваших задач:\n\n{0}", + tasksString + ); + } + return BoxAnswer.of(messageText); + } + + private String createTaskString(Task task) { + return MessageFormat.format( + "- [{0}]({1})", + task.getDescription(), task.getUrl() + ); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java index 4340c63..2da837b 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java @@ -1,8 +1,16 @@ package org.sadtech.bot.vcs.telegram.unit; +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.telegram.service.unit.PullRequestProcessing; +import org.sadtech.bot.vcs.telegram.service.unit.TaskProcessing; +import org.sadtech.social.bot.domain.unit.AnswerCheck; import org.sadtech.social.bot.domain.unit.AnswerProcessing; +import org.sadtech.social.bot.domain.unit.AnswerText; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.content.Mail; +import org.sadtech.social.core.domain.content.Message; +import org.sadtech.social.core.utils.KeyBoards; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,10 +20,67 @@ import org.springframework.context.annotation.Configuration; * @author upagge [30.01.2020] */ @Configuration +@RequiredArgsConstructor public class UnitConfig { + private final PersonService personService; + @Bean - public AnswerProcessing menu() { + public AnswerCheck regCheck( + AnswerProcessing noRegister, + AnswerText menu + ) { + return AnswerCheck.builder() + .check( + message -> personService.existsByTelegram(message.getPersonId()) + ) + .unitFalse(noRegister) + .unitTrue(menu) + .build(); + } + + @Bean + public AnswerText menu( + AnswerProcessing getTasks, + AnswerProcessing getPr + ) { + return AnswerText.builder() + .boxAnswer( + BoxAnswer.builder() + .message("Привет, выбери пункт меню!") + .keyBoard(KeyBoards.verticalMenuString( + "Мои задачи", "Проверить ПР" + )) + .build() + ) + .nextUnit(getTasks) + .nextUnit(getPr) + .build(); + } + + @Bean + public AnswerProcessing getTasks( + TaskProcessing taskProcessing + ) { + return AnswerProcessing.builder() + .processingData(taskProcessing) + .phrase("Мои задачи") + .build(); + } + + @Bean + public AnswerProcessing getPr( + PullRequestProcessing pullRequestProcessing + ) { + return AnswerProcessing.builder() + .processingData(pullRequestProcessing) + .phrase("Проверить ПР") + .build(); + } + + + @Bean + public AnswerProcessing noRegister() { return AnswerProcessing.builder() .processingData(message -> BoxAnswer.builder()