Уведомление по утрам
This commit is contained in:
parent
4b7b14f6df
commit
c09d6b2bab
@ -39,4 +39,7 @@ public class User {
|
||||
@Column(name = "telegram_id")
|
||||
private Long telegramId;
|
||||
|
||||
@Column(name = "full_name")
|
||||
private String fullName;
|
||||
|
||||
}
|
||||
|
@ -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<PullRequest, Long>
|
||||
|
||||
void deleteAllByIdIn(Collection<Long> id);
|
||||
|
||||
@Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE r.user=:reviewer")
|
||||
List<PullRequest> 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<PullRequest> findAllByReviewerAndStatuses(@Param("reviewer") String reviewer, @Param("status") ReviewerStatus status);
|
||||
|
||||
@Query("SELECT p.id from PullRequest p")
|
||||
Set<Long> getAllIds();
|
||||
|
@ -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<User> users = userService.getAllRegister();
|
||||
// List<PullRequest> 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<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses(
|
||||
user.getLogin(),
|
||||
ReviewerStatus.NEEDS_WORK
|
||||
);
|
||||
messageSendService.add(
|
||||
MessageSend.builder()
|
||||
.telegramId(3000811L)
|
||||
.message(Message.goodMorningStatistic(user.getFullName(), pullRequests))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Long> id);
|
||||
|
||||
List<PullRequest> getAllByReviewer(@NonNull String login);
|
||||
@NonNull
|
||||
List<PullRequest> getAllByReviewerAndStatuses(String login, ReviewerStatus statuses);
|
||||
|
||||
Set<Long> getAllId();
|
||||
|
||||
|
@ -16,6 +16,7 @@ public class UserJsonConverter implements Converter<UserJson, User> {
|
||||
@Override
|
||||
public User convert(UserJson source) {
|
||||
return User.builder()
|
||||
.fullName(source.getDisplayName())
|
||||
.login(source.getName())
|
||||
.build();
|
||||
}
|
||||
|
@ -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<PullRequest> getAllByReviewer(@NonNull String login) {
|
||||
return pullRequestsRepository.findAllByReviewers(login);
|
||||
public List<PullRequest> getAllByReviewerAndStatuses(String login, ReviewerStatus reviewerStatus) {
|
||||
return pullRequestsRepository.findAllByReviewerAndStatuses(login, reviewerStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<PullRequest> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<PullRequest> {
|
||||
|
||||
@Override
|
||||
public int compare(PullRequest pullRequest, PullRequest t1) {
|
||||
return pullRequest.getUpdateDate().compareTo(t1.getUpdateDate());
|
||||
}
|
||||
|
||||
}
|
@ -25,4 +25,10 @@
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="user-fullname" author="upagge">
|
||||
<addColumn tableName="user" schemaName="public" catalogName="pg_catalog">
|
||||
<column name="full_name" type="varchar(50)"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user