diff --git a/pom.xml b/pom.xml
index 3672a76..4d132d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,12 +30,6 @@
spring-boot-starter
-
- com.google.code.gson
- gson
- 2.8.5
-
-
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/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/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/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/repository/jpa/PullRequestsRepository.java b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java
index 92a60b6..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,11 +1,13 @@
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;
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 +27,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 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/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..bbfa82a
--- /dev/null
+++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java
@@ -0,0 +1,42 @@
+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 30 8 * * MON-FRI")
+ public void goodMorning() {
+ List allRegister = userService.getAllRegister();
+ for (User user : allRegister) {
+ List pullRequests = pullRequestsService.getAllByReviewerAndStatuses(
+ user.getLogin(),
+ ReviewerStatus.NEEDS_WORK
+ );
+ messageSendService.add(
+ MessageSend.builder()
+ .telegramId(user.getTelegramId())
+ .message(Message.goodMorningStatistic(user.getFullName(), pullRequests))
+ .build()
+ );
+ }
+ }
+
+}
diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java
index e7cc89d..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,8 +48,18 @@ public class SchedulerPullRequest {
private final BitbucketConfig bitbucketConfig;
@Scheduled(fixedRate = 30000)
- public void checkClosePullRequest() {
- final List users = userService.getAll();
+ 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);
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
@@ -96,9 +107,9 @@ public class SchedulerPullRequest {
}
}
- @Scheduled(fixedRate = 30000)
- public void checkOldPullRequest() {
- final List users = userService.getAll();
+ 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
@@ -237,7 +245,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/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/PullRequestsService.java b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java
index 203fb6a..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,4 +30,9 @@ public interface PullRequestsService {
void deleteAll(@NonNull Set id);
+ @NonNull
+ List getAllByReviewerAndStatuses(String login, ReviewerStatus statuses);
+
+ Set getAllId();
+
}
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..24029c9 100644
--- a/src/main/java/com/tsc/bitbucketbot/service/Utils.java
+++ b/src/main/java/com/tsc/bitbucketbot/service/Utils.java
@@ -1,8 +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 org.springframework.stereotype.Service;
+import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.IOException;
@@ -17,12 +19,22 @@ import java.util.zip.GZIPInputStream;
*
* @author upagge [30.01.2020]
*/
-@Service
+@Slf4j
public class Utils {
- private static Gson gson = new Gson();
+ private static ObjectMapper objectMapper;
- public static Optional urlToJson(@NonNull String urlValue, String token, Class classOfT) {
+ static {
+ objectMapper = new ObjectMapper();
+ objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ }
+
+ private Utils() {
+ throw new IllegalStateException("Утилитарный класс");
+ }
+
+ @NonNull
+ public static Optional urlToJson(String urlValue, String token, Class classOfT) {
StringBuilder sb = null;
URL url;
URLConnection urlCon;
@@ -51,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 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 e229037..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,4 +61,15 @@ public class PullRequestsServiceImpl implements PullRequestsService {
pullRequestsRepository.deleteAllByIdIn(id);
}
+ @NonNull
+ @Override
+ public List getAllByReviewerAndStatuses(String login, ReviewerStatus reviewerStatus) {
+ return pullRequestsRepository.findAllByReviewerAndStatuses(login, reviewerStatus);
+ }
+
+ @Override
+ public Set getAllId() {
+ return pullRequestsRepository.getAllIds();
+ }
+
}
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();
+ }
+
}
diff --git a/src/main/java/com/tsc/bitbucketbot/utils/LocalDateFromEpochDeserializer.java b/src/main/java/com/tsc/bitbucketbot/utils/LocalDateFromEpochDeserializer.java
new file mode 100644
index 0000000..ed7254e
--- /dev/null
+++ b/src/main/java/com/tsc/bitbucketbot/utils/LocalDateFromEpochDeserializer.java
@@ -0,0 +1,29 @@
+package com.tsc.bitbucketbot.utils;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+
+@Slf4j
+public class LocalDateFromEpochDeserializer extends JsonDeserializer {
+
+ @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 ef0c4bd..3bf72f7 100644
--- a/src/main/java/com/tsc/bitbucketbot/utils/Message.java
+++ b/src/main/java/com/tsc/bitbucketbot/utils/Message.java
@@ -20,12 +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_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("Утилитарный класс");
@@ -33,8 +36,8 @@ public class Message {
@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;
@@ -82,7 +85,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
@@ -99,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(TWO_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 3cba5c3..ce2c5f2 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,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file