Рефакторинг и новое сообщение о донатах
This commit is contained in:
parent
0f327e25f6
commit
24d3edaedf
@ -17,6 +17,7 @@ import com.tsc.bitbucketbot.service.Utils;
|
|||||||
import com.tsc.bitbucketbot.service.converter.PullRequestJsonConverter;
|
import com.tsc.bitbucketbot.service.converter.PullRequestJsonConverter;
|
||||||
import com.tsc.bitbucketbot.utils.Message;
|
import com.tsc.bitbucketbot.utils.Message;
|
||||||
import com.tsc.bitbucketbot.utils.Pair;
|
import com.tsc.bitbucketbot.utils.Pair;
|
||||||
|
import com.tsc.bitbucketbot.utils.Smile;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
@ -158,7 +159,7 @@ public class SchedulerPullRequest {
|
|||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
changeVersionPr(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
changeVersionPr(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
||||||
String message = stringBuilder.toString();
|
String message = stringBuilder.toString();
|
||||||
if (!Message.EMPTY.equalsIgnoreCase(message)) {
|
if (!Smile.Constants.EMPTY.equalsIgnoreCase(message)) {
|
||||||
newPullRequest.getReviewers().stream()
|
newPullRequest.getReviewers().stream()
|
||||||
.map(reviewer -> userService.getByLogin(reviewer.getUser()))
|
.map(reviewer -> userService.getByLogin(reviewer.getUser()))
|
||||||
.filter(Optional::isPresent)
|
.filter(Optional::isPresent)
|
||||||
@ -184,7 +185,7 @@ public class SchedulerPullRequest {
|
|||||||
changeStatusPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
changeStatusPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
||||||
changeReviewersPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
changeReviewersPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
||||||
final String message = stringBuilder.toString();
|
final String message = stringBuilder.toString();
|
||||||
if (!Message.EMPTY.equalsIgnoreCase(message)) {
|
if (!Smile.Constants.EMPTY.equalsIgnoreCase(message)) {
|
||||||
messageSendService.add(MessageSend.builder().message(message).telegramId(author.getTelegramId()).build());
|
messageSendService.add(MessageSend.builder().message(message).telegramId(author.getTelegramId()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import com.tsc.bitbucketbot.domain.util.ReviewerChange;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.Period;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -22,26 +21,6 @@ import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.*;
|
|||||||
*/
|
*/
|
||||||
public class Message {
|
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_FUN = "\uD83C\uDF89";
|
|
||||||
private static final String SMILE_UPDATE = "\uD83D\uDD04";
|
|
||||||
private static final String SMILE_SUN = "\uD83D\uDD06";
|
|
||||||
private static final String SMILE_MIG = "\uD83D\uDE09";
|
|
||||||
private static final String SMILE_BUY = "\uD83D\uDC4B";
|
|
||||||
private static final String SMILE_FLOWER = "\uD83C\uDF40";
|
|
||||||
private static final String SMILE_DAY_0 = "\uD83C\uDF15";
|
|
||||||
private static final String SMILE_DAY_1 = "\uD83C\uDF16";
|
|
||||||
private static final String SMILE_DAY_2 = "\uD83C\uDF17";
|
|
||||||
private static final String SMILE_DAY_3 = "\uD83C\uDF18";
|
|
||||||
private static final String SMILE_DAY_4 = "\uD83C\uDF11";
|
|
||||||
private static final String SMILE_DAY_5 = "\uD83C\uDF1A";
|
|
||||||
private static final String SMILE_MEGA_FUN = "\uD83D\uDE02";
|
|
||||||
private static final String HR = "\n -- -- -- -- --\n";
|
|
||||||
|
|
||||||
private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator();
|
private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator();
|
||||||
private static final Integer PR_COUNT = 4;
|
private static final Integer PR_COUNT = 4;
|
||||||
|
|
||||||
@ -51,19 +30,19 @@ public class Message {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String newPullRequest(PullRequest pullRequest) {
|
public static String newPullRequest(PullRequest pullRequest) {
|
||||||
return SMILE_FUN + " *Новый Pull Request*" + BREAK +
|
return Smile.FUN + " *Новый Pull Request*" + Smile.BREAK +
|
||||||
linkPr(pullRequest.getName(), pullRequest.getUrl()) +
|
linkPr(pullRequest.getName(), pullRequest.getUrl()) +
|
||||||
HR +
|
Smile.HR +
|
||||||
SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
|
Smile.AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
|
||||||
TWO_BREAK;
|
Smile.TWO_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
|
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
|
||||||
return SMILE_PEN + " *Изменился статус вашего ПР*" + HR +
|
return Smile.PEN + " *Изменился статус вашего ПР*" + Smile.HR +
|
||||||
linkPr(name, url) + BREAK +
|
linkPr(name, url) + Smile.BREAK +
|
||||||
oldStatus.name() + " -> " + newStatus.name() +
|
oldStatus.name() + " -> " + newStatus.name() +
|
||||||
TWO_BREAK;
|
Smile.TWO_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -72,25 +51,25 @@ public class Message {
|
|||||||
final Map<ReviewerChange.Type, List<ReviewerChange>> changes = reviewerChanges.stream()
|
final Map<ReviewerChange.Type, List<ReviewerChange>> changes = reviewerChanges.stream()
|
||||||
.collect(Collectors.groupingBy(ReviewerChange::getType));
|
.collect(Collectors.groupingBy(ReviewerChange::getType));
|
||||||
if (changes.containsKey(OLD)) {
|
if (changes.containsKey(OLD)) {
|
||||||
stringBuilder.append(BREAK).append("Изменили свое решение:").append(BREAK);
|
stringBuilder.append(Smile.BREAK).append("Изменили свое решение:").append(Smile.BREAK);
|
||||||
changes.get(OLD).forEach(
|
changes.get(OLD).forEach(
|
||||||
change -> stringBuilder
|
change -> stringBuilder
|
||||||
.append(SMILE_AUTHOR).append(change.getName()).append(": ")
|
.append(Smile.AUTHOR).append(change.getName()).append(": ")
|
||||||
.append(change.getOldStatus().getValue()).append(" -> ")
|
.append(change.getOldStatus().getValue()).append(" -> ")
|
||||||
.append(change.getStatus().getValue())
|
.append(change.getStatus().getValue())
|
||||||
.append(BREAK)
|
.append(Smile.BREAK)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (changes.containsKey(NEW)) {
|
if (changes.containsKey(NEW)) {
|
||||||
stringBuilder.append(BREAK).append("Новые ревьюверы:").append(BREAK);
|
stringBuilder.append(Smile.BREAK).append("Новые ревьюверы:").append(Smile.BREAK);
|
||||||
changes.get(NEW).forEach(
|
changes.get(NEW).forEach(
|
||||||
change -> stringBuilder
|
change -> stringBuilder
|
||||||
.append(change.getName()).append(" (").append(change.getStatus().getValue()).append(")")
|
.append(change.getName()).append(" (").append(change.getStatus().getValue()).append(")")
|
||||||
.append(BREAK)
|
.append(Smile.BREAK)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (changes.containsKey(DELETED)) {
|
if (changes.containsKey(DELETED)) {
|
||||||
stringBuilder.append(BREAK).append("Не выдержали ревью:").append(BREAK)
|
stringBuilder.append(Smile.BREAK).append("Не выдержали ревью:").append(Smile.BREAK)
|
||||||
.append(
|
.append(
|
||||||
changes.get(DELETED).stream()
|
changes.get(DELETED).stream()
|
||||||
.map(ReviewerChange::getName).collect(Collectors.joining(","))
|
.map(ReviewerChange::getName).collect(Collectors.joining(","))
|
||||||
@ -98,11 +77,11 @@ public class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String createMessage = stringBuilder.toString();
|
final String createMessage = stringBuilder.toString();
|
||||||
if (!EMPTY.equalsIgnoreCase(createMessage)) {
|
if (!Smile.Constants.EMPTY.equalsIgnoreCase(createMessage)) {
|
||||||
return Optional.of(
|
return Optional.of(
|
||||||
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" +
|
Smile.PEN + " *Изменения ревьюверов вашего ПР*" +
|
||||||
HR +
|
Smile.HR +
|
||||||
linkPr(pullRequest.getName(), pullRequest.getUrl()) + BREAK +
|
linkPr(pullRequest.getName(), pullRequest.getUrl()) + Smile.BREAK +
|
||||||
createMessage
|
createMessage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -111,19 +90,19 @@ public class Message {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String updatePullRequest(String pullRequestName, String prUrl, String author) {
|
public static String updatePullRequest(String pullRequestName, String prUrl, String author) {
|
||||||
return SMILE_UPDATE + " *Обновление Pull Request*" + BREAK +
|
return Smile.UPDATE + " *Обновление Pull Request*" + Smile.BREAK +
|
||||||
linkPr(pullRequestName, prUrl) +
|
linkPr(pullRequestName, prUrl) +
|
||||||
HR +
|
Smile.HR +
|
||||||
SMILE_AUTHOR + ": " + author +
|
Smile.AUTHOR + ": " + author +
|
||||||
TWO_BREAK;
|
Smile.TWO_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String goodMorningStatistic(List<PullRequest> pullRequests) {
|
public static String goodMorningStatistic(List<PullRequest> pullRequests) {
|
||||||
StringBuilder message = new StringBuilder(SMILE_SUN).append(" Доброе утро ").append(SMILE_SUN).append(HR);
|
StringBuilder message = new StringBuilder().append(Smile.SUN).append(" Доброе утро ").append(Smile.SUN).append(Smile.HR);
|
||||||
if (!pullRequests.isEmpty()) {
|
if (!pullRequests.isEmpty()) {
|
||||||
message.append("Сегодня тебя ждет проверка целых ").append(pullRequests.size()).append(" ПР!").append(TWO_BREAK)
|
message.append("Сегодня тебя ждет проверка целых ").append(pullRequests.size()).append(" ПР!").append(Smile.TWO_BREAK)
|
||||||
.append("Топ старых ПР:").append(BREAK);
|
.append("Топ старых ПР:").append(Smile.BREAK);
|
||||||
List<PullRequest> oldPr = pullRequests.stream()
|
List<PullRequest> oldPr = pullRequests.stream()
|
||||||
.sorted(COMPARATOR)
|
.sorted(COMPARATOR)
|
||||||
.limit(PR_COUNT)
|
.limit(PR_COUNT)
|
||||||
@ -133,7 +112,7 @@ public class Message {
|
|||||||
);
|
);
|
||||||
Set<Long> oldPrIds = oldPr.stream().map(PullRequest::getId).collect(Collectors.toSet());
|
Set<Long> oldPrIds = oldPr.stream().map(PullRequest::getId).collect(Collectors.toSet());
|
||||||
if (pullRequests.size() > PR_COUNT) {
|
if (pullRequests.size() > PR_COUNT) {
|
||||||
message.append(BREAK).append("Свежие ПР:").append(BREAK);
|
message.append(Smile.BREAK).append("Свежие ПР:").append(Smile.BREAK);
|
||||||
pullRequests
|
pullRequests
|
||||||
.stream()
|
.stream()
|
||||||
.filter(pullRequest -> !oldPrIds.contains(pullRequest.getId()))
|
.filter(pullRequest -> !oldPrIds.contains(pullRequest.getId()))
|
||||||
@ -144,40 +123,25 @@ public class Message {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(SMILE_MEGA_FUN).append(TWO_BREAK)
|
message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(Smile.MEGA_FUN).append(Smile.TWO_BREAK)
|
||||||
.append("Поздравляю, у тебя ни одного ПР на проверку!").append(BREAK);
|
.append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BREAK);
|
||||||
}
|
}
|
||||||
if (dayX()) {
|
if (dayX()) {
|
||||||
message.append(BREAK).append(SMILE_FUN).append(" Кстати, поздравляю, сегодня день З/П").append(BREAK);
|
message.append(Smile.BREAK).append(Smile.FUN).append(" Кстати, поздравляю, сегодня день З/П").append(Smile.BREAK)
|
||||||
|
.append(Smile.DANGEROUS).append("И раз такое дело, то напоминаю, что в виду независящих от разработчика условий бот работает на платном VDS. Поэтому всячески приветствуются ")
|
||||||
|
.append(linkPr("донаты на оплату сервера", "%donat_link%")).append(Smile.BREAK);
|
||||||
}
|
}
|
||||||
message
|
message
|
||||||
.append(BREAK)
|
.append(Smile.BREAK)
|
||||||
.append("Удачного дня ").append(SMILE_FLOWER).append(TWO_BREAK);
|
.append("Удачного дня ").append(Smile.FLOWER).append(Smile.TWO_BREAK);
|
||||||
|
|
||||||
return message.toString();
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String topPr(PullRequest pullRequest) {
|
private static String topPr(PullRequest pullRequest) {
|
||||||
return selectSmile(pullRequest) + " " +
|
return Smile.statusPr(pullRequest.getUpdateDate()) + " " +
|
||||||
linkPr(pullRequest.getName(), pullRequest.getUrl()) +
|
linkPr(pullRequest.getName(), pullRequest.getUrl()) +
|
||||||
BREAK;
|
Smile.BREAK;
|
||||||
}
|
|
||||||
|
|
||||||
private static String selectSmile(PullRequest pullRequest) {
|
|
||||||
switch (Period.between(LocalDate.now(), pullRequest.getUpdateDate()).getDays()) {
|
|
||||||
case 0:
|
|
||||||
return SMILE_DAY_0;
|
|
||||||
case 1:
|
|
||||||
return SMILE_DAY_1;
|
|
||||||
case 2:
|
|
||||||
return SMILE_DAY_2;
|
|
||||||
case 3:
|
|
||||||
return SMILE_DAY_3;
|
|
||||||
case 4:
|
|
||||||
return SMILE_DAY_4;
|
|
||||||
default:
|
|
||||||
return SMILE_DAY_5;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean dayX() {
|
private static boolean dayX() {
|
||||||
@ -192,7 +156,7 @@ public class Message {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String goodWeekEnd() {
|
public static String goodWeekEnd() {
|
||||||
return "Ну вот и все! Веселых выходных " + SMILE_MIG + BREAK +
|
return "Ну вот и все! Веселых выходных " + Smile.MIG + Smile.BREAK +
|
||||||
"До понедельника" + SMILE_BUY + TWO_BREAK;
|
"До понедельника" + Smile.BUY + Smile.TWO_BREAK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
src/main/java/com/tsc/bitbucketbot/utils/Smile.java
Normal file
53
src/main/java/com/tsc/bitbucketbot/utils/Smile.java
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package com.tsc.bitbucketbot.utils;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Period;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Smile {
|
||||||
|
|
||||||
|
BREAK("\n"),
|
||||||
|
TWO_BREAK("\n\n"),
|
||||||
|
AUTHOR("\uD83D\uDC68\u200D\uD83D\uDCBB️"),
|
||||||
|
PEN("✏️"),
|
||||||
|
FUN("\uD83C\uDF89"),
|
||||||
|
UPDATE("\uD83D\uDD04"),
|
||||||
|
SUN("\uD83D\uDD06"),
|
||||||
|
MIG("\uD83D\uDE09"),
|
||||||
|
BUY("\uD83D\uDC4B"),
|
||||||
|
FLOWER("\uD83C\uDF40"),
|
||||||
|
DAY_0("\uD83C\uDF15"),
|
||||||
|
DAY_1("\uD83C\uDF16"),
|
||||||
|
DAY_2("\uD83C\uDF17"),
|
||||||
|
DAY_3("\uD83C\uDF18"),
|
||||||
|
DAY_4("\uD83C\uDF11"),
|
||||||
|
DAY_5("\uD83C\uDF1A"),
|
||||||
|
MEGA_FUN("\uD83D\uDE02"),
|
||||||
|
DANGEROUS("⚠️"),
|
||||||
|
HR("\n -- -- -- -- --\n");
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public static Smile statusPr(LocalDate updateDate) {
|
||||||
|
int periodDay = Period.between(LocalDate.now(), updateDate).getDays();
|
||||||
|
if (periodDay < 5) {
|
||||||
|
return Smile.valueOf("DAY_" + periodDay);
|
||||||
|
} else {
|
||||||
|
return Smile.DAY_5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Constants {
|
||||||
|
public static final String EMPTY = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user