Небольшой рефакторинг утреннего сообщения

This commit is contained in:
upagge 2020-10-11 11:18:09 +03:00
parent 232624ec8d
commit 2b49d95412
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
11 changed files with 52 additions and 42 deletions

View File

@ -27,7 +27,7 @@ bitbucketbot:
comment-count: 100
init:
start-comment-id: 8157
use: true
use: false
bitbucket:
token: ${BITBUCKET_ADMIN_TOKEN}
url-pull-request-open: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN

View File

@ -3,3 +3,5 @@ server:
telegram-config:
bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: ${TELEGRAM_BOT_TOKEN}
bitbucketbot:
version: 2.15.3

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.vcs.core.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "bitbucketbot")
public class AppProperty {
private String version;
}

View File

@ -25,42 +25,49 @@ public class GoodMorningNotify extends Notify {
private final List<PullRequest> pullRequestsReviews;
private final List<PullRequest> pullRequestsNeedWork;
private final String personName;
private final String version;
@Builder
protected GoodMorningNotify(
Set<String> recipients,
List<PullRequest> pullRequestsReviews,
List<PullRequest> pullRequestsNeedWork
) {
List<PullRequest> pullRequestsNeedWork,
String personName, String version) {
super(EntityType.PERSON, recipients);
this.pullRequestsReviews = pullRequestsReviews;
this.pullRequestsNeedWork = pullRequestsNeedWork;
this.personName = personName;
this.version = version;
}
@Override
public String generateMessage() {
StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро* ").append(Smile.SUN).append(Smile.HR);
StringBuilder message = new StringBuilder().append(Smile.SUN).append(" *Доброе утро, ").append(personName).append("* ").append(Smile.SUN).append(Smile.TWO_BR);
if (!pullRequestsReviews.isEmpty()) {
message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР!").append(Smile.TWO_BR)
.append("Самые старые:").append(Smile.BR);
message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР:").append(Smile.BR);
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);
message.append("Поздравляю, у тебя ни одного ПР на проверку!").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)
messageNeedWork -> message.append(Smile.TWO_BR)
.append(Smile.DANGEROUS).append(" Требуется доработать ").append(pullRequestsNeedWork.size()).append(" ПР:").append(Smile.BR)
.append(messageNeedWork)
.append(Smile.BR)
);
message
.append(Smile.BR).append("Удачного дня ").append(Smile.FLOWER).append(Smile.TWO_BR);
.append(Smile.BR).append("Удачного дня ").append(Smile.FLOWER)
.append(Smile.HR)
.append("_Version ").append(version).append(" | Developer @uPagge_");
return message.toString();
}

View File

@ -37,7 +37,7 @@ public class AnswerCommentNotify extends Notify {
@Override
public String generateMessage() {
final String answerText = answers.stream()
.map(answer -> answer.getAuthorName() + ": " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500)))
.map(answer -> "*" + answer.getAuthorName() + "*: " + answer.getMessage().substring(0, Math.min(answer.getMessage().length(), 500)))
.collect(Collectors.joining("\n\n"));
return MessageFormat.format(
"{0} *Новые ответы на ваш комментарий* | [ПР]({1}){2}" +

View File

@ -35,7 +35,7 @@ public class CommentNotify extends Notify {
public String generateMessage() {
return MessageFormat.format(
"{0} *Новое упоминание* | [ПР]({1}){2}" +
"{3}: {4}",
"*{3}*: {4}",
Smile.BELL, url, Smile.HR, authorName, escapeMarkdown(message.replaceAll("@[\\w]+", ""))
);
}

View File

@ -1,6 +1,7 @@
package org.sadtech.bot.vcs.core.scheduler;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.core.config.properties.AppProperty;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
@ -35,8 +36,10 @@ public class NotificationScheduler {
private final NotifyService notifyService;
private final AppProperty appProperty;
// Утреннее сообщение
@Scheduled(cron = "0 15 8 * * MON-FRI")
@Scheduled(cron = "0 */1 * * * *")
public void goodMorning() {
List<Person> allRegister = personService.getAllRegister();
for (Person user : allRegister) {
@ -48,9 +51,11 @@ public class NotificationScheduler {
List<PullRequest> pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED);
notifyService.send(
GoodMorningNotify.builder()
.personName(user.getFullName())
.pullRequestsNeedWork(pullRequestsNeedWork)
.pullRequestsReviews(pullRequestsReviews)
.recipients(Collections.singleton(user.getLogin()))
.version(appProperty.getVersion())
.build()
);
}

View File

@ -132,8 +132,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
oldTask.getAnswers().clear();
oldTask.setAnswers(existsNewAnswersIds);
if (!newAnswers.isEmpty()) {
oldTask.getAnswers().clear();
oldTask.setAnswers(existsNewAnswersIds);
notifyService.send(
AnswerCommentNotify.builder()
.recipients(Collections.singleton(oldTask.getAuthor()))

View File

@ -48,8 +48,7 @@ public final class MessageUtils {
private static String generateStringItemPullRequestReview(PullRequest pullRequest) {
return Smile.statusPr(pullRequest.getUpdateDate()) + " " +
link(pullRequest.getTitle(), pullRequest.getUrl()) +
Smile.BR;
link(pullRequest.getTitle(), pullRequest.getUrl());
}
@NonNull

View File

@ -31,7 +31,7 @@ public enum Smile {
TOP_TWO("\uD83D\uDE0E"),
TOP_THREE("\uD83E\uDD49"),
KAKASHKA("\uD83D\uDCA9"),
MEGA_FUN("\uD83D\uDE02"),
LUPA("\uD83D\uDD0D"),
DANGEROUS("⚠️"),
BELL("\uD83D\uDECE"),
HR("\n -- -- -- -- --\n"),

24
pom.xml
View File

@ -148,36 +148,14 @@
<version>${javax.persistance}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>org.junit.vintage</groupId>-->
<!-- <artifactId>junit-vintage-engine</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
</dependencies>
</dependencyManagement>
<!-- <build>-->
<!-- <finalName>bitbucketbot</finalName>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<developers>
<developer>
<id>uPagge</id>
<name>Struchkov Mark</name>
<email>upagge@ya.ru</email>
<email>upagge@mail.ru</email>
</developer>
</developers>