From 1f9296b59073d7d4979d2e4fd73a4ba8fff2e5b7 Mon Sep 17 00:00:00 2001 From: upagge Date: Mon, 2 Mar 2020 19:26:19 +0300 Subject: [PATCH 1/9] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tsc/bitbucketbot/utils/Message.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index ef0c4bd..12bbf39 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -82,7 +82,7 @@ public class Message { final String createMessage = stringBuilder.toString(); if (!EMPTY.equalsIgnoreCase(createMessage)) { return Optional.of( - SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK + + SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + HR + "[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + BREAK + createMessage From 4c603effc7821f56ca86220574ace693bb2835d6 Mon Sep 17 00:00:00 2001 From: upagge Date: Mon, 2 Mar 2020 20:39:54 +0300 Subject: [PATCH 2/9] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsc/bitbucketbot/config/AppConfig.java | 2 +- .../repository/jpa/UserRepository.java | 4 ++++ .../scheduler/SchedulerNotification.java | 22 +++++++++++++++++++ .../scheduler/SchedulerPullRequest.java | 6 ++--- .../tsc/bitbucketbot/service/UserService.java | 3 +-- .../com/tsc/bitbucketbot/service/Utils.java | 9 +++++--- .../service/impl/UserServiceImpl.java | 13 +++++------ 7 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java diff --git a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java index f978d82..1dd0ae6 100644 --- a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java +++ b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java @@ -13,7 +13,7 @@ public class AppConfig { @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); - taskScheduler.setPoolSize(5); + taskScheduler.setPoolSize(6); return taskScheduler; } diff --git a/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java b/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java index fcaf24a..80ec58a 100644 --- a/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java +++ b/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java @@ -4,6 +4,8 @@ import com.tsc.bitbucketbot.domain.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + /** * TODO: Добавить описание класса. * @@ -16,4 +18,6 @@ public interface UserRepository extends JpaRepository { boolean existsByLogin(String login); + List findAllByTelegramIdNotNullAndTokenNotNull(); + } diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java new file mode 100644 index 0000000..7e93fb2 --- /dev/null +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -0,0 +1,22 @@ +//package com.tsc.bitbucketbot.scheduler; +// +//import com.tsc.bitbucketbot.domain.entity.User; +//import com.tsc.bitbucketbot.service.UserService; +//import lombok.RequiredArgsConstructor; +//import org.springframework.scheduling.annotation.Scheduled; +//import org.springframework.stereotype.Service; +// +//import java.util.List; +// +//@Service +//@RequiredArgsConstructor +//public class SchedulerNotification { +// +// private final UserService userService; +// +// @Scheduled(cron = "0 9 * * MON-FRI") +// public void goodMorning() { +// List users = userService.getAllRegister(); +// } +// +//} diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java index e7cc89d..e7d9ec0 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java @@ -48,7 +48,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkClosePullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { @@ -98,7 +98,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkOldPullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { @@ -237,7 +237,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkNewPullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { diff --git a/src/main/java/com/tsc/bitbucketbot/service/UserService.java b/src/main/java/com/tsc/bitbucketbot/service/UserService.java index 20dedc3..f3e2724 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/UserService.java +++ b/src/main/java/com/tsc/bitbucketbot/service/UserService.java @@ -18,12 +18,11 @@ public interface UserService { Optional getByLogin(String login); - Optional update(User user); - Set existsByLogin(@NonNull Set logins); Optional reg(@NonNull User user); List addAll(Set newUsers); + List getAllRegister(); } diff --git a/src/main/java/com/tsc/bitbucketbot/service/Utils.java b/src/main/java/com/tsc/bitbucketbot/service/Utils.java index ffcca57..5a89540 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/Utils.java +++ b/src/main/java/com/tsc/bitbucketbot/service/Utils.java @@ -2,7 +2,6 @@ package com.tsc.bitbucketbot.service; import com.google.gson.Gson; import lombok.NonNull; -import org.springframework.stereotype.Service; import java.io.BufferedReader; import java.io.IOException; @@ -17,12 +16,16 @@ import java.util.zip.GZIPInputStream; * * @author upagge [30.01.2020] */ -@Service public class Utils { private static Gson gson = new Gson(); - public static Optional urlToJson(@NonNull String urlValue, String token, Class classOfT) { + private Utils() { + throw new IllegalStateException("Утилитарный класс"); + } + + @NonNull + public static Optional urlToJson(String urlValue, String token, Class classOfT) { StringBuilder sb = null; URL url; URLConnection urlCon; diff --git a/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java b/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java index 4c8ea18..3f5cd74 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java +++ b/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java @@ -38,14 +38,6 @@ public class UserServiceImpl implements UserService { return userRepository.findById(login); } - @Override - public Optional update(User user) { - if (userRepository.existsById(user.getLogin())) { - return Optional.of(userRepository.save(user)); - } - return Optional.empty(); - } - @Override public Set existsByLogin(@NonNull Set logins) { return logins.stream().filter(userRepository::existsById).collect(Collectors.toSet()); @@ -70,4 +62,9 @@ public class UserServiceImpl implements UserService { return userRepository.saveAll(newUsers); } + @Override + public List getAllRegister() { + return userRepository.findAllByTelegramIdNotNullAndTokenNotNull(); + } + } From 5b96965518212a36fb451bad1740154ce98649a4 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 00:20:48 +0300 Subject: [PATCH 3/9] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=20=D0=B4=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D0=B9=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 10 +++---- .../tsc/bitbucketbot/config/AppConfig.java | 6 ++++ .../domain/entity/PullRequest.java | 7 +++++ .../dto/bitbucket/PullRequestJson.java | 10 +++++++ .../bitbucket/sheet/PullRequestSheetJson.java | 1 + .../scheduler/SchedulerPushMessageSend.java | 11 +++++-- .../com/tsc/bitbucketbot/service/Utils.java | 19 ++++++++++-- .../converter/PullRequestJsonConverter.java | 2 ++ .../utils/LocalDateFromEpochDeserializer.java | 29 +++++++++++++++++++ .../com/tsc/bitbucketbot/utils/Message.java | 6 ++-- .../resources/liquibase/change-set/v1.2.0.xml | 10 +++++++ 11 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/tsc/bitbucketbot/utils/LocalDateFromEpochDeserializer.java diff --git a/pom.xml b/pom.xml index 3672a76..9056521 100644 --- a/pom.xml +++ b/pom.xml @@ -30,11 +30,11 @@ spring-boot-starter - - com.google.code.gson - gson - 2.8.5 - + + + + + org.springframework.boot diff --git a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java index 1dd0ae6..12ed871 100644 --- a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java +++ b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java @@ -17,4 +17,10 @@ public class AppConfig { return taskScheduler; } +// @Bean +// public ObjectMapper objectMapper(ObjectMapper objectMapper) { +// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); +// return objectMapper; +// } + } diff --git a/src/main/java/com/tsc/bitbucketbot/domain/entity/PullRequest.java b/src/main/java/com/tsc/bitbucketbot/domain/entity/PullRequest.java index 613f01d..4462b52 100644 --- a/src/main/java/com/tsc/bitbucketbot/domain/entity/PullRequest.java +++ b/src/main/java/com/tsc/bitbucketbot/domain/entity/PullRequest.java @@ -21,6 +21,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import java.time.LocalDate; import java.util.List; /** @@ -70,4 +71,10 @@ public class PullRequest { @Column(name = "status") private PullRequestStatus status; + @Column(name = "create_date") + private LocalDate createDate; + + @Column(name = "update_date") + private LocalDate updateDate; + } diff --git a/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/PullRequestJson.java b/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/PullRequestJson.java index d91e773..91b23cf 100644 --- a/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/PullRequestJson.java +++ b/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/PullRequestJson.java @@ -1,7 +1,10 @@ package com.tsc.bitbucketbot.dto.bitbucket; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.tsc.bitbucketbot.utils.LocalDateFromEpochDeserializer; import lombok.Data; +import java.time.LocalDate; import java.util.List; /** @@ -15,6 +18,13 @@ public class PullRequestJson { private Long id; private Integer version; private PullRequestState state; + + @JsonDeserialize(using = LocalDateFromEpochDeserializer.class) + private LocalDate createdDate; + + @JsonDeserialize(using = LocalDateFromEpochDeserializer.class) + private LocalDate updatedDate; + private String title; private String description; private LinkJson links; diff --git a/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/sheet/PullRequestSheetJson.java b/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/sheet/PullRequestSheetJson.java index 81b1f96..1aba698 100644 --- a/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/sheet/PullRequestSheetJson.java +++ b/src/main/java/com/tsc/bitbucketbot/dto/bitbucket/sheet/PullRequestSheetJson.java @@ -9,4 +9,5 @@ import com.tsc.bitbucketbot.dto.bitbucket.Sheet; * @author upagge [02.02.2020] */ public class PullRequestSheetJson extends Sheet { + } diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPushMessageSend.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPushMessageSend.java index 88704bd..ccde063 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPushMessageSend.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPushMessageSend.java @@ -1,6 +1,7 @@ package com.tsc.bitbucketbot.scheduler; -import com.google.gson.Gson; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.tsc.bitbucketbot.config.PushMessageConfig; import com.tsc.bitbucketbot.domain.MessageSend; import com.tsc.bitbucketbot.service.MessageSendService; @@ -30,7 +31,7 @@ public class SchedulerPushMessageSend { private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); private final MessageSendService messageSendService; - private final Gson gson = new Gson(); + private final ObjectMapper objectMapper = new ObjectMapper(); private final PushMessageConfig pushMessageConfig; private OkHttpClient client; @@ -61,7 +62,11 @@ public class SchedulerPushMessageSend { public void sendNewMessage() { List pushMessage = messageSendService.getPushMessage(); if (!pushMessage.isEmpty()) { - sendMessage(gson.toJson(pushMessage)); + try { + sendMessage(objectMapper.writeValueAsString(pushMessage)); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } } } diff --git a/src/main/java/com/tsc/bitbucketbot/service/Utils.java b/src/main/java/com/tsc/bitbucketbot/service/Utils.java index 5a89540..24029c9 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/Utils.java +++ b/src/main/java/com/tsc/bitbucketbot/service/Utils.java @@ -1,7 +1,10 @@ package com.tsc.bitbucketbot.service; -import com.google.gson.Gson; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; import java.io.BufferedReader; import java.io.IOException; @@ -16,9 +19,15 @@ import java.util.zip.GZIPInputStream; * * @author upagge [30.01.2020] */ +@Slf4j public class Utils { - private static Gson gson = new Gson(); + private static ObjectMapper objectMapper; + + static { + objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } private Utils() { throw new IllegalStateException("Утилитарный класс"); @@ -54,7 +63,11 @@ public class Utils { } if (sb != null) { - return Optional.of(gson.fromJson(sb.toString(), classOfT)); + try { + return Optional.of(objectMapper.readValue(sb.toString(), classOfT)); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + } } return Optional.empty(); } diff --git a/src/main/java/com/tsc/bitbucketbot/service/converter/PullRequestJsonConverter.java b/src/main/java/com/tsc/bitbucketbot/service/converter/PullRequestJsonConverter.java index 19f9bea..eebc845 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/converter/PullRequestJsonConverter.java +++ b/src/main/java/com/tsc/bitbucketbot/service/converter/PullRequestJsonConverter.java @@ -35,6 +35,8 @@ public class PullRequestJsonConverter implements Converter { + + @Override + public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) { + try { + Long time = jp.readValueAs(Long.class); + Instant instant = Instant.ofEpochMilli(time); + LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); + return localDate; + } catch (IOException e) { + log.error(e.getMessage()); + } + return LocalDate.now(); + } + +} diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index 12bbf39..09b3c1b 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -24,17 +24,19 @@ public class Message { private static final String TWO_BREAK = "\n\n"; private static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB️"; private static final String SMILE_PEN = "✏️"; + private static final String SMILE_NEW_PR = "\uD83C\uDF89"; private static final String SMILE_UPDATE = "\uD83D\uDD04"; private static final String HR = "\n -- -- -- -- --\n"; + private Message() { throw new IllegalStateException("Утилитарный класс"); } @NonNull public static String newPullRequest(PullRequest pullRequest) { - return "\uD83C\uDF89 *Новый Pull Request*\n" + - "[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")\n" + + return SMILE_NEW_PR + " *Новый Pull Request*" + BREAK + + "[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + HR + SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() + TWO_BREAK; diff --git a/src/main/resources/liquibase/change-set/v1.2.0.xml b/src/main/resources/liquibase/change-set/v1.2.0.xml index 3cba5c3..dc8c7ec 100644 --- a/src/main/resources/liquibase/change-set/v1.2.0.xml +++ b/src/main/resources/liquibase/change-set/v1.2.0.xml @@ -15,4 +15,14 @@ + + + + + + + + + + \ No newline at end of file From 4b7b14f6dfa07af357155e48a8e69be625aa72a7 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 01:26:11 +0300 Subject: [PATCH 4/9] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D1=82=D0=B5=D1=80=D1=8F=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20(=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85)=20=D0=9F=D0=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +--- .../tsc/bitbucketbot/config/AppConfig.java | 8 +--- .../jpa/PullRequestsRepository.java | 7 +++ .../scheduler/SchedulerNotification.java | 8 +++- .../scheduler/SchedulerPullRequest.java | 44 +++++++++++-------- .../service/PullRequestsService.java | 4 ++ .../service/impl/PullRequestsServiceImpl.java | 10 +++++ 7 files changed, 56 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index 9056521..4d132d8 100644 --- a/pom.xml +++ b/pom.xml @@ -30,12 +30,6 @@ spring-boot-starter - - - - - - org.springframework.boot spring-boot-devtools @@ -46,7 +40,7 @@ org.springframework.boot spring-boot-starter-data-jpa - + org.liquibase liquibase-core diff --git a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java index 12ed871..f978d82 100644 --- a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java +++ b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java @@ -13,14 +13,8 @@ public class AppConfig { @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); - taskScheduler.setPoolSize(6); + taskScheduler.setPoolSize(5); return taskScheduler; } -// @Bean -// public ObjectMapper objectMapper(ObjectMapper objectMapper) { -// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); -// return objectMapper; -// } - } diff --git a/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java index 92a60b6..4b6f6be 100644 --- a/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java +++ b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.Set; @@ -25,4 +26,10 @@ public interface PullRequestsRepository extends JpaRepository void deleteAllByIdIn(Collection id); + @Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.user=:reviewer") + List findAllByReviewers(@Param("reviewer") String reviewer); + + @Query("SELECT p.id from PullRequest p") + Set getAllIds(); + } diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java index 7e93fb2..9e265fe 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -1,6 +1,8 @@ //package com.tsc.bitbucketbot.scheduler; // +//import com.tsc.bitbucketbot.domain.entity.PullRequest; //import com.tsc.bitbucketbot.domain.entity.User; +//import com.tsc.bitbucketbot.service.PullRequestsService; //import com.tsc.bitbucketbot.service.UserService; //import lombok.RequiredArgsConstructor; //import org.springframework.scheduling.annotation.Scheduled; @@ -13,10 +15,14 @@ //public class SchedulerNotification { // // private final UserService userService; +// private final PullRequestsService pullRequestsService; // -// @Scheduled(cron = "0 9 * * MON-FRI") +//// @Scheduled(cron = "0 9 * * MON-FRI") +// @Scheduled(fixedRate = 50000) // public void goodMorning() { // List users = userService.getAllRegister(); +// List mstruchkov = pullRequestsService.getAllByReviewer("mstruchkov"); +// System.out.println(); // } // //} diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java index e7d9ec0..0ddff3f 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java @@ -24,6 +24,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -47,7 +48,17 @@ public class SchedulerPullRequest { private final BitbucketConfig bitbucketConfig; @Scheduled(fixedRate = 30000) - public void checkClosePullRequest() { + public void checkOldPullRequest() { + Set existsId = pullRequestsService.getAllId(); + Set openId = checkOpenPullRequest(); + checkClosePullRequest(); + existsId.removeAll(openId); + if (!existsId.isEmpty()) { + pullRequestsService.deleteAll(existsId); + } + } + + private void checkClosePullRequest() { final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class); @@ -96,9 +107,9 @@ public class SchedulerPullRequest { } } - @Scheduled(fixedRate = 30000) - public void checkOldPullRequest() { + private Set checkOpenPullRequest() { final List users = userService.getAllRegister(); + final Set ids = new HashSet<>(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { @@ -116,7 +127,12 @@ public class SchedulerPullRequest { .collect(Collectors.toMap(PullRequest::getId, pullRequest -> pullRequest)); final Set pullRequests = pullRequestsService.getAllById(existsPullRequestBitbucket.keySet()); if (!existsPullRequestBitbucket.isEmpty() && !pullRequests.isEmpty()) { - pullRequestsService.updateAll(processingUpdate(existsPullRequestBitbucket, pullRequests)); + processingUpdate(existsPullRequestBitbucket, pullRequests); + ids.addAll( + pullRequestsService.updateAll(existsPullRequestBitbucket.values()).stream() + .map(PullRequest::getId) + .collect(Collectors.toSet()) + ); } if (pullRequestBitbucketSheet.getNextPageStart() != null) { @@ -126,23 +142,19 @@ public class SchedulerPullRequest { } } } + return ids; } @NonNull - private List processingUpdate(Map newPullRequests, Set pullRequests) { - List updatePullRequest = new ArrayList<>(); + private void processingUpdate(Map newPullRequests, Set pullRequests) { for (PullRequest pullRequest : pullRequests) { PullRequest newPullRequest = newPullRequests.get(pullRequest.getId()); - @NonNull boolean author = processingAuthor(pullRequest, newPullRequest); - @NonNull boolean reviewer = processingReviewer(pullRequest, newPullRequest); - if (author || reviewer) { - updatePullRequest.add(newPullRequest); - } + processingAuthor(pullRequest, newPullRequest); + processingReviewer(pullRequest, newPullRequest); } - return updatePullRequest; } - private boolean processingReviewer(PullRequest pullRequest, PullRequest newPullRequest) { + private void processingReviewer(PullRequest pullRequest, PullRequest newPullRequest) { StringBuilder stringBuilder = new StringBuilder(); changeVersionPr(pullRequest, newPullRequest).ifPresent(stringBuilder::append); String message = stringBuilder.toString(); @@ -161,13 +173,11 @@ public class SchedulerPullRequest { newPullRequest.getAuthor().getLogin())) .build()) ); - return true; } - return false; } @NonNull - private boolean processingAuthor(PullRequest pullRequest, PullRequest newPullRequest) { + private void processingAuthor(PullRequest pullRequest, PullRequest newPullRequest) { final User author = pullRequest.getAuthor(); StringBuilder stringBuilder = new StringBuilder(); if (author.getTelegramId() != null) { @@ -176,10 +186,8 @@ public class SchedulerPullRequest { final String message = stringBuilder.toString(); if (!Message.EMPTY.equalsIgnoreCase(message)) { messageSendService.add(MessageSend.builder().message(message).telegramId(author.getTelegramId()).build()); - return true; } } - return false; } @NonNull diff --git a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java index 203fb6a..571e9f0 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java +++ b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java @@ -29,4 +29,8 @@ public interface PullRequestsService { void deleteAll(@NonNull Set id); + List getAllByReviewer(@NonNull String login); + + Set getAllId(); + } diff --git a/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java b/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java index e229037..f79f092 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java +++ b/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java @@ -60,4 +60,14 @@ public class PullRequestsServiceImpl implements PullRequestsService { pullRequestsRepository.deleteAllByIdIn(id); } + @Override + public List getAllByReviewer(@NonNull String login) { + return pullRequestsRepository.findAllByReviewers(login); + } + + @Override + public Set getAllId() { + return pullRequestsRepository.getAllIds(); + } + } From c09d6b2babe18177d37a048109937f4b14e05b87 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 02:36:46 +0300 Subject: [PATCH 5/9] =?UTF-8?q?=D0=A3=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=20=D1=83=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsc/bitbucketbot/domain/entity/User.java | 3 + .../jpa/PullRequestsRepository.java | 5 +- .../scheduler/SchedulerNotification.java | 68 +++++++++++-------- .../service/PullRequestsService.java | 4 +- .../service/converter/UserJsonConverter.java | 1 + .../service/impl/PullRequestsServiceImpl.java | 6 +- .../com/tsc/bitbucketbot/utils/Message.java | 41 ++++++++--- .../utils/UpdateDataComparator.java | 14 ++++ .../resources/liquibase/change-set/v1.2.0.xml | 6 ++ 9 files changed, 107 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/tsc/bitbucketbot/utils/UpdateDataComparator.java diff --git a/src/main/java/com/tsc/bitbucketbot/domain/entity/User.java b/src/main/java/com/tsc/bitbucketbot/domain/entity/User.java index 18dcf33..72e10e7 100644 --- a/src/main/java/com/tsc/bitbucketbot/domain/entity/User.java +++ b/src/main/java/com/tsc/bitbucketbot/domain/entity/User.java @@ -39,4 +39,7 @@ public class User { @Column(name = "telegram_id") private Long telegramId; + @Column(name = "full_name") + private String fullName; + } diff --git a/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java index 4b6f6be..b14b6e5 100644 --- a/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java +++ b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java @@ -1,5 +1,6 @@ package com.tsc.bitbucketbot.repository.jpa; +import com.tsc.bitbucketbot.domain.ReviewerStatus; import com.tsc.bitbucketbot.domain.entity.PullRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -26,8 +27,8 @@ public interface PullRequestsRepository extends JpaRepository void deleteAllByIdIn(Collection id); - @Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.user=:reviewer") - List findAllByReviewers(@Param("reviewer") String reviewer); + @Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.user=:reviewer AND r.status =:status") + List findAllByReviewerAndStatuses(@Param("reviewer") String reviewer, @Param("status") ReviewerStatus status); @Query("SELECT p.id from PullRequest p") Set getAllIds(); diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java index 9e265fe..68b9d19 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -1,28 +1,40 @@ -//package com.tsc.bitbucketbot.scheduler; -// -//import com.tsc.bitbucketbot.domain.entity.PullRequest; -//import com.tsc.bitbucketbot.domain.entity.User; -//import com.tsc.bitbucketbot.service.PullRequestsService; -//import com.tsc.bitbucketbot.service.UserService; -//import lombok.RequiredArgsConstructor; -//import org.springframework.scheduling.annotation.Scheduled; -//import org.springframework.stereotype.Service; -// -//import java.util.List; -// -//@Service -//@RequiredArgsConstructor -//public class SchedulerNotification { -// -// private final UserService userService; -// private final PullRequestsService pullRequestsService; -// -//// @Scheduled(cron = "0 9 * * MON-FRI") -// @Scheduled(fixedRate = 50000) -// public void goodMorning() { -// List users = userService.getAllRegister(); -// List mstruchkov = pullRequestsService.getAllByReviewer("mstruchkov"); -// System.out.println(); -// } -// -//} +package com.tsc.bitbucketbot.scheduler; + +import com.tsc.bitbucketbot.domain.MessageSend; +import com.tsc.bitbucketbot.domain.ReviewerStatus; +import com.tsc.bitbucketbot.domain.entity.PullRequest; +import com.tsc.bitbucketbot.domain.entity.User; +import com.tsc.bitbucketbot.service.MessageSendService; +import com.tsc.bitbucketbot.service.PullRequestsService; +import com.tsc.bitbucketbot.service.UserService; +import com.tsc.bitbucketbot.utils.Message; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class SchedulerNotification { + + private final UserService userService; + private final PullRequestsService pullRequestsService; + private final MessageSendService messageSendService; + + @Scheduled(cron = "0 9 * * MON-FRI") + public void goodMorning() { + User user = userService.getByLogin("mstruchkov").get(); + List pullRequests = pullRequestsService.getAllByReviewerAndStatuses( + user.getLogin(), + ReviewerStatus.NEEDS_WORK + ); + messageSendService.add( + MessageSend.builder() + .telegramId(3000811L) + .message(Message.goodMorningStatistic(user.getFullName(), pullRequests)) + .build() + ); + } + +} diff --git a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java index 571e9f0..a0b0fa6 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java +++ b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java @@ -1,5 +1,6 @@ package com.tsc.bitbucketbot.service; +import com.tsc.bitbucketbot.domain.ReviewerStatus; import com.tsc.bitbucketbot.domain.entity.PullRequest; import lombok.NonNull; @@ -29,7 +30,8 @@ public interface PullRequestsService { void deleteAll(@NonNull Set id); - List getAllByReviewer(@NonNull String login); + @NonNull + List getAllByReviewerAndStatuses(String login, ReviewerStatus statuses); Set getAllId(); diff --git a/src/main/java/com/tsc/bitbucketbot/service/converter/UserJsonConverter.java b/src/main/java/com/tsc/bitbucketbot/service/converter/UserJsonConverter.java index 48e11a2..b7006fb 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/converter/UserJsonConverter.java +++ b/src/main/java/com/tsc/bitbucketbot/service/converter/UserJsonConverter.java @@ -16,6 +16,7 @@ public class UserJsonConverter implements Converter { @Override public User convert(UserJson source) { return User.builder() + .fullName(source.getDisplayName()) .login(source.getName()) .build(); } diff --git a/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java b/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java index f79f092..150db25 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java +++ b/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java @@ -1,5 +1,6 @@ package com.tsc.bitbucketbot.service.impl; +import com.tsc.bitbucketbot.domain.ReviewerStatus; import com.tsc.bitbucketbot.domain.entity.PullRequest; import com.tsc.bitbucketbot.repository.jpa.PullRequestsRepository; import com.tsc.bitbucketbot.service.PullRequestsService; @@ -60,9 +61,10 @@ public class PullRequestsServiceImpl implements PullRequestsService { pullRequestsRepository.deleteAllByIdIn(id); } + @NonNull @Override - public List getAllByReviewer(@NonNull String login) { - return pullRequestsRepository.findAllByReviewers(login); + public List getAllByReviewerAndStatuses(String login, ReviewerStatus reviewerStatus) { + return pullRequestsRepository.findAllByReviewerAndStatuses(login, reviewerStatus); } @Override diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index 09b3c1b..d6ccff1 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -20,14 +20,15 @@ import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.*; public class Message { public static final String EMPTY = ""; - private static final String BREAK = "\n"; - private static final String TWO_BREAK = "\n\n"; - private static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB️"; - private static final String SMILE_PEN = "✏️"; - private static final String SMILE_NEW_PR = "\uD83C\uDF89"; - private static final String SMILE_UPDATE = "\uD83D\uDD04"; - private static final String HR = "\n -- -- -- -- --\n"; - + public static final String BREAK = "\n"; + public static final String TWO_BREAK = "\n\n"; + public static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB️"; + public static final String SMILE_PEN = "✏️"; + public static final String SMILE_NEW_PR = "\uD83C\uDF89"; + public static final String SMILE_UPDATE = "\uD83D\uDD04"; + public static final String SMILE_SUN = "\uD83D\uDD06"; + public static final String SMILE_PIN = "\uD83D\uDCCD"; + public static final String HR = "\n -- -- -- -- --\n"; private Message() { throw new IllegalStateException("Утилитарный класс"); @@ -101,4 +102,28 @@ public class Message { SMILE_AUTHOR + ": " + author + TWO_BREAK; } + + @NonNull + public static String goodMorningStatistic(String userName, List pullRequests) { + StringBuilder message = new StringBuilder(SMILE_SUN).append(" Доброе утро, ").append(userName).append("!") + .append(HR); + if (!pullRequests.isEmpty()) { + message.append("Сегодня тебя ждет процерка целых ").append(pullRequests.size()).append(" ПР!").append(TWO_BREAK) + .append("Позволь представить, горячая десятка:").append(BREAK); + pullRequests.stream() + .sorted(new UpdateDataComparator()) + .limit(10) + .forEach(pullRequest -> message.append(SMILE_PIN) + .append("[").append(pullRequest.getName()).append("](").append(pullRequest.getUrl()).append(")").append(BREAK)); + } else { + message.append("Ты либо самый лучший рабоник, либо тебе не доверяют проверку ПР :D").append(BREAK) + .append("Поздравляю, у тебя ни одного ПР на проверку!").append(BREAK); + } + return message + .append(BREAK) + .append("Удачной работы сегодня!") + .toString(); + } + + } diff --git a/src/main/java/com/tsc/bitbucketbot/utils/UpdateDataComparator.java b/src/main/java/com/tsc/bitbucketbot/utils/UpdateDataComparator.java new file mode 100644 index 0000000..1610f1b --- /dev/null +++ b/src/main/java/com/tsc/bitbucketbot/utils/UpdateDataComparator.java @@ -0,0 +1,14 @@ +package com.tsc.bitbucketbot.utils; + +import com.tsc.bitbucketbot.domain.entity.PullRequest; + +import java.util.Comparator; + +public class UpdateDataComparator implements Comparator { + + @Override + public int compare(PullRequest pullRequest, PullRequest t1) { + return pullRequest.getUpdateDate().compareTo(t1.getUpdateDate()); + } + +} diff --git a/src/main/resources/liquibase/change-set/v1.2.0.xml b/src/main/resources/liquibase/change-set/v1.2.0.xml index dc8c7ec..ce2c5f2 100644 --- a/src/main/resources/liquibase/change-set/v1.2.0.xml +++ b/src/main/resources/liquibase/change-set/v1.2.0.xml @@ -25,4 +25,10 @@ + + + + + + \ No newline at end of file From c5144e10433a0dda7af5ebc24f991ab87a21b4c7 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 02:37:26 +0300 Subject: [PATCH 6/9] =?UTF-8?q?=D0=A3=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=20=D1=83=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/SchedulerNotification.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java index 68b9d19..263ea5b 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -24,17 +24,19 @@ public class SchedulerNotification { @Scheduled(cron = "0 9 * * MON-FRI") public void goodMorning() { - User user = userService.getByLogin("mstruchkov").get(); - List pullRequests = pullRequestsService.getAllByReviewerAndStatuses( - user.getLogin(), - ReviewerStatus.NEEDS_WORK - ); - messageSendService.add( - MessageSend.builder() - .telegramId(3000811L) - .message(Message.goodMorningStatistic(user.getFullName(), pullRequests)) - .build() - ); + List allRegister = userService.getAllRegister(); + for (User user : allRegister) { + List pullRequests = pullRequestsService.getAllByReviewerAndStatuses( + user.getLogin(), + ReviewerStatus.NEEDS_WORK + ); + messageSendService.add( + MessageSend.builder() + .telegramId(3000811L) + .message(Message.goodMorningStatistic(user.getFullName(), pullRequests)) + .build() + ); + } } } From 582a92a7b52f7329c67fc6a2f413ea1f16aef7c5 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 02:40:48 +0300 Subject: [PATCH 7/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20cron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tsc/bitbucketbot/scheduler/SchedulerNotification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java index 263ea5b..7206fa2 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -22,7 +22,7 @@ public class SchedulerNotification { private final PullRequestsService pullRequestsService; private final MessageSendService messageSendService; - @Scheduled(cron = "0 9 * * MON-FRI") + @Scheduled(cron = "0 9 * * 1-5") public void goodMorning() { List allRegister = userService.getAllRegister(); for (User user : allRegister) { From b802600ee7fccf92fe94714b5e38042f975d4159 Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 09:11:40 +0300 Subject: [PATCH 8/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tsc/bitbucketbot/scheduler/SchedulerNotification.java | 4 ++-- src/main/java/com/tsc/bitbucketbot/utils/Message.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java index 7206fa2..bbfa82a 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -22,7 +22,7 @@ public class SchedulerNotification { private final PullRequestsService pullRequestsService; private final MessageSendService messageSendService; - @Scheduled(cron = "0 9 * * 1-5") + @Scheduled(cron = "0 30 8 * * MON-FRI") public void goodMorning() { List allRegister = userService.getAllRegister(); for (User user : allRegister) { @@ -32,7 +32,7 @@ public class SchedulerNotification { ); messageSendService.add( MessageSend.builder() - .telegramId(3000811L) + .telegramId(user.getTelegramId()) .message(Message.goodMorningStatistic(user.getFullName(), pullRequests)) .build() ); diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index d6ccff1..b8975ed 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -108,7 +108,7 @@ public class Message { StringBuilder message = new StringBuilder(SMILE_SUN).append(" Доброе утро, ").append(userName).append("!") .append(HR); if (!pullRequests.isEmpty()) { - message.append("Сегодня тебя ждет процерка целых ").append(pullRequests.size()).append(" ПР!").append(TWO_BREAK) + message.append("Сегодня тебя ждет проверка целых ").append(pullRequests.size()).append(" ПР!").append(TWO_BREAK) .append("Позволь представить, горячая десятка:").append(BREAK); pullRequests.stream() .sorted(new UpdateDataComparator()) @@ -116,12 +116,12 @@ public class Message { .forEach(pullRequest -> message.append(SMILE_PIN) .append("[").append(pullRequest.getName()).append("](").append(pullRequest.getUrl()).append(")").append(BREAK)); } else { - message.append("Ты либо самый лучший рабоник, либо тебе не доверяют проверку ПР :D").append(BREAK) + message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР :D").append(BREAK) .append("Поздравляю, у тебя ни одного ПР на проверку!").append(BREAK); } return message .append(BREAK) - .append("Удачной работы сегодня!") + .append("Удачной работы!") .toString(); } From 0bb084e69a331dbffddfc0df3e6a4a7c2384acbb Mon Sep 17 00:00:00 2001 From: upagge Date: Tue, 3 Mar 2020 09:12:22 +0300 Subject: [PATCH 9/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tsc/bitbucketbot/utils/Message.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tsc/bitbucketbot/utils/Message.java b/src/main/java/com/tsc/bitbucketbot/utils/Message.java index b8975ed..3bf72f7 100644 --- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java +++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java @@ -116,7 +116,7 @@ public class Message { .forEach(pullRequest -> message.append(SMILE_PIN) .append("[").append(pullRequest.getName()).append("](").append(pullRequest.getUrl()).append(")").append(BREAK)); } else { - message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР :D").append(BREAK) + message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР :D").append(TWO_BREAK) .append("Поздравляю, у тебя ни одного ПР на проверку!").append(BREAK); } return message