Рабочая версия

This commit is contained in:
upagge 2020-04-07 11:25:08 +03:00
parent 8bc397dc8c
commit 7fe3388207
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
3 changed files with 27 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.domain.entity.Reviewer;
import com.tsc.bitbucketbot.domain.entity.User;
import com.tsc.bitbucketbot.domain.util.ReviewerChange;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import com.tsc.bitbucketbot.dto.bitbucket.sheet.PullRequestSheetJson;
import com.tsc.bitbucketbot.service.MessageSendService;
import com.tsc.bitbucketbot.service.PullRequestsService;
@ -31,6 +32,11 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.DECLINED;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.MERGED;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.OPEN;
/**
* @author upagge [30.01.2020]
@ -39,6 +45,8 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class SchedulerPullRequest {
private static final Set<PullRequestStatus> STATUSES = Stream.of(MERGED, OPEN, DECLINED).collect(Collectors.toSet());
private final PullRequestsService pullRequestsService;
private final UserService userService;
private final MessageSendService messageSendService;
@ -47,7 +55,9 @@ public class SchedulerPullRequest {
@Scheduled(fixedRate = 30000)
public void checkOldPullRequest() {
final Set<Long> existsId = pullRequestsService.getAllId();
final Set<Long> existsId = pullRequestsService.getAllId(STATUSES).stream()
.map(IdAndStatusPr::getId)
.collect(Collectors.toSet());
final Set<Long> openId = checkOpenPullRequest();
final Set<Long> closeId = checkClosePullRequest();
final Set<Long> newNotExistsId = existsId.stream()
@ -119,17 +129,17 @@ public class SchedulerPullRequest {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) {
final PullRequestSheetJson jsonSheet = sheetJson.get();
final Map<Long, PullRequest> existsJsonPr = jsonSheet.getValues().stream()
final Map<Long, PullRequest> existsPr = jsonSheet.getValues().stream()
.filter(Objects::nonNull)
.map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class))
.peek(pullRequest -> pullRequestsService.getIdByBitbucketIdAndReposId(pullRequest.getBitbucketId(), pullRequest.getRepositoryId()).ifPresent(pullRequest::setId))
.filter(pullRequest -> pullRequest.getId() != null)
.collect(Collectors.toMap(PullRequest::getId, pullRequest -> pullRequest));
final Set<PullRequest> pullRequests = pullRequestsService.getAllById(existsJsonPr.keySet());
if (!existsJsonPr.isEmpty() && !pullRequests.isEmpty()) {
processingUpdate(existsJsonPr, pullRequests);
final Set<PullRequest> pullRequests = pullRequestsService.getAllById(existsPr.keySet());
if (!existsPr.isEmpty() && !pullRequests.isEmpty()) {
processingUpdate(existsPr, pullRequests);
ids.addAll(
pullRequestsService.updateAll(existsJsonPr.values()).stream()
pullRequestsService.updateAll(existsPr.values()).stream()
.map(PullRequest::getId)
.collect(Collectors.toSet())
);

View File

@ -1,8 +1,10 @@
package com.tsc.bitbucketbot.service;
import com.tsc.bitbucketbot.domain.Pagination;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import lombok.NonNull;
import org.springframework.data.domain.Page;
@ -35,6 +37,8 @@ public interface PullRequestsService {
Set<Long> getAllId();
Set<IdAndStatusPr> getAllId(Collection<PullRequestStatus> statuses);
Page<PullRequest> getAll(@NonNull Pagination pagination);
List<PullRequest> getAllByAuthor(@NonNull String login, @NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);

View File

@ -1,8 +1,10 @@
package com.tsc.bitbucketbot.service.impl;
import com.tsc.bitbucketbot.domain.Pagination;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import com.tsc.bitbucketbot.repository.jpa.PullRequestsRepository;
import com.tsc.bitbucketbot.service.PullRequestsService;
import lombok.NonNull;
@ -76,6 +78,11 @@ public class PullRequestsServiceImpl implements PullRequestsService {
return pullRequestsRepository.findAllIds();
}
@Override
public Set<IdAndStatusPr> getAllId(Collection<PullRequestStatus> statuses) {
return pullRequestsRepository.findAllIdByStatusIn(statuses);
}
@Override
public Page<PullRequest> getAll(@NonNull Pagination pagination) {
return pullRequestsRepository.findAll(PageRequest.of(pagination.getPage(), pagination.getSize()));