From a6e3dc785c3816c4851fd2d7678f06178e283478 Mon Sep 17 00:00:00 2001 From: upagge Date: Wed, 7 Oct 2020 09:56:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=87?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yaml | 2 + .../src/main/resources/application-prod.yaml | 2 + .../v.2.0.0/2020-09-06-cumulative.xml | 1 + .../2020-10-07-add-colum-reviewer-date.xml | 12 ++++ .../src/main/resources/logback-dev.xml | 24 +++++++ .../{logback.xml => logback-prod.xml} | 0 .../bot/vcs/core/domain/entity/Reviewer.java | 4 ++ .../core/domain/notify/GoodMorningNotify.java | 33 ++++------ .../vcs/core/service/PullRequestsService.java | 6 ++ .../service/impl/PullRequestsServiceImpl.java | 6 ++ .../bot/vcs/core/utils/MessageUtils.java | 21 ++++-- .../PullRequestNeedWorkProcessing.java | 41 ++++++++++++ .../PullRequestReviewProcessing.java} | 4 +- .../telegram/unit/PullRequestUnitConfig.java | 64 +++++++++++++++++++ .../bot/vcs/telegram/unit/UnitConfig.java | 15 +---- .../telegram/utils/GeneratorKeyBoards.java | 2 +- 16 files changed, 197 insertions(+), 40 deletions(-) create mode 100644 bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-07-add-colum-reviewer-date.xml create mode 100644 bitbucket-app/src/main/resources/logback-dev.xml rename bitbucket-app/src/main/resources/{logback.xml => logback-prod.xml} (100%) create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java rename telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/{PullRequestProcessing.java => pullrequest/PullRequestReviewProcessing.java} (92%) create mode 100644 telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/PullRequestUnitConfig.java diff --git a/bitbucket-app/src/main/resources/application-dev.yaml b/bitbucket-app/src/main/resources/application-dev.yaml index b803227..3fcf33b 100644 --- a/bitbucket-app/src/main/resources/application-dev.yaml +++ b/bitbucket-app/src/main/resources/application-dev.yaml @@ -16,6 +16,8 @@ spring: jdbc: lob: non_contextual_creation: true +logging: + config: classpath:logback-dev.xml bitbucketbot: scheduler: person: 0 */1 * * * * diff --git a/bitbucket-app/src/main/resources/application-prod.yaml b/bitbucket-app/src/main/resources/application-prod.yaml index 52b67e4..13a5397 100644 --- a/bitbucket-app/src/main/resources/application-prod.yaml +++ b/bitbucket-app/src/main/resources/application-prod.yaml @@ -16,6 +16,8 @@ spring: jdbc: lob: non_contextual_creation: true +logging: + config: classpath:logback-prod.xml bitbucketbot: scheduler: person: 0 0 0 */1 * * diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml index 3638d94..dfe762d 100644 --- a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-09-06-cumulative.xml @@ -9,5 +9,6 @@ + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-07-add-colum-reviewer-date.xml b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-07-add-colum-reviewer-date.xml new file mode 100644 index 0000000..b0952f7 --- /dev/null +++ b/bitbucket-app/src/main/resources/liquibase/v.2.0.0/2020-10-07-add-colum-reviewer-date.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/bitbucket-app/src/main/resources/logback-dev.xml b/bitbucket-app/src/main/resources/logback-dev.xml new file mode 100644 index 0000000..e106cf3 --- /dev/null +++ b/bitbucket-app/src/main/resources/logback-dev.xml @@ -0,0 +1,24 @@ + + + + %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/bitbucket-app/src/main/resources/logback.xml b/bitbucket-app/src/main/resources/logback-prod.xml similarity index 100% rename from bitbucket-app/src/main/resources/logback.xml rename to bitbucket-app/src/main/resources/logback-prod.xml diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/Reviewer.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/Reviewer.java index 5378527..79f9579 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/Reviewer.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/entity/Reviewer.java @@ -17,6 +17,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; +import java.time.LocalDateTime; /** * Ревьювер пулреквеста. @@ -52,6 +53,9 @@ public class Reviewer { @Column(name = "status") private ReviewerStatus status; + @Column(name = "date_change") + private LocalDateTime dateChange; + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH, optional = false) @JoinColumn(name = "pull_request_id") private PullRequest pullRequest; diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java index d10ae64..35d5a37 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/domain/notify/GoodMorningNotify.java @@ -2,7 +2,6 @@ package org.sadtech.bot.vcs.core.domain.notify; import lombok.Builder; import lombok.Getter; -import lombok.NonNull; import org.sadtech.bot.vcs.core.domain.entity.PullRequest; import org.sadtech.bot.vcs.core.utils.MessageUtils; import org.sadtech.bot.vcs.core.utils.Smile; @@ -10,6 +9,7 @@ import org.sadtech.bot.vcs.core.utils.UpdateDataComparator; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * // TODO: 20.09.2020 Добавить описание. @@ -36,35 +36,28 @@ public class GoodMorningNotify extends Notify { this.pullRequestsNeedWork = pullRequestsNeedWork; } - private static String needWorkPr(@NonNull List pullRequestsNeedWork) { - final StringBuilder message = new StringBuilder(); - pullRequestsNeedWork.stream() - .limit(3) - .forEach( - pullRequest -> message.append("-- ").append(link(pullRequest.getTitle(), pullRequest.getUrl())).append(Smile.BR) - ); - return message.toString(); - } - - private static String link(String name, String url) { - return "[" + name + "](" + url + ")"; - } - @Override public String generateMessage() { StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро* ").append(Smile.SUN).append(Smile.HR); if (!pullRequestsReviews.isEmpty()) { message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР!").append(Smile.TWO_BR) .append("Самые старые:").append(Smile.BR); - MessageUtils.pullRequestForReview(pullRequestsReviews).ifPresent(message::append); + MessageUtils.pullRequestForReview( + pullRequestsReviews.stream() + .limit(3) + .collect(Collectors.toList()) + ).ifPresent(message::append); } else { message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(Smile.MEGA_FUN).append(Smile.TWO_BR) .append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BR); } - if (!pullRequestsNeedWork.isEmpty()) { - message.append(Smile.BR).append(Smile.DANGEROUS).append("Требуется доработать ").append(pullRequestsNeedWork.size()).append(" ПР:").append(Smile.BR); - message.append(needWorkPr(pullRequestsNeedWork)).append(Smile.BR); - } + MessageUtils.pullRequestForNeedWork( + pullRequestsNeedWork.stream() + .limit(3) + .collect(Collectors.toList()) + ).ifPresent( + messageNeedWork -> message.append(Smile.BR).append(Smile.DANGEROUS).append("Требуется доработать ").append(pullRequestsNeedWork.size()).append(" ПР:").append(Smile.BR).append(messageNeedWork) + ); message .append(Smile.BR).append("Удачного дня ").append(Smile.FLOWER).append(Smile.TWO_BR); return message.toString(); diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java index 2b66e29..4a635e8 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/PullRequestsService.java @@ -25,6 +25,12 @@ public interface PullRequestsService extends SimpleManagerService getAllByReviewerAndStatuses(@NonNull String login, @NonNull ReviewerStatus reviewerStatus, @NonNull Set pullRequestStatuses); + /** + * Получить все ПР с определенным статусом, который есть хотя бы у одного ревьювера. + * + * @param login Автор ПР. + * @param status Статус ревьювера. + */ List getAllByAuthorAndReviewerStatus(@NonNull String login, @NonNull ReviewerStatus status); /** diff --git a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java index 6326139..f49975f 100644 --- a/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/vcs/core/service/impl/PullRequestsServiceImpl.java @@ -31,6 +31,7 @@ import org.sadtech.bot.vcs.core.service.RatingService; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -64,6 +65,10 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService reviewer.setDateChange(LocalDateTime.now()) + ); + final PullRequest newPullRequest = pullRequestsRepository.save(pullRequest); ratingService.addRating(newPullRequest.getAuthorLogin(), PointType.CREATE_PULL_REQUEST, PointType.CREATE_PULL_REQUEST.getPoints()); @@ -174,6 +179,7 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService pullRequestForReview(@NonNull List pullRequestsReviews) { if (!pullRequestsReviews.isEmpty()) { return Optional.of( pullRequestsReviews.stream() .sorted(COMPARATOR) - .limit(PR_COUNT) - .map(MessageUtils::topPr) + .map(MessageUtils::generateStringItemPullRequestReview) .collect(Collectors.joining("\n")) ); } return Optional.empty(); } - private static String topPr(PullRequest pullRequest) { + public static Optional pullRequestForNeedWork(@NonNull List pullRequestNeedWork) { + if (!pullRequestNeedWork.isEmpty()) { + return Optional.of( + pullRequestNeedWork.stream() + .map(MessageUtils::generateStringItemPullRequestNeedWork) + .collect(Collectors.joining("\n")) + ); + } + return Optional.empty(); + } + + private static String generateStringItemPullRequestNeedWork(PullRequest pullRequest) { + return "-- " + link(pullRequest.getTitle(), pullRequest.getUrl()); + } + + private static String generateStringItemPullRequestReview(PullRequest pullRequest) { return Smile.statusPr(pullRequest.getUpdateDate()) + " " + link(pullRequest.getTitle(), pullRequest.getUrl()) + Smile.BR; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java new file mode 100644 index 0000000..765a2b6 --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestNeedWorkProcessing.java @@ -0,0 +1,41 @@ +package org.sadtech.bot.vcs.telegram.service.unit.pullrequest; + +import lombok.RequiredArgsConstructor; +import org.sadtech.bot.vcs.core.domain.ReviewerStatus; +import org.sadtech.bot.vcs.core.domain.entity.Person; +import org.sadtech.bot.vcs.core.domain.entity.PullRequest; +import org.sadtech.bot.vcs.core.exception.NotFoundException; +import org.sadtech.bot.vcs.core.service.PersonService; +import org.sadtech.bot.vcs.core.service.PullRequestsService; +import org.sadtech.bot.vcs.core.utils.MessageUtils; +import org.sadtech.social.bot.service.usercode.ProcessingData; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.content.Message; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * // TODO: 17.09.2020 Добавить описание. + * + * @author upagge 17.09.2020 + */ +@Component +@RequiredArgsConstructor +public class PullRequestNeedWorkProcessing implements ProcessingData { + + private final PersonService personService; + private final PullRequestsService pullRequestsService; + + @Override + public BoxAnswer processing(Message message) { + final Person person = personService.getByTelegramId(message.getPersonId()) + .orElseThrow(() -> new NotFoundException("Пользователь не найден")); + final List pullRequests = pullRequestsService.getAllByAuthorAndReviewerStatus(person.getLogin(), ReviewerStatus.UNAPPROVED); + return BoxAnswer.of( + MessageUtils.pullRequestForNeedWork(pullRequests) + .orElse("Не найдено ПРов, которые нуждаются в доработке :)") + ); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java similarity index 92% rename from telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java rename to telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java index 24a93bd..a529c0b 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/PullRequestProcessing.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/service/unit/pullrequest/PullRequestReviewProcessing.java @@ -1,4 +1,4 @@ -package org.sadtech.bot.vcs.telegram.service.unit; +package org.sadtech.bot.vcs.telegram.service.unit.pullrequest; import lombok.RequiredArgsConstructor; import org.sadtech.bot.vcs.core.domain.PullRequestStatus; @@ -24,7 +24,7 @@ import java.util.List; */ @Component @RequiredArgsConstructor -public class PullRequestProcessing implements ProcessingData { +public class PullRequestReviewProcessing implements ProcessingData { private final PersonService personService; private final PullRequestsService pullRequestsService; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/PullRequestUnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/PullRequestUnitConfig.java new file mode 100644 index 0000000..e6acb6f --- /dev/null +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/PullRequestUnitConfig.java @@ -0,0 +1,64 @@ +package org.sadtech.bot.vcs.telegram.unit; + +import org.sadtech.bot.vcs.telegram.service.unit.pullrequest.PullRequestNeedWorkProcessing; +import org.sadtech.bot.vcs.telegram.service.unit.pullrequest.PullRequestReviewProcessing; +import org.sadtech.social.bot.domain.unit.AnswerProcessing; +import org.sadtech.social.bot.domain.unit.AnswerText; +import org.sadtech.social.core.domain.BoxAnswer; +import org.sadtech.social.core.domain.content.Message; +import org.sadtech.social.core.utils.KeyBoards; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * // TODO: 02.10.2020 Добавить описание. + * + * @author upagge 02.10.2020 + */ +@Configuration +public class PullRequestUnitConfig { + + @Bean + public AnswerText menuPullRequest( + AnswerProcessing reviewPullRequest, + AnswerProcessing needWorkPullRequest + ) { + return AnswerText.builder() + .boxAnswer( + BoxAnswer.builder() + .message("Эта вкладка для работы с Pull Request") + .keyBoard( + KeyBoards.verticalMenuString( + "Нуждаются в ревью", + "Необходимо доработать" + ) + ) + .build() + ) + .phrase("Pull Requests") + .nextUnit(reviewPullRequest) + .nextUnit(needWorkPullRequest) + .build(); + } + + @Bean + public AnswerProcessing reviewPullRequest( + PullRequestReviewProcessing pullRequestReviewProcessing + ) { + return AnswerProcessing.builder() + .processingData(pullRequestReviewProcessing) + .phrase("Нуждаются в ревью") + .build(); + } + + @Bean + public AnswerProcessing needWorkPullRequest( + PullRequestNeedWorkProcessing pullRequestNeedWorkProcessing + ) { + return AnswerProcessing.builder() + .processingData(pullRequestNeedWorkProcessing) + .phrase("Необходимо доработать") + .build(); + } + +} diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java index a2eca09..618842d 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/unit/UnitConfig.java @@ -2,7 +2,6 @@ package org.sadtech.bot.vcs.telegram.unit; import lombok.RequiredArgsConstructor; import org.sadtech.bot.vcs.core.service.PersonService; -import org.sadtech.bot.vcs.telegram.service.unit.PullRequestProcessing; import org.sadtech.bot.vcs.telegram.service.unit.RatingTopProcessing; import org.sadtech.bot.vcs.telegram.service.unit.TaskProcessing; import org.sadtech.bot.vcs.telegram.utils.GeneratorKeyBoards; @@ -44,7 +43,7 @@ public class UnitConfig { @Bean public AnswerText menu( AnswerProcessing getTasks, - AnswerProcessing getPr, + AnswerText menuPullRequest, AnswerText settings, AnswerProcessing getTopRating ) { @@ -56,7 +55,7 @@ public class UnitConfig { .build() ) .nextUnit(getTasks) - .nextUnit(getPr) + .nextUnit(menuPullRequest) .nextUnit(settings) .nextUnit(getTopRating) .build(); @@ -90,16 +89,6 @@ public class UnitConfig { .build(); } - @Bean - public AnswerProcessing getPr( - PullRequestProcessing pullRequestProcessing - ) { - return AnswerProcessing.builder() - .processingData(pullRequestProcessing) - .phrase("Проверить ПР") - .build(); - } - @Bean AnswerProcessing getTopRating( RatingTopProcessing ratingTopProcessing diff --git a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java index a5cb80c..45f3cfb 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/vcs/telegram/utils/GeneratorKeyBoards.java @@ -16,7 +16,7 @@ public class GeneratorKeyBoards { public static KeyBoard menu() { final KeyBoardButtonText tasks = KeyBoardButtonText.builder().label("Мои задачи").build(); - final KeyBoardButtonText pr = KeyBoardButtonText.builder().label("Проверить ПР").build(); + final KeyBoardButtonText pr = KeyBoardButtonText.builder().label("Pull Requests").build(); final KeyBoardButtonText top = KeyBoardButtonText.builder().label("\uD83C\uDF1F Таблица рейтинга \uD83C\uDF1F").build(); final KeyBoardButtonText settings = KeyBoardButtonText.builder().label("Настройки").build();