diff --git a/pom.xml b/pom.xml
index 9056521..4d132d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,12 +30,6 @@
spring-boot-starter
-
-
-
-
-
-
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/config/AppConfig.java b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java
index 12ed871..f978d82 100644
--- a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java
+++ b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java
@@ -13,14 +13,8 @@ public class AppConfig {
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
- taskScheduler.setPoolSize(6);
+ taskScheduler.setPoolSize(5);
return taskScheduler;
}
-// @Bean
-// public ObjectMapper objectMapper(ObjectMapper objectMapper) {
-// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-// return objectMapper;
-// }
-
}
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..4b6f6be 100644
--- a/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java
+++ b/src/main/java/com/tsc/bitbucketbot/repository/jpa/PullRequestsRepository.java
@@ -6,6 +6,7 @@ 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 +26,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")
+ List findAllByReviewers(@Param("reviewer") String reviewer);
+
+ @Query("SELECT p.id from PullRequest p")
+ Set getAllIds();
+
}
diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java
index 7e93fb2..9e265fe 100644
--- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java
+++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java
@@ -1,6 +1,8 @@
//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;
@@ -13,10 +15,14 @@
//public class SchedulerNotification {
//
// private final UserService userService;
+// private final PullRequestsService pullRequestsService;
//
-// @Scheduled(cron = "0 9 * * MON-FRI")
+//// @Scheduled(cron = "0 9 * * MON-FRI")
+// @Scheduled(fixedRate = 50000)
// public void goodMorning() {
// List users = userService.getAllRegister();
+// List mstruchkov = pullRequestsService.getAllByReviewer("mstruchkov");
+// System.out.println();
// }
//
//}
diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java
index e7d9ec0..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,7 +48,17 @@ public class SchedulerPullRequest {
private final BitbucketConfig bitbucketConfig;
@Scheduled(fixedRate = 30000)
- public void checkClosePullRequest() {
+ 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);
@@ -96,9 +107,9 @@ public class SchedulerPullRequest {
}
}
- @Scheduled(fixedRate = 30000)
- public void checkOldPullRequest() {
+ 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
diff --git a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java
index 203fb6a..571e9f0 100644
--- a/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java
+++ b/src/main/java/com/tsc/bitbucketbot/service/PullRequestsService.java
@@ -29,4 +29,8 @@ public interface PullRequestsService {
void deleteAll(@NonNull Set id);
+ List getAllByReviewer(@NonNull String login);
+
+ Set getAllId();
+
}
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..f79f092 100644
--- a/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java
+++ b/src/main/java/com/tsc/bitbucketbot/service/impl/PullRequestsServiceImpl.java
@@ -60,4 +60,14 @@ public class PullRequestsServiceImpl implements PullRequestsService {
pullRequestsRepository.deleteAllByIdIn(id);
}
+ @Override
+ public List getAllByReviewer(@NonNull String login) {
+ return pullRequestsRepository.findAllByReviewers(login);
+ }
+
+ @Override
+ public Set getAllId() {
+ return pullRequestsRepository.getAllIds();
+ }
+
}