Небольшой рефакторинг утреннего сообщения
This commit is contained in:
parent
232624ec8d
commit
2b49d95412
@ -27,7 +27,7 @@ bitbucketbot:
|
|||||||
comment-count: 100
|
comment-count: 100
|
||||||
init:
|
init:
|
||||||
start-comment-id: 8157
|
start-comment-id: 8157
|
||||||
use: true
|
use: false
|
||||||
bitbucket:
|
bitbucket:
|
||||||
token: ${BITBUCKET_ADMIN_TOKEN}
|
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
|
url-pull-request-open: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN
|
||||||
|
@ -3,3 +3,5 @@ server:
|
|||||||
telegram-config:
|
telegram-config:
|
||||||
bot-username: ${TELEGRAM_BOT_USERNAME}
|
bot-username: ${TELEGRAM_BOT_USERNAME}
|
||||||
bot-token: ${TELEGRAM_BOT_TOKEN}
|
bot-token: ${TELEGRAM_BOT_TOKEN}
|
||||||
|
bitbucketbot:
|
||||||
|
version: 2.15.3
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -25,42 +25,49 @@ public class GoodMorningNotify extends Notify {
|
|||||||
|
|
||||||
private final List<PullRequest> pullRequestsReviews;
|
private final List<PullRequest> pullRequestsReviews;
|
||||||
private final List<PullRequest> pullRequestsNeedWork;
|
private final List<PullRequest> pullRequestsNeedWork;
|
||||||
|
private final String personName;
|
||||||
|
private final String version;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected GoodMorningNotify(
|
protected GoodMorningNotify(
|
||||||
Set<String> recipients,
|
Set<String> recipients,
|
||||||
List<PullRequest> pullRequestsReviews,
|
List<PullRequest> pullRequestsReviews,
|
||||||
List<PullRequest> pullRequestsNeedWork
|
List<PullRequest> pullRequestsNeedWork,
|
||||||
) {
|
String personName, String version) {
|
||||||
super(EntityType.PERSON, recipients);
|
super(EntityType.PERSON, recipients);
|
||||||
this.pullRequestsReviews = pullRequestsReviews;
|
this.pullRequestsReviews = pullRequestsReviews;
|
||||||
this.pullRequestsNeedWork = pullRequestsNeedWork;
|
this.pullRequestsNeedWork = pullRequestsNeedWork;
|
||||||
|
this.personName = personName;
|
||||||
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
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()) {
|
if (!pullRequestsReviews.isEmpty()) {
|
||||||
message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР!").append(Smile.TWO_BR)
|
message.append("Необходимо проверить ").append(pullRequestsReviews.size()).append(" ПР:").append(Smile.BR);
|
||||||
.append("Самые старые:").append(Smile.BR);
|
|
||||||
MessageUtils.pullRequestForReview(
|
MessageUtils.pullRequestForReview(
|
||||||
pullRequestsReviews.stream()
|
pullRequestsReviews.stream()
|
||||||
.limit(3)
|
.limit(3)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
).ifPresent(message::append);
|
).ifPresent(message::append);
|
||||||
} else {
|
} else {
|
||||||
message.append("Ты либо самый лучший работник, либо тебе не доверяют проверку ПР ").append(Smile.MEGA_FUN).append(Smile.TWO_BR)
|
message.append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BR);
|
||||||
.append("Поздравляю, у тебя ни одного ПР на проверку!").append(Smile.BR);
|
|
||||||
}
|
}
|
||||||
MessageUtils.pullRequestForNeedWork(
|
MessageUtils.pullRequestForNeedWork(
|
||||||
pullRequestsNeedWork.stream()
|
pullRequestsNeedWork.stream()
|
||||||
.limit(3)
|
.limit(3)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
).ifPresent(
|
).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
|
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();
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class AnswerCommentNotify extends Notify {
|
|||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
final String answerText = answers.stream()
|
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"));
|
.collect(Collectors.joining("\n\n"));
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Новые ответы на ваш комментарий* | [ПР]({1}){2}" +
|
"{0} *Новые ответы на ваш комментарий* | [ПР]({1}){2}" +
|
||||||
|
@ -35,7 +35,7 @@ public class CommentNotify extends Notify {
|
|||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Новое упоминание* | [ПР]({1}){2}" +
|
"{0} *Новое упоминание* | [ПР]({1}){2}" +
|
||||||
"{3}: {4}",
|
"*{3}*: {4}",
|
||||||
Smile.BELL, url, Smile.HR, authorName, escapeMarkdown(message.replaceAll("@[\\w]+", ""))
|
Smile.BELL, url, Smile.HR, authorName, escapeMarkdown(message.replaceAll("@[\\w]+", ""))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.sadtech.bot.vcs.core.scheduler;
|
package org.sadtech.bot.vcs.core.scheduler;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
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.EntityType;
|
||||||
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
|
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
|
||||||
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
|
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
|
||||||
@ -35,8 +36,10 @@ public class NotificationScheduler {
|
|||||||
|
|
||||||
private final NotifyService notifyService;
|
private final NotifyService notifyService;
|
||||||
|
|
||||||
|
private final AppProperty appProperty;
|
||||||
|
|
||||||
// Утреннее сообщение
|
// Утреннее сообщение
|
||||||
@Scheduled(cron = "0 15 8 * * MON-FRI")
|
@Scheduled(cron = "0 */1 * * * *")
|
||||||
public void goodMorning() {
|
public void goodMorning() {
|
||||||
List<Person> allRegister = personService.getAllRegister();
|
List<Person> allRegister = personService.getAllRegister();
|
||||||
for (Person user : allRegister) {
|
for (Person user : allRegister) {
|
||||||
@ -48,9 +51,11 @@ public class NotificationScheduler {
|
|||||||
List<PullRequest> pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED);
|
List<PullRequest> pullRequestsNeedWork = pullRequestsService.getAllByAuthorAndReviewerStatus(user.getLogin(), ReviewerStatus.UNAPPROVED);
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
GoodMorningNotify.builder()
|
GoodMorningNotify.builder()
|
||||||
|
.personName(user.getFullName())
|
||||||
.pullRequestsNeedWork(pullRequestsNeedWork)
|
.pullRequestsNeedWork(pullRequestsNeedWork)
|
||||||
.pullRequestsReviews(pullRequestsReviews)
|
.pullRequestsReviews(pullRequestsReviews)
|
||||||
.recipients(Collections.singleton(user.getLogin()))
|
.recipients(Collections.singleton(user.getLogin()))
|
||||||
|
.version(appProperty.getVersion())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -132,8 +132,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
oldTask.getAnswers().clear();
|
oldTask.getAnswers().clear();
|
||||||
oldTask.setAnswers(existsNewAnswersIds);
|
oldTask.setAnswers(existsNewAnswersIds);
|
||||||
if (!newAnswers.isEmpty()) {
|
if (!newAnswers.isEmpty()) {
|
||||||
oldTask.getAnswers().clear();
|
|
||||||
oldTask.setAnswers(existsNewAnswersIds);
|
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
AnswerCommentNotify.builder()
|
AnswerCommentNotify.builder()
|
||||||
.recipients(Collections.singleton(oldTask.getAuthor()))
|
.recipients(Collections.singleton(oldTask.getAuthor()))
|
||||||
|
@ -48,8 +48,7 @@ public final class MessageUtils {
|
|||||||
|
|
||||||
private static String generateStringItemPullRequestReview(PullRequest pullRequest) {
|
private static String generateStringItemPullRequestReview(PullRequest pullRequest) {
|
||||||
return Smile.statusPr(pullRequest.getUpdateDate()) + " " +
|
return Smile.statusPr(pullRequest.getUpdateDate()) + " " +
|
||||||
link(pullRequest.getTitle(), pullRequest.getUrl()) +
|
link(pullRequest.getTitle(), pullRequest.getUrl());
|
||||||
Smile.BR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -31,7 +31,7 @@ public enum Smile {
|
|||||||
TOP_TWO("\uD83D\uDE0E"),
|
TOP_TWO("\uD83D\uDE0E"),
|
||||||
TOP_THREE("\uD83E\uDD49"),
|
TOP_THREE("\uD83E\uDD49"),
|
||||||
KAKASHKA("\uD83D\uDCA9"),
|
KAKASHKA("\uD83D\uDCA9"),
|
||||||
MEGA_FUN("\uD83D\uDE02"),
|
LUPA("\uD83D\uDD0D"),
|
||||||
DANGEROUS("⚠️"),
|
DANGEROUS("⚠️"),
|
||||||
BELL("\uD83D\uDECE"),
|
BELL("\uD83D\uDECE"),
|
||||||
HR("\n -- -- -- -- --\n"),
|
HR("\n -- -- -- -- --\n"),
|
||||||
|
24
pom.xml
24
pom.xml
@ -148,36 +148,14 @@
|
|||||||
<version>${javax.persistance}</version>
|
<version>${javax.persistance}</version>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<!-- <build>-->
|
|
||||||
<!-- <finalName>bitbucketbot</finalName>-->
|
|
||||||
<!-- <plugins>-->
|
|
||||||
<!-- <plugin>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
|
|
||||||
<!-- </plugin>-->
|
|
||||||
<!-- </plugins>-->
|
|
||||||
<!-- </build>-->
|
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
<id>uPagge</id>
|
<id>uPagge</id>
|
||||||
<name>Struchkov Mark</name>
|
<name>Struchkov Mark</name>
|
||||||
<email>upagge@ya.ru</email>
|
<email>upagge@mail.ru</email>
|
||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user