From 418b7c9f80f07074bab5e3b7482829cdba3d376b Mon Sep 17 00:00:00 2001 From: uPagge Date: Thu, 14 Jan 2021 13:10:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractPullRequestBitbucketParser.java | 123 --------------- bot-app/pom.xml | 7 +- .../app/BitbucketbotApplication.java | 8 +- .../app/config/AppConfig.java | 2 +- .../property/CommentSchedulerProperty.java | 2 +- .../scheduler/CommentAndTaskScheduler.java | 4 +- .../scheduler/PullRequestParserScheduler.java | 2 +- .../app/service/CommentAndTaskParser.java | 21 ++- .../app/service/ExecutorScanner.java | 14 +- .../app/service/executor/DataScan.java | 2 +- .../app/service/executor/Executor.java | 2 +- .../app/service/executor/ResultScan.java | 2 +- .../app/service/executor/Seeker.java | 3 +- .../parser/PullRequestBitbucketParser.java | 116 +++++++++++++++ .../app/scheduler/PersonScheduler.java | 19 --- .../app/scheduler/RatingScheduler.java | 49 ------ .../service/parser/PersonBitbucketParser.java | 51 ------- .../parser/PullRequestBitbucketParser.java | 58 -------- .../src/main/resources/application-dev.yaml | 43 ------ .../src/main/resources/application-prod.yaml | 41 ----- bot-app/src/main/resources/application.yaml | 40 ++++- .../2020-09-06-create-table.xml | 0 bot-app/src/main/resources/logback-dev.xml | 24 --- bot-app/src/main/resources/logback-prod.xml | 24 --- .../gitlab/context/domain/entity/Person.java | 50 ------- .../context/domain/entity/RatingHistory.java | 49 ------ .../context/domain/entity/RatingList.java | 42 ------ .../context/repository/PersonRepository.java | 31 ---- .../repository/RatingHistoryRepository.java | 19 --- .../repository/RatingListRepository.java | 24 --- .../gitlab/context/service/PersonService.java | 29 ---- .../gitlab/context/service/RatingService.java | 19 --- .../context/service/parser/PersonParser.java | 15 -- ...ucketProperty.java => GitlabProperty.java} | 16 +- .../config/properties/RatingProperty.java | 21 --- .../core/scheduler/NotificationScheduler.java | 3 - .../core/service/impl/CommentServiceImpl.java | 1 - .../core/service/impl/PersonServiceImpl.java | 111 -------------- .../service/impl/PullRequestsServiceImpl.java | 2 - .../core/service/impl/RatingServiceImpl.java | 140 ------------------ .../core/service/impl/TaskServiceImpl.java | 1 - .../sadtech/bot/gitlab/core/utils/Utils.java | 54 ------- .../data/impl/PersonRepositoryImpl.java | 74 --------- .../impl/RatingHistoryRepositoryImpl.java | 33 ----- .../data/impl/RatingListRepositoryImpl.java | 47 ------ .../gitlab/data/jpa/PersonJpaRepository.java | 34 ----- .../data/jpa/RatingHistoryJpaRepository.java | 19 --- .../data/jpa/RatingListJpaRepository.java | 22 --- {bitbucketbot-core => gitlab-core}/pom.xml | 0 .../converter/CommentJsonToComment.java | 0 .../converter/CommentJsonToTaskConvert.java | 0 .../converter/PullRequestJsonConverter.java | 56 +++---- .../service/converter/UserJsonConverter.java | 1 - .../bot/gitlab/sdk/domain/AuthorJson.java | 21 +++ .../gitlab/sdk/domain/PullRequestJson.java | 27 ++-- .../gitlab/sdk/domain/PullRequestState.java | 2 +- .../gitlab/sdk/domain/UserDecisionJson.java | 18 --- .../domain/sheet/PullRequestSheetJson.java | 13 -- pom.xml | 8 +- .../config/property/TeamcityProperty.java | 2 +- .../core/service/parser/BuildShortParser.java | 1 - .../service/parser/TeamcityProjectParser.java | 1 - .../service/MessageSendTelegramService.java | 1 - .../service/unit/RatingTopProcessing.java | 34 ----- .../telegram/service/unit/TaskProcessing.java | 2 - .../PullRequestNeedWorkProcessing.java | 2 - .../PullRequestReviewProcessing.java | 2 - .../telegram/unit/NotifySettingUnit.java | 2 - .../bot/gitlab/telegram/unit/UnitConfig.java | 2 - 69 files changed, 272 insertions(+), 1436 deletions(-) delete mode 100644 bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/AbstractPullRequestBitbucketParser.java rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/BitbucketbotApplication.java (52%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/config/AppConfig.java (95%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/config/property/CommentSchedulerProperty.java (92%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/scheduler/CommentAndTaskScheduler.java (84%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/scheduler/PullRequestParserScheduler.java (93%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/CommentAndTaskParser.java (93%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/ExecutorScanner.java (78%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/executor/DataScan.java (68%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/executor/Executor.java (73%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/executor/ResultScan.java (83%) rename bot-app/src/main/java/org/sadtech/bot/{vcs/bitbucket => gitlab}/app/service/executor/Seeker.java (88%) create mode 100644 bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/PullRequestBitbucketParser.java delete mode 100644 bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java delete mode 100644 bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/RatingScheduler.java delete mode 100644 bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java delete mode 100644 bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java delete mode 100644 bot-app/src/main/resources/application-dev.yaml delete mode 100644 bot-app/src/main/resources/application-prod.yaml rename bot-app/src/main/resources/liquibase/{v.2.0.0 => v.1.0.0}/2020-09-06-create-table.xml (100%) delete mode 100644 bot-app/src/main/resources/logback-dev.xml delete mode 100644 bot-app/src/main/resources/logback-prod.xml delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingHistory.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingList.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingHistoryRepository.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingListRepository.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/RatingService.java delete mode 100644 bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/parser/PersonParser.java rename bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/{BitbucketProperty.java => GitlabProperty.java} (77%) delete mode 100644 bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/RatingProperty.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/RatingServiceImpl.java delete mode 100644 bot-core/src/main/java/org/sadtech/bot/gitlab/core/utils/Utils.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingHistoryRepositoryImpl.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingListRepositoryImpl.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingHistoryJpaRepository.java delete mode 100644 bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingListJpaRepository.java rename {bitbucketbot-core => gitlab-core}/pom.xml (100%) rename {bitbucketbot-core => gitlab-core}/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToComment.java (100%) rename {bitbucketbot-core => gitlab-core}/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToTaskConvert.java (100%) rename {bitbucketbot-core => gitlab-core}/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java (96%) rename {bitbucketbot-core => gitlab-core}/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/UserJsonConverter.java (90%) create mode 100644 gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/AuthorJson.java delete mode 100644 gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/UserDecisionJson.java delete mode 100644 gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/sheet/PullRequestSheetJson.java delete mode 100644 telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/RatingTopProcessing.java diff --git a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/AbstractPullRequestBitbucketParser.java b/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/AbstractPullRequestBitbucketParser.java deleted file mode 100644 index fdb1fa7..0000000 --- a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/AbstractPullRequestBitbucketParser.java +++ /dev/null @@ -1,123 +0,0 @@ -package org.sadtech.bot.vcs.bitbucket.core; - -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; -import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; -import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter; -import org.sadtech.bot.gitlab.context.service.PullRequestsService; -import org.sadtech.bot.gitlab.core.utils.Pair; -import org.sadtech.bot.gitlab.core.utils.Utils; -import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson; -import org.sadtech.bot.gitlab.sdk.domain.sheet.PullRequestSheetJson; -import org.sadtech.bot.vsc.context.domain.PullRequestStatus; -import org.sadtech.bot.vsc.context.service.PullRequestParser; -import org.springframework.core.convert.ConversionService; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Абстрактный парсер ПРов, для использования в мульти и локал версиях приложения. - * - * @author upagge 25.10.2020 - */ -@Slf4j -public abstract class AbstractPullRequestBitbucketParser implements PullRequestParser { - - private static final Set OLD_STATUSES = Stream.of(PullRequestStatus.MERGED, PullRequestStatus.OPEN, PullRequestStatus.DECLINED).collect(Collectors.toSet()); - - protected final PullRequestsService pullRequestsService; - protected final ConversionService conversionService; - - protected AbstractPullRequestBitbucketParser( - PullRequestsService pullRequestsService, - ConversionService conversionService - ) { - this.pullRequestsService = pullRequestsService; - this.conversionService = conversionService; - } - - public void processingOldPullRequests(@NonNull String urlPullRequestOpen, @NonNull String urlPullRequestClose) { - final Set existsId = pullRequestsService.getAllId(OLD_STATUSES).stream() - .map(IdAndStatusPr::getId) - .collect(Collectors.toSet()); - final Set openId = getExistsPullRequestIds(urlPullRequestOpen); - final Set closeId = getExistsPullRequestIds(urlPullRequestClose); - final Set newNotExistsId = existsId.stream() - .filter(id -> !openId.contains(id) && !closeId.contains(id)) - .collect(Collectors.toSet()); - log.info("Открыты: " + Arrays.toString(openId.toArray())); - log.info("Закрыты: " + Arrays.toString(closeId.toArray())); - log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray())); - if (!newNotExistsId.isEmpty() && !openId.isEmpty()) { - pullRequestsService.deleteAllById(newNotExistsId); - } - } - - protected abstract Set getExistsPullRequestIds(@NonNull String bitbucketUrl); - - protected void createNewPullRequest(@NonNull String urlPullRequestOpen, @NonNull String bitbucketToken) { - Optional sheetJson = Utils.urlToJson(urlPullRequestOpen, bitbucketToken, PullRequestSheetJson.class); - while (sheetJson.isPresent() && sheetJson.get().hasContent()) { - final PullRequestSheetJson pullRequestBitbucketSheet = sheetJson.get(); - final List newPullRequest = pullRequestBitbucketSheet.getValues().stream() - .collect(Collectors.toMap(pullRequestJson -> new Pair<>(pullRequestJson.getId(), pullRequestJson.getFromRef().getRepository().getId()), pullRequestJson -> pullRequestJson)) - .values() - .stream() - .filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson))) - .map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class)) - .collect(Collectors.toList()); - - pullRequestsService.createAll(newPullRequest); - - if (pullRequestBitbucketSheet.getNextPageStart() != null) { - sheetJson = Utils.urlToJson(urlPullRequestOpen + pullRequestBitbucketSheet.getNextPageStart(), bitbucketToken, PullRequestSheetJson.class); - } else { - break; - } - } - } - - protected Set updateOldPullRequests(@NonNull String url, @NonNull String token) { - Optional sheetJson = Utils.urlToJson(url, token, PullRequestSheetJson.class); - Set ids = new HashSet<>(); - while (sheetJson.isPresent() && sheetJson.get().hasContent()) { - final PullRequestSheetJson jsonSheet = sheetJson.get(); - final List existsPr = getExistsPr(jsonSheet.getValues()); - - ids.addAll( - pullRequestsService.updateAll(existsPr).stream() - .map(PullRequest::getId) - .collect(Collectors.toSet()) - ); - - if (jsonSheet.getNextPageStart() != null) { - sheetJson = Utils.urlToJson(url + jsonSheet.getNextPageStart(), token, PullRequestSheetJson.class); - } else { - break; - } - } - return ids; - } - - private List getExistsPr(@NonNull List pullRequestJsons) { - return pullRequestJsons.stream() - .filter(json -> pullRequestsService.exists(bitbucketIdAndPullRequestId(json))) - .map(json -> conversionService.convert(json, PullRequest.class)) - .collect(Collectors.toList()); - } - - private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) { - return PullRequestFilter.builder() - .bitbucketId(json.getId()) - .bitbucketRepositoryId(json.getFromRef().getRepository().getId()) - .build(); - } - -} diff --git a/bot-app/pom.xml b/bot-app/pom.xml index ead43c2..bb7694d 100644 --- a/bot-app/pom.xml +++ b/bot-app/pom.xml @@ -75,6 +75,11 @@ gitlab-sdk + + org.sadtech.haiti + haiti-utils + + org.liquibase liquibase-core @@ -98,7 +103,7 @@ org.springframework.boot spring-boot-maven-plugin - bitbucketbot + gitlab-notification diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/BitbucketbotApplication.java similarity index 52% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/BitbucketbotApplication.java index 8fa4c25..887c73f 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/BitbucketbotApplication.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/BitbucketbotApplication.java @@ -1,13 +1,13 @@ -package org.sadtech.bot.vcs.bitbucket.app; +package org.sadtech.bot.gitlab.app; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -@EnableJpaRepositories(basePackages = {"org.sadtech.bot.vcs.bitbucketbot.data.jpa", "org.sadtech.bot.vcs.teamcity.core.repository.jpa"}) -@SpringBootApplication(scanBasePackages = "org.sadtech.bot.vcs") -@EntityScan(basePackages = {"org.sadtech.bot.vsc.bitbucketbot.context.domain.entity", "org.sadtech.bot.vcs.teamcity.core.domain.entity"}) +@EnableJpaRepositories(basePackages = {"org.sadtech.bot.gitlab.data.jpa", "org.sadtech.bot.gitlab.teamcity.core.repository.jpa"}) +@SpringBootApplication(scanBasePackages = "org.sadtech.bot.gitlab") +@EntityScan(basePackages = {"org.sadtech.bot.gitlab.context.domain.entity", "org.sadtech.bot.gitlab.teamcity.core.domain.entity"}) public class BitbucketbotApplication { public static void main(String[] args) { diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/AppConfig.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java similarity index 95% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/AppConfig.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java index 8b505ef..a615ff0 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/AppConfig.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.config; +package org.sadtech.bot.gitlab.app.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/property/CommentSchedulerProperty.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/property/CommentSchedulerProperty.java similarity index 92% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/property/CommentSchedulerProperty.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/property/CommentSchedulerProperty.java index 042e334..bc798f9 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/config/property/CommentSchedulerProperty.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/property/CommentSchedulerProperty.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.config.property; +package org.sadtech.bot.gitlab.app.config.property; import lombok.Getter; import lombok.Setter; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/CommentAndTaskScheduler.java similarity index 84% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/CommentAndTaskScheduler.java index ac59a96..df0f804 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/CommentAndTaskScheduler.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/CommentAndTaskScheduler.java @@ -1,7 +1,7 @@ -package org.sadtech.bot.vcs.bitbucket.app.scheduler; +package org.sadtech.bot.gitlab.app.scheduler; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.bitbucket.app.service.CommentAndTaskParser; +import org.sadtech.bot.gitlab.app.service.CommentAndTaskParser; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/PullRequestParserScheduler.java similarity index 93% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/PullRequestParserScheduler.java index 73c8d11..ea1e5fe 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PullRequestParserScheduler.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/PullRequestParserScheduler.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.scheduler; +package org.sadtech.bot.gitlab.app.scheduler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/CommentAndTaskParser.java similarity index 93% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/CommentAndTaskParser.java index ff8d1e8..d6a9bc4 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/CommentAndTaskParser.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/CommentAndTaskParser.java @@ -1,6 +1,8 @@ -package org.sadtech.bot.vcs.bitbucket.app.service; +package org.sadtech.bot.gitlab.app.service; import lombok.NonNull; +import org.sadtech.bot.gitlab.app.config.property.CommentSchedulerProperty; +import org.sadtech.bot.gitlab.app.service.executor.DataScan; import org.sadtech.bot.gitlab.context.domain.entity.Comment; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; @@ -9,13 +11,10 @@ import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.service.CommentService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.service.TaskService; -import org.sadtech.bot.gitlab.core.config.properties.BitbucketProperty; +import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.core.config.properties.InitProperty; -import org.sadtech.bot.gitlab.core.utils.Utils; import org.sadtech.bot.gitlab.sdk.domain.CommentJson; import org.sadtech.bot.gitlab.sdk.domain.Severity; -import org.sadtech.bot.vcs.bitbucket.app.config.property.CommentSchedulerProperty; -import org.sadtech.bot.vcs.bitbucket.app.service.executor.DataScan; import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.core.page.PaginationImpl; import org.springframework.core.convert.ConversionService; @@ -41,7 +40,7 @@ public class CommentAndTaskParser { private final TaskService taskService; private final ConversionService conversionService; - private final BitbucketProperty bitbucketProperty; + private final GitlabProperty gitlabProperty; private final CommentSchedulerProperty commentSchedulerProperty; private final InitProperty initProperty; @@ -53,7 +52,7 @@ public class CommentAndTaskParser { ExecutorScanner executorScanner, TaskService taskService, ConversionService conversionService, - BitbucketProperty bitbucketProperty, + GitlabProperty gitlabProperty, CommentSchedulerProperty commentSchedulerProperty, InitProperty initProperty ) { @@ -62,7 +61,7 @@ public class CommentAndTaskParser { this.executorScanner = executorScanner; this.taskService = taskService; this.conversionService = conversionService; - this.bitbucketProperty = bitbucketProperty; + this.gitlabProperty = gitlabProperty; this.commentSchedulerProperty = commentSchedulerProperty; this.initProperty = initProperty; } @@ -157,7 +156,7 @@ public class CommentAndTaskParser { } private String getCommentUrl(long commentId, PullRequest pullRequest) { - return bitbucketProperty.getUrlPullRequestComment() + return gitlabProperty.getUrlPullRequestComment() .replace("{projectKey}", pullRequest.getProjectKey()) .replace("{repositorySlug}", pullRequest.getRepositorySlug()) .replace("{pullRequestId}", pullRequest.getBitbucketId().toString()) @@ -171,7 +170,7 @@ public class CommentAndTaskParser { for (Comment oldComment : comments) { final Optional optCommentJson = Utils.urlToJson( oldComment.getUrlApi(), - bitbucketProperty.getToken(), + gitlabProperty.getToken(), CommentJson.class ); if (optCommentJson.isPresent()) { @@ -195,7 +194,7 @@ public class CommentAndTaskParser { for (Task oldTask : tasks) { final Optional optCommentJson = Utils.urlToJson( oldTask.getUrlApi(), - bitbucketProperty.getToken(), + gitlabProperty.getToken(), CommentJson.class ); if (optCommentJson.isPresent()) { diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java similarity index 78% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java index 33b88ca..5ec642e 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/ExecutorScanner.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java @@ -1,13 +1,13 @@ -package org.sadtech.bot.vcs.bitbucket.app.service; +package org.sadtech.bot.gitlab.app.service; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.sadtech.bot.gitlab.core.config.properties.BitbucketProperty; +import org.sadtech.bot.gitlab.app.service.executor.DataScan; +import org.sadtech.bot.gitlab.app.service.executor.Executor; +import org.sadtech.bot.gitlab.app.service.executor.Seeker; +import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.sdk.domain.CommentJson; -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.springframework.stereotype.Service; import java.util.ArrayList; @@ -25,13 +25,13 @@ public class ExecutorScanner implements Executor { private final ExecutorService executorService; private List>> resultList = new ArrayList<>(); - private final BitbucketProperty bitbucketProperty; + private final GitlabProperty gitlabProperty; @Override public boolean registration(@NonNull List dataScans) { resultList.addAll( dataScans.stream() - .map(dataScan -> new Seeker(dataScan, bitbucketProperty.getToken())) + .map(dataScan -> new Seeker(dataScan, gitlabProperty.getToken())) .map(executorService::submit) .collect(Collectors.toList()) ); diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/DataScan.java similarity index 68% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/DataScan.java index 1a32fbd..2a23135 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/DataScan.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/DataScan.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.executor; +package org.sadtech.bot.gitlab.app.service.executor; import lombok.Data; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Executor.java similarity index 73% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Executor.java index 894c22f..3c0f8d2 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Executor.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Executor.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.executor; +package org.sadtech.bot.gitlab.app.service.executor; import lombok.NonNull; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/ResultScan.java similarity index 83% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/ResultScan.java index 9931625..a355c61 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/ResultScan.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/ResultScan.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.executor; +package org.sadtech.bot.gitlab.app.service.executor; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Seeker.java similarity index 88% rename from bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Seeker.java index 0de843c..074827f 100644 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/executor/Seeker.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/executor/Seeker.java @@ -1,7 +1,6 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.executor; +package org.sadtech.bot.gitlab.app.service.executor; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.core.utils.Utils; import org.sadtech.bot.gitlab.sdk.domain.CommentJson; import java.util.Optional; diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/PullRequestBitbucketParser.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/PullRequestBitbucketParser.java new file mode 100644 index 0000000..6627a79 --- /dev/null +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/PullRequestBitbucketParser.java @@ -0,0 +1,116 @@ +package org.sadtech.bot.gitlab.app.service.parser; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; +import org.sadtech.bot.gitlab.context.service.PullRequestsService; +import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; +import org.sadtech.bot.gitlab.core.utils.Pair; +import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson; +import org.sadtech.bot.vsc.context.domain.PullRequestStatus; +import org.sadtech.bot.vsc.context.service.PullRequestParser; +import org.sadtech.haiti.utils.network.HttpHeader; +import org.sadtech.haiti.utils.network.HttpParse; +import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT; +import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION; +import static org.sadtech.haiti.utils.network.HttpParse.BEARER; + +@Slf4j +@Service +@RequiredArgsConstructor +public class PullRequestBitbucketParser implements PullRequestParser { + + private static final Set OLD_STATUSES = Stream.of(PullRequestStatus.MERGED, PullRequestStatus.OPEN, PullRequestStatus.DECLINED).collect(Collectors.toSet()); + + private final GitlabProperty gitlabProperty; + private final PullRequestsService pullRequestsService; + private final ConversionService conversionService; + + @Override + public void parsingOldPullRequest() { +// processingOldPullRequests(gitlabProperty.getUrlPullRequestOpen(), gitlabProperty.getUrlPullRequestClose()); + } + + @Override + public void parsingNewPullRequest() { + + final List pullRequestJsons = HttpParse.request(gitlabProperty.getUrlPullRequestOpen()) + .header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken())) + .header(ACCEPT) + .executeList(PullRequestJson.class); + + while (pullRequestJsons != null && !pullRequestJsons.isEmpty()) { + final List newPullRequest = pullRequestJsons.stream() + .collect(Collectors.toMap(pullRequestJson -> new Pair<>(pullRequestJson.getId(), pullRequestJson.getFromRef().getRepository().getId()), pullRequestJson -> pullRequestJson)) + .values() + .stream() +// .filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson))) + .map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class)) + .collect(Collectors.toList()); + + pullRequestsService.createAll(newPullRequest); + } + } + +// private Set getExistsPullRequestIds(String bitbucketUrl) { +// Optional sheetJson = Utils.urlToJson(url, token, PullRequestSheetJson.class); +// Set ids = new HashSet<>(); +// while (sheetJson.isPresent() && sheetJson.get().hasContent()) { +// final PullRequestSheetJson jsonSheet = sheetJson.get(); +// final List existsPr = getExistsPr(jsonSheet.getValues()); +// +// ids.addAll( +// pullRequestsService.updateAll(existsPr).stream() +// .map(PullRequest::getId) +// .collect(Collectors.toSet()) +// ); +// +// if (jsonSheet.getNextPageStart() != null) { +// sheetJson = Utils.urlToJson(url + jsonSheet.getNextPageStart(), token, PullRequestSheetJson.class); +// } else { +// break; +// } +// } +// return ids; +// } +// +// public void processingOldPullRequests(@NonNull String urlPullRequestOpen, @NonNull String urlPullRequestClose) { +// final Set existsId = pullRequestsService.getAllId(OLD_STATUSES).stream() +// .map(IdAndStatusPr::getId) +// .collect(Collectors.toSet()); +// final Set openId = getExistsPullRequestIds(urlPullRequestOpen); +// final Set closeId = getExistsPullRequestIds(urlPullRequestClose); +// final Set newNotExistsId = existsId.stream() +// .filter(id -> !openId.contains(id) && !closeId.contains(id)) +// .collect(Collectors.toSet()); +// log.info("Открыты: " + Arrays.toString(openId.toArray())); +// log.info("Закрыты: " + Arrays.toString(closeId.toArray())); +// log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray())); +// if (!newNotExistsId.isEmpty() && !openId.isEmpty()) { +// pullRequestsService.deleteAllById(newNotExistsId); +// } +// } +// +// private List getExistsPr(@NonNull List pullRequestJsons) { +// return pullRequestJsons.stream() +// .filter(json -> pullRequestsService.exists(bitbucketIdAndPullRequestId(json))) +// .map(json -> conversionService.convert(json, PullRequest.class)) +// .collect(Collectors.toList()); +// } +// +// private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) { +// return PullRequestFilter.builder() +// .bitbucketId(json.getId()) +// .bitbucketRepositoryId(json.getFromRef().getRepository().getId()) +// .build(); +// } + +} diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java b/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java deleted file mode 100644 index 667f3e1..0000000 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/PersonScheduler.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.bot.vcs.bitbucket.app.scheduler; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.vcs.bitbucket.app.service.parser.PersonBitbucketParser; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class PersonScheduler { - - private final PersonBitbucketParser personParser; - - @Scheduled(cron = "${bitbucketbot.scheduler.person:0 0 0 */1 * *}") - public void scanPersons() { - personParser.scanNewPerson(); - } - -} diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/RatingScheduler.java b/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/RatingScheduler.java deleted file mode 100644 index a0cfe7a..0000000 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/scheduler/RatingScheduler.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sadtech.bot.vcs.bitbucket.app.scheduler; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.EntityType; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.domain.notify.SimpleTextNotify; -import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.context.service.RatingService; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import java.util.Collections; -import java.util.List; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Component -@RequiredArgsConstructor -public class RatingScheduler { - - private final RatingService ratingService; - private final PersonService personService; - private final NotifyService notifyService; - - @Scheduled(cron = "0 */50 * * * *") - private void ratingRecalculation() { - ratingService.ratingRecalculation(); - } - - @Scheduled(cron = "0 20 8 * * MON-FRI") - private void goodMorningRating() { - List allRegister = personService.getAllRegister(); - for (Person person : allRegister) { - final String message = ratingService.getRatingTop(person.getLogin()); - notifyService.send( - SimpleTextNotify.builder() - .entityType(EntityType.PERSON) - .message(message) - .recipients(Collections.singleton(person.getLogin())) - .build() - ); - } - } - -} diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java b/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java deleted file mode 100644 index 1df7d2d..0000000 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PersonBitbucketParser.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.parser; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.context.service.parser.PersonParser; -import org.sadtech.bot.gitlab.core.config.properties.BitbucketProperty; -import org.sadtech.bot.gitlab.core.utils.Utils; -import org.sadtech.bot.gitlab.sdk.domain.UserJson; -import org.sadtech.bot.gitlab.sdk.domain.sheet.UserSheetJson; -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -@Service -@RequiredArgsConstructor -public class PersonBitbucketParser implements PersonParser { - - private final PersonService personService; - private final ConversionService conversionService; - - private final BitbucketProperty bitbucketProperty; - - @Override - public void scanNewPerson() { - Optional sheetJson = Utils.urlToJson(bitbucketProperty.getUrlUsers(), bitbucketProperty.getToken(), UserSheetJson.class); - while (sheetJson.isPresent() && sheetJson.get().hasContent()) { - final UserSheetJson sheetUsers = sheetJson.get(); - final List users = sheetUsers.getValues(); - final Set logins = users.stream().map(UserJson::getName).collect(Collectors.toSet()); - final Set existsLogins = personService.existsByLogin(logins); - final Set newUsers = users.stream() - .filter(userJson -> !existsLogins.contains(userJson.getName())) - .map(userJson -> conversionService.convert(userJson, Person.class)) - .collect(Collectors.toSet()); - if (!newUsers.isEmpty()) { - personService.createAll(newUsers); - } - if (sheetUsers.getNextPageStart() != null) { - sheetJson = Utils.urlToJson(bitbucketProperty.getUrlUsers() + sheetUsers.getNextPageStart(), bitbucketProperty.getToken(), UserSheetJson.class); - } else { - break; - } - } - } - -} diff --git a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java b/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java deleted file mode 100644 index 3dddcee..0000000 --- a/bot-app/src/main/java/org/sadtech/bot/vcs/bitbucket/app/service/parser/PullRequestBitbucketParser.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.sadtech.bot.vcs.bitbucket.app.service.parser; - -import lombok.extern.slf4j.Slf4j; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.context.service.PullRequestsService; -import org.sadtech.bot.gitlab.core.config.properties.BitbucketProperty; -import org.sadtech.bot.vcs.bitbucket.core.AbstractPullRequestBitbucketParser; -import org.sadtech.bot.vsc.context.service.PullRequestParser; -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Service; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -@Slf4j -@Service -public class PullRequestBitbucketParser extends AbstractPullRequestBitbucketParser implements PullRequestParser { - - private final PersonService personService; - private final BitbucketProperty bitbucketProperty; - - protected PullRequestBitbucketParser( - PullRequestsService pullRequestsService, - PersonService personService, - ConversionService conversionService, - BitbucketProperty bitbucketProperty - ) { - super(pullRequestsService, conversionService); - this.personService = personService; - this.bitbucketProperty = bitbucketProperty; - } - - @Override - public void parsingOldPullRequest() { - processingOldPullRequests(bitbucketProperty.getUrlPullRequestOpen(), bitbucketProperty.getUrlPullRequestClose()); - } - - @Override - public void parsingNewPullRequest() { - final List users = personService.getAllRegister(); - for (Person user : users) { - createNewPullRequest(bitbucketProperty.getUrlPullRequestOpen(), user.getToken()); - } - } - - @Override - protected Set getExistsPullRequestIds(String bitbucketUrl) { - final List persons = personService.getAllRegister(); - final Set ids = new HashSet<>(); - for (Person person : persons) { - ids.addAll(updateOldPullRequests(bitbucketUrl, person.getToken())); - } - return ids; - } - -} diff --git a/bot-app/src/main/resources/application-dev.yaml b/bot-app/src/main/resources/application-dev.yaml deleted file mode 100644 index a5b2fc3..0000000 --- a/bot-app/src/main/resources/application-dev.yaml +++ /dev/null @@ -1,43 +0,0 @@ -spring: - datasource: - url: ${DATASOURCE_URL} - username: ${DATASOURCE_USERNAME} - driver-class-name: org.postgresql.Driver - password: ${DATASOURCE_PASSWORD} - liquibase: - change-log: classpath:liquibase/change-log.xml - jpa: - show-sql: false - hibernate: - ddl-auto: none - database-platform: org.hibernate.dialect.PostgreSQLDialect - properties: - hibernate: - jdbc: - lob: - non_contextual_creation: true -logging: - config: classpath:logback-dev.xml -bitbucketbot: - scheduler: - person: 0 */1 * * * * - comment: - settings: - no-comment-count: 20 - comment-count: 100 - init: - start-comment-id: 8301 - use: false - rating: - enable: true - bitbucket: - token: ${BITBUCKET_ADMIN_TOKEN} - url-pull-request-open: ${BITBUCKET_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN - url-pull-request-close: ${BITBUCKET_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 - url-pull-request-comment: ${BITBUCKET_URL}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} - url-pull-request: ${BITBUCKET_URL}/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/overview - url-users: ${BITBUCKET_URL}/rest/api/1.0/admin/users - teamcity: - token: ${TEAMCITY_ADMIN_TOKEN} - project-url: ${TEAMCITY_URL}/app/rest/projects - build-url: ${TEAMCITY_URL}/app/rest/builds/?locator=project:(id:{0}),branch:(default:any) \ No newline at end of file diff --git a/bot-app/src/main/resources/application-prod.yaml b/bot-app/src/main/resources/application-prod.yaml deleted file mode 100644 index f9582d0..0000000 --- a/bot-app/src/main/resources/application-prod.yaml +++ /dev/null @@ -1,41 +0,0 @@ -spring: - datasource: - url: ${DATASOURCE_URL} - username: ${DATASOURCE_USERNAME} - driver-class-name: org.postgresql.Driver - password: ${DATASOURCE_PASSWORD} - liquibase: - change-log: classpath:liquibase/change-log.xml - jpa: - show-sql: false - hibernate: - ddl-auto: none - database-platform: org.hibernate.dialect.PostgreSQLDialect - properties: - hibernate: - jdbc: - lob: - non_contextual_creation: true -logging: - config: classpath:logback-prod.xml -bitbucketbot: - scheduler: - person: 0 0 0 */1 * * - comment: - settings: - no-comment-count: 20 - comment-count: 100 - init: - start-comment-id: 7807 - use: false - bitbucket: - token: ${BITBUCKET_ADMIN_TOKEN} - url-pull-request-open: ${BITBUCKET_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN - url-pull-request-close: ${BITBUCKET_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 - url-pull-request-comment: ${BITBUCKET_URL}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} - url-pull-request: ${BITBUCKET_URL}/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/overview - url-users: ${BITBUCKET_URL}/rest/api/1.0/admin/users - teamcity: - token: ${TEAMCITY_ADMIN_TOKEN} - project-url: ${TEAMCITY_URL}/app/rest/projects - build-url: ${TEAMCITY_URL}/app/rest/builds/?locator=project:(id:{0}),branch:(default:any) \ No newline at end of file diff --git a/bot-app/src/main/resources/application.yaml b/bot-app/src/main/resources/application.yaml index e865bae..edb30e6 100644 --- a/bot-app/src/main/resources/application.yaml +++ b/bot-app/src/main/resources/application.yaml @@ -1,7 +1,43 @@ server: port: 8018 +spring: + datasource: + url: ${DATASOURCE_URL} + username: ${DATASOURCE_USERNAME} + driver-class-name: org.postgresql.Driver + password: ${DATASOURCE_PASSWORD} + liquibase: + change-log: classpath:liquibase/change-log.xml + jpa: + show-sql: false + hibernate: + ddl-auto: none + database-platform: org.hibernate.dialect.PostgreSQLDialect + properties: + hibernate: + jdbc: + lob: + non_contextual_creation: true telegram-config: bot-username: ${TELEGRAM_BOT_USERNAME} bot-token: ${TELEGRAM_BOT_TOKEN} -bitbucketbot: - version: 2.15.3 \ No newline at end of file +gitlab-bot: + version: 2.15.3 + scheduler: + comment: + settings: + no-comment-count: 20 + comment-count: 100 + gitlab: + token: ${GITLAB_PERSONAL_TOKEN} + username: ${GITLAB_USERNAME} + full-name: ${GITLAB_FULLNAME} + url-pull-request-open: ${GITLAB_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN + url-pull-request-close: ${GITLAB_URL}/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400 + url-pull-request-comment: ${GITLAB_URL}/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId} + url-pull-request: ${GITLAB_URL}/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/overview + url-users: ${GITLAB_URL}/rest/api/1.0/admin/users + teamcity: + token: ${TEAMCITY_ADMIN_TOKEN} + project-url: ${TEAMCITY_URL}/app/rest/projects + build-url: ${TEAMCITY_URL}/app/rest/builds/?locator=project:(id:{0}),branch:(default:any) \ No newline at end of file diff --git a/bot-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-create-table.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/2020-09-06-create-table.xml similarity index 100% rename from bot-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-create-table.xml rename to bot-app/src/main/resources/liquibase/v.1.0.0/2020-09-06-create-table.xml diff --git a/bot-app/src/main/resources/logback-dev.xml b/bot-app/src/main/resources/logback-dev.xml deleted file mode 100644 index e106cf3..0000000 --- a/bot-app/src/main/resources/logback-dev.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - %d{dd.MM.yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{20} - %msg%n - - - - - bitbucketbot-logs.log - - bitbucket.%d{yyyy-MM-dd}.log - 10 - 50MB - - - %d{dd.MM.yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{20} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/bot-app/src/main/resources/logback-prod.xml b/bot-app/src/main/resources/logback-prod.xml deleted file mode 100644 index 0335154..0000000 --- a/bot-app/src/main/resources/logback-prod.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - %d{dd.MM.yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{20} - %msg%n - - - - - bitbucketbot-logs.log - - bitbucket.%d{yyyy-MM-dd}.log - 10 - 50MB - - - %d{dd.MM.yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{20} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java deleted file mode 100644 index 21d62d1..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.sadtech.bot.gitlab.context.domain.entity; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * Пользователь битбакета. - * - * @author upagge [30.01.2020] - */ -@Getter -@Setter -@Entity -@Table(name = "person") -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class Person { - - /** - * Логин - */ - @Id - @EqualsAndHashCode.Include - @Column(name = "login") - private String login; - - /** - * Персональный токен из битбакета - */ - @Column(name = "bitbucket_token") - private String token; - - /** - * Идентификатор телеграма - */ - @Column(name = "telegram_id") - private Long telegramId; - - /** - * ФИО - */ - @Column(name = "full_name") - private String fullName; - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingHistory.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingHistory.java deleted file mode 100644 index 9c14969..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingHistory.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.sadtech.bot.gitlab.context.domain.entity; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Setter; -import org.sadtech.bot.gitlab.context.domain.PointType; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import java.time.LocalDateTime; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Getter -@Setter -@Entity -@Table(name = "rating_history") -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class RatingHistory { - - @Id - @Column(name = "id") - @EqualsAndHashCode.Include - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "login") - private String login; - - @Column(name = "points") - private Integer points; - - @Enumerated(EnumType.STRING) - @Column(name = "type") - private PointType type; - - @Column(name = "date_add") - private LocalDateTime dateAdd; - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingList.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingList.java deleted file mode 100644 index c0298e6..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/RatingList.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sadtech.bot.gitlab.context.domain.entity; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ - -@Getter -@Setter -@Entity -@Table(name = "rating_list") -@EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class RatingList implements Comparable { - - @Id - @Column(name = "login") - @EqualsAndHashCode.Include - private String login; - - @Column(name = "points") - private Integer points; - - @Column(name = "number") - private Integer number; - - @Override - public int compareTo(@NonNull RatingList ratingList) { - return Integer.compare(ratingList.getPoints(), points); - } - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java deleted file mode 100644 index 1311ce0..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.sadtech.bot.gitlab.context.repository; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.entity.Person; - -import java.util.List; -import java.util.Optional; -import java.util.Set; - -/** - * // TODO: 06.09.2020 Добавить описание. - * - * @author upagge 06.09.2020 - */ -public interface PersonRepository { - - Person save(@NonNull Person person); - - boolean existsByTelegramId(Long chatId); - - boolean existsByLogin(String login); - - List findAllByTelegramIdNotNullAndTokenNotNull(); - - Set findAllTelegramIdByLogin(Set logins); - - Optional findByLogin(@NonNull String login); - - Optional findByTelegramId(@NonNull Long telegramId); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingHistoryRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingHistoryRepository.java deleted file mode 100644 index e6842e1..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingHistoryRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.bot.gitlab.context.repository; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.entity.RatingHistory; -import org.sadtech.haiti.context.repository.SimpleManagerRepository; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -public interface RatingHistoryRepository extends SimpleManagerRepository { - - List findAllByDateAddBetween(@NonNull LocalDateTime from, @NonNull LocalDateTime to); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingListRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingListRepository.java deleted file mode 100644 index 9643e8c..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/RatingListRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sadtech.bot.gitlab.context.repository; - -import org.sadtech.bot.gitlab.context.domain.entity.RatingList; -import org.sadtech.haiti.context.repository.SimpleManagerRepository; - -import java.util.List; -import java.util.Optional; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -public interface RatingListRepository extends SimpleManagerRepository { - - Optional getByLogin(String login); - - List findFirstThree(); - - List findLastThree(); - - long count(); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java deleted file mode 100644 index 03f0db4..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.sadtech.bot.gitlab.context.service; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.entity.Person; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -public interface PersonService { - - Set existsByLogin(@NonNull Set logins); - - Person reg(@NonNull Person user); - - List getAllRegister(); - - Set getAllTelegramIdByLogin(Set logins); - - Person create(@NonNull Person person); - - List createAll(Collection newUsers); - - boolean existsByTelegram(Long telegramId); - - Optional getByTelegramId(@NonNull Long telegramId); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/RatingService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/RatingService.java deleted file mode 100644 index a8406a7..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/RatingService.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.bot.gitlab.context.service; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.PointType; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -public interface RatingService { - - void addRating(@NonNull String login, @NonNull PointType type, @NonNull Integer points); - - void ratingRecalculation(); - - String getRatingTop(@NonNull String login); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/parser/PersonParser.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/parser/PersonParser.java deleted file mode 100644 index b5427b6..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/parser/PersonParser.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.sadtech.bot.gitlab.context.service.parser; - -/** - * // TODO: 06.09.2020 Добавить описание. - * - * @author upagge 06.09.2020 - */ -public interface PersonParser { - - /** - * Извлечение новых пользователей SCV. - */ - void scanNewPerson(); - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/BitbucketProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java similarity index 77% rename from bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/BitbucketProperty.java rename to bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java index 596aa5f..3fa4ab5 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/BitbucketProperty.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java @@ -13,12 +13,13 @@ import org.springframework.stereotype.Component; @Getter @Setter @Component -@ConfigurationProperties("bitbucketbot.bitbucket") -public class BitbucketProperty { +@ConfigurationProperties("gitlab-bot.gitlab") +public class GitlabProperty { + + private String username; + + private String fullName; - /** - * Токен администратора - */ private String token; /** @@ -41,9 +42,4 @@ public class BitbucketProperty { */ private String urlPullRequest; - /** - * Адрес на получение пользователей битбакет - */ - private String urlUsers; - } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/RatingProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/RatingProperty.java deleted file mode 100644 index 7b9c125..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/RatingProperty.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.sadtech.bot.gitlab.core.config.properties; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * // TODO: 25.10.2020 Добавить описание. - * - * @author upagge 25.10.2020 - */ -@Getter -@Setter -@Component -@ConfigurationProperties(prefix = "bitbucketbot.rating") -public class RatingProperty { - - boolean enabled = false; - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/scheduler/NotificationScheduler.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/scheduler/NotificationScheduler.java index 90cd306..6160c31 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/scheduler/NotificationScheduler.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/scheduler/NotificationScheduler.java @@ -2,12 +2,10 @@ package org.sadtech.bot.gitlab.core.scheduler; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.EntityType; -import org.sadtech.bot.gitlab.context.domain.entity.Person; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.notify.GoodMorningNotify; import org.sadtech.bot.gitlab.context.domain.notify.SimpleTextNotify; import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.utils.Smile; import org.sadtech.bot.gitlab.core.config.properties.AppProperty; @@ -31,7 +29,6 @@ public class NotificationScheduler { "mstruchkov", "emukhin", "imescheryakov", "kkeglev" )); - private final PersonService personService; private final PullRequestsService pullRequestsService; private final NotifyService notifyService; diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java index d8fd0c8..4fd92a0 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java @@ -11,7 +11,6 @@ import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.repository.CommentRepository; import org.sadtech.bot.gitlab.context.service.CommentService; import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.sadtech.bot.gitlab.context.service.RatingService; import org.sadtech.bot.gitlab.context.service.TaskService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.util.Assert; diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java deleted file mode 100644 index 095dda0..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.sadtech.bot.gitlab.core.service.impl; - -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.exception.RegException; -import org.sadtech.bot.gitlab.context.repository.PersonRepository; -import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.core.config.properties.BitbucketProperty; -import org.sadtech.bot.gitlab.core.utils.Utils; -import org.sadtech.haiti.core.util.Assert; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -@Service -public class PersonServiceImpl implements PersonService { - - private final PersonRepository personRepository; - private final BitbucketProperty bitbucketProperty; - - private final NotifyService notifyService; - - public PersonServiceImpl( - PersonRepository personRepository, - BitbucketProperty bitbucketProperty, - @Lazy NotifyService notifyService - ) { - this.personRepository = personRepository; - this.bitbucketProperty = bitbucketProperty; - this.notifyService = notifyService; - } - - @Override - public Set existsByLogin(@NonNull Set logins) { - return logins.stream() - .filter(personRepository::existsByLogin) - .collect(Collectors.toSet()); - } - - @Override - public Person reg(@NonNull Person user) { - final Optional optUser = personRepository.findByLogin(user.getLogin()); - if (optUser.isPresent()) { - final Person oldUser = optUser.get(); - if (oldUser.getTelegramId() == null) { - Optional sheetJson = Utils.urlToJson(bitbucketProperty.getUrlPullRequestClose(), user.getToken(), Object.class); - if (sheetJson.isPresent()) { - oldUser.setTelegramId(user.getTelegramId()); - - defaultSettings(oldUser); - - return personRepository.save(oldUser); - } else { - throw new RegException("Ваш токен не валиден"); - } - } else { - throw new RegException("Вы уже авторизованы в системе"); - } - } - throw new RegException("Пользователь не найден, подождите обновление базы пользователей!"); - } - - private void defaultSettings(Person person) { - final NotifySetting notifySetting = new NotifySetting(); - notifySetting.setLogin(person.getLogin()); - notifySetting.setStartReceiving(LocalDateTime.now()); - notifyService.saveSettings(notifySetting); - } - - @Override - public List getAllRegister() { - return personRepository.findAllByTelegramIdNotNullAndTokenNotNull(); - } - - @Override - public Set getAllTelegramIdByLogin(Set logins) { - return personRepository.findAllTelegramIdByLogin(logins); - } - - @Override - public Person create(@NonNull Person person) { - Assert.isNotNull(person.getLogin(), "При создании пользователя должен присутствовать логин"); - return personRepository.save(person); - } - - @Override - public List createAll(Collection newPersons) { - 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/gitlab/core/service/impl/PullRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PullRequestsServiceImpl.java index 7ef89c0..dd91e10 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PullRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PullRequestsServiceImpl.java @@ -19,8 +19,6 @@ import org.sadtech.bot.gitlab.context.exception.UpdateException; import org.sadtech.bot.gitlab.context.repository.PullRequestsRepository; import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; -import org.sadtech.bot.gitlab.context.service.RatingService; -import org.sadtech.bot.gitlab.core.config.properties.RatingProperty; import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.ReviewerStatus; import org.sadtech.haiti.context.page.Pagination; diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/RatingServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/RatingServiceImpl.java deleted file mode 100644 index 49bf273..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/RatingServiceImpl.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.sadtech.bot.gitlab.core.service.impl; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.PointType; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.domain.entity.RatingHistory; -import org.sadtech.bot.gitlab.context.domain.entity.RatingList; -import org.sadtech.bot.gitlab.context.exception.NotFoundException; -import org.sadtech.bot.gitlab.context.repository.RatingHistoryRepository; -import org.sadtech.bot.gitlab.context.repository.RatingListRepository; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.context.service.RatingService; -import org.sadtech.bot.gitlab.context.utils.Smile; -import org.springframework.stereotype.Service; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Service -@RequiredArgsConstructor -public class RatingServiceImpl implements RatingService { - - private final RatingHistoryRepository ratingHistoryRepository; - private final RatingListRepository ratingListRepository; - private final PersonService personService; - - @Override - public void addRating(@NonNull String login, @NonNull PointType type, @NonNull Integer points) { - final RatingHistory ratingHistory = new RatingHistory(); - ratingHistory.setLogin(login); - ratingHistory.setPoints(points); - ratingHistory.setType(type); - ratingHistory.setDateAdd(LocalDateTime.now()); - ratingHistoryRepository.save(ratingHistory); - } - - @Override - public void ratingRecalculation() { - AtomicInteger i = new AtomicInteger(); - final List newRatingList = ratingHistoryRepository.findAllByDateAddBetween(LocalDateTime.now().minusDays(30L), LocalDateTime.now()).stream() - .collect(Collectors.groupingBy(RatingHistory::getLogin, Collectors.summingInt(RatingHistory::getPoints))) - .entrySet().stream() - .map(this::createRatingList) - .collect(Collectors.toList()); - final Set ratingListLogins = newRatingList.stream() - .map(RatingList::getLogin) - .collect(Collectors.toSet()); - final Set regLogins = personService.getAllRegister().stream() - .map(Person::getLogin) - .collect(Collectors.toSet()); - newRatingList.addAll( - regLogins.stream() - .filter(s -> !ratingListLogins.contains(s)) - .map(this::createEmptyRatingList) - .collect(Collectors.toList()) - ); - ratingListRepository.saveAll( - newRatingList.stream() - .sorted() - .peek(ratingList -> ratingList.setNumber(i.getAndIncrement())) - .collect(Collectors.toList()) - ); - } - - private RatingList createEmptyRatingList(String s) { - final RatingList ratingList = new RatingList(); - ratingList.setLogin(s); - ratingList.setPoints(0); - return ratingList; - } - - private RatingList createRatingList(Map.Entry entry) { - final RatingList ratingList = new RatingList(); - ratingList.setLogin(entry.getKey()); - ratingList.setPoints(entry.getValue()); - return ratingList; - } - - @Override - public String getRatingTop(@NonNull String login) { - final RatingList personRating = ratingListRepository.getByLogin(login) - .orElseThrow(() -> new NotFoundException("Пользователь не найден")); - - final long countPerson = ratingListRepository.count(); - final String threeMessage = ratingListRepository.findFirstThree().stream() - .map(this::createString) - .collect(Collectors.joining("\n")); - final String lastMessage = ratingListRepository.findLastThree().stream() - .limit(countPerson - 3 < 0 ? 0 : countPerson - 3) - .map(this::createString) - .collect(Collectors.joining("\n")); - - String message; - - if (personRating.getPoints() == 0) { - message = Smile.SADLY + " У вас не обнаружена активность в битбакете, поэтому вы не учавствуйте в рейтинге" + - "\n\n" + Smile.TOP + " Рейтинговая таблица " + Smile.TOP + Smile.HR + threeMessage + "\n... ... ... ... ...\n"; - } else { - message = Smile.TOP + " Рейтинговая таблица " + Smile.TOP + Smile.HR + threeMessage; - final Integer numberRatingList = personRating.getNumber(); - if (numberRatingList <= 2) { - if (countPerson > 3) { - message += "\n... ... ... ... ...\n"; - } - } else if (numberRatingList > 3 && numberRatingList <= (countPerson - 3)) { - message += "\n... ... ... ... ...\n" + personRating.getNumber() + ": " + personRating.getLogin() + "\n... ... ... ... ...\n"; - } else { - message += "\n... ... ... ... ...\n"; - } - } - message += lastMessage; - return message; - } - - private String createString(RatingList ratingList) { - String message = ""; - final Integer number = ratingList.getNumber(); - if (number == 0) { - message += Smile.TOP_ONE.getValue() + " " + ratingList.getLogin() + " " + Smile.TOP_ONE.getValue(); - } else if (number == 1) { - message += Smile.TOP_TWO.getValue() + " " + ratingList.getLogin() + " " + Smile.TOP_TWO.getValue(); - } else if (number == 2) { - message += Smile.TOP_THREE.getValue() + " " + ratingList.getLogin() + " " + Smile.TOP_THREE.getValue(); - } else { - message += Smile.KAKASHKA.getValue() + " " + ratingList.getLogin(); - } - return message; - } - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java index d350319..713274d 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java @@ -16,7 +16,6 @@ import org.sadtech.bot.gitlab.context.repository.TaskRepository; import org.sadtech.bot.gitlab.context.service.CommentService; import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; -import org.sadtech.bot.gitlab.context.service.RatingService; import org.sadtech.bot.gitlab.context.service.TaskService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.util.Assert; diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/utils/Utils.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/utils/Utils.java deleted file mode 100644 index 368d6e1..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/utils/Utils.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.sadtech.bot.gitlab.core.utils; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -import java.io.IOException; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -/** - * @author upagge [30.01.2020] - */ -@Slf4j -public class Utils { - - private static final ObjectMapper objectMapper; - - static { - objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - } - - private static final OkHttpClient client = new OkHttpClient.Builder() - .connectTimeout(60, TimeUnit.SECONDS) - .writeTimeout(60, TimeUnit.SECONDS) - .readTimeout(60, TimeUnit.SECONDS) - .build(); - - private Utils() { - throw new IllegalStateException("Утилитарный класс"); - } - - public static Optional urlToJson(@NonNull String urlValue, @NonNull String token, @NonNull Class classOfT) { - Request request = new Request.Builder() - .url(urlValue) - .header("Authorization", "Bearer " + token) - .header("Accept", "text/html,application/xhtml+xml,application/json") - .build(); - try (final Response execute = client.newCall(request).execute()) { - if (execute.isSuccessful() && execute.body() != null) { - return Optional.ofNullable(objectMapper.readValue(execute.body().string(), classOfT)); - } - } catch (IOException e) { - log.error(e.getMessage()); - } - return Optional.empty(); - } - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java deleted file mode 100644 index 102fb2e..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.sadtech.bot.gitlab.data.impl; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.repository.PersonRepository; -import org.sadtech.bot.gitlab.data.jpa.PersonJpaRepository; -import org.springframework.dao.InvalidDataAccessResourceUsageException; -import org.springframework.stereotype.Repository; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -/** - * // TODO: 06.09.2020 Добавить описание. - * - * @author upagge 06.09.2020 - */ -@Slf4j -@Repository -@RequiredArgsConstructor -public class PersonRepositoryImpl implements PersonRepository { - - private final PersonJpaRepository jpaRepository; - - @Override - public Person save(@NonNull Person person) { - return jpaRepository.save(person); - } - - @Override - public boolean existsByTelegramId(Long chatId) { - return jpaRepository.existsByTelegramId(chatId); - } - - @Override - public boolean existsByLogin(String login) { - try { - return jpaRepository.existsByLogin(login); - } catch (InvalidDataAccessResourceUsageException e) { - log.error(e.getMessage()); - } - return false; - } - - @Override - public List findAllByTelegramIdNotNullAndTokenNotNull() { - try { - return jpaRepository.findAllByTelegramIdNotNullAndTokenNotNull(); - } catch (InvalidDataAccessResourceUsageException e) { - log.error(e.getMessage()); - } - return Collections.emptyList(); - } - - @Override - public Set findAllTelegramIdByLogin(Set logins) { - return jpaRepository.findAllTelegramIdByLogin(logins); - } - - @Override - public Optional findByLogin(@NonNull String login) { - return jpaRepository.findById(login); - } - - @Override - public Optional findByTelegramId(@NonNull Long telegramId) { - return jpaRepository.findByTelegramId(telegramId); - } - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingHistoryRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingHistoryRepositoryImpl.java deleted file mode 100644 index 4558aa7..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingHistoryRepositoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sadtech.bot.gitlab.data.impl; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.entity.RatingHistory; -import org.sadtech.bot.gitlab.context.repository.RatingHistoryRepository; -import org.sadtech.bot.gitlab.data.jpa.RatingHistoryJpaRepository; -import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.stereotype.Repository; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Repository -public class RatingHistoryRepositoryImpl extends AbstractSimpleManagerRepository implements RatingHistoryRepository { - - private final RatingHistoryJpaRepository jpaRepository; - - public RatingHistoryRepositoryImpl(RatingHistoryJpaRepository jpaRepository) { - super(jpaRepository); - this.jpaRepository = jpaRepository; - } - - @Override - public List findAllByDateAddBetween(@NonNull LocalDateTime from, @NonNull LocalDateTime to) { - return jpaRepository.findAllByDateAddBetween(from, to); - } - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingListRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingListRepositoryImpl.java deleted file mode 100644 index 47f0adb..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/RatingListRepositoryImpl.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.sadtech.bot.gitlab.data.impl; - -import org.sadtech.bot.gitlab.context.domain.entity.RatingList; -import org.sadtech.bot.gitlab.context.repository.RatingListRepository; -import org.sadtech.bot.gitlab.data.jpa.RatingListJpaRepository; -import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Repository -public class RatingListRepositoryImpl extends AbstractSimpleManagerRepository implements RatingListRepository { - - private final RatingListJpaRepository jpaRepository; - - public RatingListRepositoryImpl(RatingListJpaRepository jpaRepository) { - super(jpaRepository); - this.jpaRepository = jpaRepository; - } - - @Override - public Optional getByLogin(String login) { - return jpaRepository.findById(login); - } - - @Override - public List findFirstThree() { - return jpaRepository.findTop3ByPointsGreaterThanOrderByNumberAsc(0); - } - - @Override - public List findLastThree() { - return jpaRepository.findTop3ByPointsGreaterThanOrderByNumberDesc(0); - } - - @Override - public long count() { - return jpaRepository.countByNumberGreaterThan(0); - } - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java deleted file mode 100644 index f9f9a0c..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.sadtech.bot.gitlab.data.jpa; - -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; -import java.util.Set; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [30.01.2020] - */ -@Repository -public interface PersonJpaRepository extends JpaRepository { - - boolean existsByTelegramId(Long chatId); - - boolean existsByLogin(String login); - - List findAllByTelegramIdNotNullAndTokenNotNull(); - - @Query("SELECT u.telegramId FROM Person u WHERE u.login=:login") - Long findTelegramIdByLogin(String login); - - @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-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingHistoryJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingHistoryJpaRepository.java deleted file mode 100644 index 56883ba..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingHistoryJpaRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.bot.gitlab.data.jpa; - - -import org.sadtech.bot.gitlab.context.domain.entity.RatingHistory; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -public interface RatingHistoryJpaRepository extends JpaRepository { - - List findAllByDateAddBetween(LocalDateTime from, LocalDateTime to); - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingListJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingListJpaRepository.java deleted file mode 100644 index 3c71741..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/RatingListJpaRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sadtech.bot.gitlab.data.jpa; - - -import org.sadtech.bot.gitlab.context.domain.entity.RatingList; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -public interface RatingListJpaRepository extends JpaRepository { - - List findTop3ByPointsGreaterThanOrderByNumberAsc(Integer points); - - List findTop3ByPointsGreaterThanOrderByNumberDesc(Integer points); - - Long countByNumberGreaterThan(Integer points); - -} diff --git a/bitbucketbot-core/pom.xml b/gitlab-core/pom.xml similarity index 100% rename from bitbucketbot-core/pom.xml rename to gitlab-core/pom.xml diff --git a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToComment.java b/gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToComment.java similarity index 100% rename from bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToComment.java rename to gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToComment.java diff --git a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToTaskConvert.java b/gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToTaskConvert.java similarity index 100% rename from bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToTaskConvert.java rename to gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/CommentJsonToTaskConvert.java diff --git a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java b/gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java similarity index 96% rename from bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java rename to gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java index da3d162..c09f5c4 100644 --- a/bitbucketbot-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java +++ b/gitlab-core/src/main/java/org/sadtech/bot/vcs/bitbucket/core/service/converter/PullRequestJsonConverter.java @@ -4,11 +4,11 @@ import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.domain.entity.Reviewer; import org.sadtech.bot.gitlab.core.utils.StringUtils; +import org.sadtech.bot.gitlab.sdk.domain.AuthorJson; import org.sadtech.bot.gitlab.sdk.domain.Outcome; import org.sadtech.bot.gitlab.sdk.domain.Properties; import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson; import org.sadtech.bot.gitlab.sdk.domain.PullRequestState; -import org.sadtech.bot.gitlab.sdk.domain.UserDecisionJson; import org.sadtech.bot.gitlab.sdk.domain.UserPullRequestStatus; import org.sadtech.bot.vsc.context.domain.PullRequestStatus; import org.sadtech.bot.vsc.context.domain.ReviewerStatus; @@ -23,6 +23,32 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class PullRequestJsonConverter implements Converter { + public static PullRequestStatus convertPullRequestStatus(PullRequestState state) { + switch (state) { + case OPENED: + return PullRequestStatus.OPEN; + case MERGED: + return PullRequestStatus.MERGED; + case DECLINED: + return PullRequestStatus.DECLINED; + default: + throw new ConvertException("Неподдерживаемый тип ПР"); + } + } + + private static ReviewerStatus convertStatusReviewer(UserPullRequestStatus status) { + switch (status) { + case APPROVED: + return ReviewerStatus.APPROVED; + case NEEDS_WORK: + return ReviewerStatus.UNAPPROVED; + case UNAPPROVED: + return ReviewerStatus.NEEDS_WORK; + default: + throw new ConvertException("Неподдерживаемый статус ревьювера"); + } + } + @Override public PullRequest convert(PullRequestJson json) { @@ -54,20 +80,7 @@ public class PullRequestJsonConverter implements Converter convertReviewers(List jsonReviewers) { + private List convertReviewers(List jsonReviewers) { return jsonReviewers.stream() .map( jsonReviewer -> { @@ -80,17 +93,4 @@ public class PullRequestJsonConverter implements Converter reviewers; - private FromRefJson fromRef; - private Properties properties; + private AuthorJson author; + + @JsonProperty("web_url") + private String webUrl; + + @JsonProperty("has_conflicts") + private String conflicts; } diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java index 9b61eb6..f1d1719 100644 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java @@ -7,6 +7,6 @@ package org.sadtech.bot.gitlab.sdk.domain; */ public enum PullRequestState { - OPEN, MERGED, DECLINED + OPENED, MERGED, DECLINED } diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/UserDecisionJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/UserDecisionJson.java deleted file mode 100644 index d409127..0000000 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/UserDecisionJson.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sadtech.bot.gitlab.sdk.domain; - -import lombok.Data; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [31.01.2020] - */ -@Data -public class UserDecisionJson { - - private UserJson user; - private BitbucketUserRole role; - private Boolean approved; - private UserPullRequestStatus status; - -} diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/sheet/PullRequestSheetJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/sheet/PullRequestSheetJson.java deleted file mode 100644 index 93292fa..0000000 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/sheet/PullRequestSheetJson.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sadtech.bot.gitlab.sdk.domain.sheet; - -import org.sadtech.bot.gitlab.sdk.domain.PullRequestJson; -import org.sadtech.bot.gitlab.sdk.domain.Sheet; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [02.02.2020] - */ -public class PullRequestSheetJson extends Sheet { - -} diff --git a/pom.xml b/pom.xml index 65a15cc..3ab693d 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ bot-core bot-app teamcity - bitbucketbot-core + gitlab-core bot-data @@ -171,6 +171,12 @@ ${haiti.database.version} + + org.sadtech.haiti + haiti-utils + 1.0-SNAPSHOT + + org.sadtech.bot.godfather telegram-bot diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/config/property/TeamcityProperty.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/config/property/TeamcityProperty.java index c2759c5..8e9a7e4 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/config/property/TeamcityProperty.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/config/property/TeamcityProperty.java @@ -13,7 +13,7 @@ import org.springframework.stereotype.Component; @Getter @Setter @Component -@ConfigurationProperties(prefix = "bitbucketbot.teamcity") +@ConfigurationProperties(prefix = "gitlab-bot.teamcity") public class TeamcityProperty { private String token; diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/BuildShortParser.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/BuildShortParser.java index 4b07dcb..f945cb4 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/BuildShortParser.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/BuildShortParser.java @@ -7,7 +7,6 @@ package org.sadtech.bot.gitlab.teamcity.core.service.parser; */ import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.core.utils.Utils; import org.sadtech.bot.gitlab.teamcity.core.config.property.TeamcityProperty; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.BuildShort; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject; diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/TeamcityProjectParser.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/TeamcityProjectParser.java index fc64ec8..8399087 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/TeamcityProjectParser.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/parser/TeamcityProjectParser.java @@ -1,7 +1,6 @@ package org.sadtech.bot.gitlab.teamcity.core.service.parser; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.core.utils.Utils; import org.sadtech.bot.gitlab.teamcity.core.config.property.TeamcityProperty; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcityProject; import org.sadtech.bot.gitlab.teamcity.core.service.TeamcityProjectService; 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 39d8a16..98b6d12 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 @@ -6,7 +6,6 @@ import org.sadtech.bot.gitlab.context.domain.notify.Notify; import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.service.ChatService; import org.sadtech.bot.gitlab.context.service.MessageSendService; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.service.sender.Sending; import org.springframework.stereotype.Service; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/RatingTopProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/RatingTopProcessing.java deleted file mode 100644 index d795491..0000000 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/RatingTopProcessing.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.sadtech.bot.gitlab.telegram.service.unit; - -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.entity.Person; -import org.sadtech.bot.gitlab.context.exception.NotFoundException; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.context.service.RatingService; -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; - -/** - * // TODO: 01.10.2020 Добавить описание. - * - * @author upagge 01.10.2020 - */ -@Component -@RequiredArgsConstructor -public class RatingTopProcessing implements ProcessingData { - - private final RatingService ratingService; - private final PersonService personService; - - @Override - public BoxAnswer processing(Message content) { - final Person person = personService.getByTelegramId(content.getPersonId()) - .orElseThrow(() -> new NotFoundException("Пользователь не найден")); - return BoxAnswer.builder() - .message(ratingService.getRatingTop(person.getLogin())) - .build(); - } - -} 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 568d8bd..16c4570 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 @@ -2,10 +2,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.TaskStatus; -import org.sadtech.bot.gitlab.context.domain.entity.Person; import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.exception.NotFoundException; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.TaskService; import org.sadtech.social.bot.service.usercode.ProcessingData; import org.sadtech.social.core.domain.BoxAnswer; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java index 3052669..6b43fe1 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java @@ -1,10 +1,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.entity.Person; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.exception.NotFoundException; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.utils.MessageUtils; import org.sadtech.bot.vsc.context.domain.ReviewerStatus; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java index 0a82b8e..8a0e4c9 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java @@ -1,10 +1,8 @@ package org.sadtech.bot.gitlab.telegram.service.unit.pullrequest; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.entity.Person; import org.sadtech.bot.gitlab.context.domain.entity.PullRequest; import org.sadtech.bot.gitlab.context.exception.NotFoundException; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.PullRequestsService; import org.sadtech.bot.gitlab.context.utils.MessageUtils; import org.sadtech.bot.vsc.context.domain.PullRequestStatus; 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 index 9f836fc..b7c1f5a 100644 --- 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 @@ -4,10 +4,8 @@ import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; -import org.sadtech.bot.gitlab.context.domain.entity.Person; import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.service.NotifyService; -import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.social.bot.domain.unit.AnswerProcessing; import org.sadtech.social.bot.domain.unit.AnswerText; import org.sadtech.social.core.domain.BoxAnswer; 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 34b4cb8..9c88b9e 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 @@ -1,8 +1,6 @@ package org.sadtech.bot.gitlab.telegram.unit; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.service.PersonService; -import org.sadtech.bot.gitlab.telegram.service.unit.RatingTopProcessing; import org.sadtech.bot.gitlab.telegram.service.unit.TaskProcessing; import org.sadtech.bot.gitlab.telegram.utils.GeneratorKeyBoards; import org.sadtech.social.bot.domain.unit.AnswerCheck;