From 93deab1c3b264d51dc7b849fa2ffa36fefc1053c Mon Sep 17 00:00:00 2001 From: upagge Date: Thu, 5 Mar 2020 09:50:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=20=D0=B4=D0=BE=D0=BD=D0=B0=D1=82=D0=B0?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/SchedulerPullRequest.java | 35 +++++++++---------- .../com/tsc/bitbucketbot/utils/Message.java | 5 +-- .../com/tsc/bitbucketbot/utils/Smile.java | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java index 1039b46..e80ee8c 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java @@ -156,25 +156,22 @@ public class SchedulerPullRequest { } private void processingReviewer(PullRequest pullRequest, PullRequest newPullRequest) { - StringBuilder stringBuilder = new StringBuilder(); - changeVersionPr(pullRequest, newPullRequest).ifPresent(stringBuilder::append); - String message = stringBuilder.toString(); - if (!Smile.Constants.EMPTY.equalsIgnoreCase(message)) { - newPullRequest.getReviewers().stream() - .map(reviewer -> userService.getByLogin(reviewer.getUser())) - .filter(Optional::isPresent) - .map(Optional::get) - .filter(user -> user.getTelegramId() != null) - .forEach(user -> messageSendService.add( - MessageSend.builder() - .telegramId(user.getTelegramId()) - .message(Message.updatePullRequest( - newPullRequest.getName(), - newPullRequest.getUrl(), - newPullRequest.getAuthor().getLogin())) - .build()) - ); - } + changeVersionPr(pullRequest, newPullRequest).ifPresent( + message -> newPullRequest.getReviewers().stream() + .map(reviewer -> userService.getByLogin(reviewer.getUser())) + .filter(Optional::isPresent) + .map(Optional::get) + .filter(user -> user.getTelegramId() != null) + .forEach(user -> messageSendService.add( + MessageSend.builder() + .telegramId(user.getTelegramId()) + .message(Message.updatePullRequest( + newPullRequest.getName(), + newPullRequest.getUrl(), + newPullRequest.getAuthor().getLogin())) + .build()) + ) + ); } @NonNull diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index bdbf75c..aa532e6 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -23,6 +23,7 @@ public class Message { private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator(); private static final Integer PR_COUNT = 4; + private static final String DONATION_LINK = "https://www.tinkoff.ru/sl/1T9s4esiMf"; private Message() { throw new IllegalStateException("Утилитарный класс"); @@ -128,8 +129,8 @@ public class Message { } if (dayX()) { message.append(Smile.BREAK).append(Smile.FUN).append(" Кстати, поздравляю, сегодня день З/П").append(Smile.BREAK) - .append(Smile.DANGEROUS).append("И раз такое дело, то напоминаю, что в виду независящих от разработчика условий бот работает на платном VDS. Поэтому всячески приветствуются ") - .append(linkPr("донаты на оплату сервера", "%donat_link%")).append(Smile.BREAK); + .append(Smile.DANGEROUS).append("И раз такое дело, то напоминаю, что в виду независящих от разработчика условий, бот работает на платном VDS. Поэтому всячески приветствуются ") + .append(linkPr("донаты на оплату сервера", DONATION_LINK)).append(Smile.BREAK); } message .append(Smile.BREAK) diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Smile.java b/src/main/java/com/tsc/bitbucketbot/utils/Smile.java index 5de03d8..3179e47 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Smile.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Smile.java @@ -33,7 +33,7 @@ public enum Smile { private String value; public static Smile statusPr(LocalDate updateDate) { - int periodDay = Period.between(LocalDate.now(), updateDate).getDays(); + int periodDay = Period.between(updateDate, LocalDate.now()).getDays(); if (periodDay < 5) { return Smile.valueOf("DAY_" + periodDay); } else {