Упростил обработку MR и тредов
This commit is contained in:
parent
422de73854
commit
e02187d9c1
@ -1,8 +1,6 @@
|
|||||||
package dev.struchkov.bot.gitlab.context.repository;
|
package dev.struchkov.bot.gitlab.context.repository;
|
||||||
|
|
||||||
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
|
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -24,7 +22,7 @@ public interface DiscussionRepository {
|
|||||||
|
|
||||||
void deleteById(String discussionId);
|
void deleteById(String discussionId);
|
||||||
|
|
||||||
Page<Discussion> findAll(Pageable pagination);
|
List<Discussion> findAll();
|
||||||
|
|
||||||
List<Discussion> findAllById(Set<String> discussionIds);
|
List<Discussion> findAllById(Set<String> discussionIds);
|
||||||
|
|
||||||
|
@ -16,14 +16,11 @@ public interface MergeRequestRepository {
|
|||||||
|
|
||||||
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
|
Set<IdAndStatusPr> findAllIdByStateIn(@NonNull Set<MergeRequestState> states);
|
||||||
|
|
||||||
//TODO [28.01.2022]: Решить, нужно ли оставить
|
|
||||||
List<MergeRequest> findAllByAssignee(@NonNull Long userId);
|
|
||||||
|
|
||||||
MergeRequest save(MergeRequest mergeRequest);
|
MergeRequest save(MergeRequest mergeRequest);
|
||||||
|
|
||||||
Optional<MergeRequest> findById(Long mergeRequestId);
|
Optional<MergeRequest> findById(Long mergeRequestId);
|
||||||
|
|
||||||
Page<MergeRequest> findAll(Pageable pagination);
|
List<MergeRequest> findAll();
|
||||||
|
|
||||||
List<MergeRequest> findAllById(Set<Long> mergeRequestIds);
|
List<MergeRequest> findAllById(Set<Long> mergeRequestIds);
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ package dev.struchkov.bot.gitlab.context.service;
|
|||||||
import dev.struchkov.bot.gitlab.context.domain.ExistContainer;
|
import dev.struchkov.bot.gitlab.context.domain.ExistContainer;
|
||||||
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
|
import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -37,7 +35,7 @@ public interface DiscussionService {
|
|||||||
|
|
||||||
List<Discussion> createAll(@NonNull List<Discussion> newDiscussions);
|
List<Discussion> createAll(@NonNull List<Discussion> newDiscussions);
|
||||||
|
|
||||||
Page<Discussion> getAll(@NonNull Pageable pagination);
|
List<Discussion> getAll();
|
||||||
|
|
||||||
void deleteById(String discussionId);
|
void deleteById(String discussionId);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public interface MergeRequestsService {
|
|||||||
*/
|
*/
|
||||||
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
|
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
|
||||||
|
|
||||||
Page<MergeRequest> getAll(Pageable pagination);
|
List<MergeRequest> getAll();
|
||||||
|
|
||||||
Page<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pageable pagination);
|
Page<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pageable pagination);
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import okhttp3.FormBody;
|
|||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@ -297,8 +295,8 @@ public class DiscussionServiceImpl implements DiscussionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<Discussion> getAll(@NonNull Pageable pagination) {
|
public List<Discussion> getAll() {
|
||||||
return repository.findAll(pagination);
|
return repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -210,8 +210,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MergeRequest> getAll(Pageable pagination) {
|
public List<MergeRequest> getAll() {
|
||||||
return repository.findAll(pagination);
|
return repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,8 +14,6 @@ import dev.struchkov.haiti.utils.network.HttpParse;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@ -45,8 +43,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DiscussionParser {
|
public class DiscussionParser {
|
||||||
|
|
||||||
public static final int COUNT = 500;
|
|
||||||
|
|
||||||
private final DiscussionService discussionService;
|
private final DiscussionService discussionService;
|
||||||
private final MergeRequestsService mergeRequestsService;
|
private final MergeRequestsService mergeRequestsService;
|
||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
@ -59,18 +55,12 @@ public class DiscussionParser {
|
|||||||
*/
|
*/
|
||||||
public void scanNewDiscussion() {
|
public void scanNewDiscussion() {
|
||||||
log.debug("Старт обработки новых дискуссий");
|
log.debug("Старт обработки новых дискуссий");
|
||||||
int page = 0;
|
final List<MergeRequest> mergeRequests = mergeRequestsService.getAll();
|
||||||
Page<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(page, COUNT));
|
|
||||||
|
|
||||||
while (mergeRequestSheet.hasContent()) {
|
for (MergeRequest mergeRequest : mergeRequests) {
|
||||||
final List<MergeRequest> mergeRequests = mergeRequestSheet.getContent();
|
processingMergeRequest(mergeRequest);
|
||||||
|
|
||||||
for (MergeRequest mergeRequest : mergeRequests) {
|
|
||||||
processingMergeRequest(mergeRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeRequestSheet = mergeRequestsService.getAll(PageRequest.of(++page, COUNT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Конец обработки новых дискуссий");
|
log.debug("Конец обработки новых дискуссий");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,38 +146,32 @@ public class DiscussionParser {
|
|||||||
*/
|
*/
|
||||||
public void scanOldDiscussions() {
|
public void scanOldDiscussions() {
|
||||||
log.debug("Старт обработки старых дискуссий");
|
log.debug("Старт обработки старых дискуссий");
|
||||||
int page = 0;
|
final List<Discussion> discussions = discussionService.getAll();
|
||||||
Page<Discussion> discussionPage = discussionService.getAll(PageRequest.of(page, COUNT));
|
|
||||||
|
|
||||||
while (discussionPage.hasContent()) {
|
// Удаляем обсуждения, которые потеряли свои MR
|
||||||
final List<Discussion> discussions = discussionPage.getContent();
|
//TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия
|
||||||
|
discussions.stream()
|
||||||
|
.filter(discussion -> checkNull(discussion.getMergeRequest()))
|
||||||
|
.map(Discussion::getId)
|
||||||
|
.forEach(discussionService::deleteById);
|
||||||
|
|
||||||
// Удаляем обсуждения, которые потеряли свои MR
|
final List<Discussion> newDiscussions = new ArrayList<>();
|
||||||
//TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия
|
for (Discussion discussion : discussions) {
|
||||||
discussions.stream()
|
if (checkNotNull(discussion.getMergeRequest())) {
|
||||||
.filter(discussion -> checkNull(discussion.getMergeRequest()))
|
getOldDiscussionJson(discussion)
|
||||||
.map(Discussion::getId)
|
.map(json -> {
|
||||||
.forEach(discussionService::deleteById);
|
final Discussion newDiscussion = conversionService.convert(json, Discussion.class);
|
||||||
|
newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest()));
|
||||||
final List<Discussion> newDiscussions = new ArrayList<>();
|
return newDiscussion;
|
||||||
for (Discussion discussion : discussions) {
|
}).ifPresent(newDiscussions::add);
|
||||||
if (checkNotNull(discussion.getMergeRequest())) {
|
|
||||||
getOldDiscussionJson(discussion)
|
|
||||||
.map(json -> {
|
|
||||||
final Discussion newDiscussion = conversionService.convert(json, Discussion.class);
|
|
||||||
newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest()));
|
|
||||||
return newDiscussion;
|
|
||||||
}).ifPresent(newDiscussions::add);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkNotEmpty(newDiscussions)) {
|
|
||||||
personMapping(newDiscussions);
|
|
||||||
discussionService.updateAll(newDiscussions);
|
|
||||||
}
|
|
||||||
|
|
||||||
discussionPage = discussionService.getAll(PageRequest.of(++page, COUNT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkNotEmpty(newDiscussions)) {
|
||||||
|
personMapping(newDiscussions);
|
||||||
|
discussionService.updateAll(newDiscussions);
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("Конец обработки старых дискуссий");
|
log.debug("Конец обработки старых дискуссий");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,6 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
|||||||
@Service
|
@Service
|
||||||
public class PipelineParser {
|
public class PipelineParser {
|
||||||
|
|
||||||
public static final Integer COUNT = 100;
|
|
||||||
private static final Set<PipelineStatus> oldStatus = Set.of(
|
private static final Set<PipelineStatus> oldStatus = Set.of(
|
||||||
CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL
|
CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL
|
||||||
);
|
);
|
||||||
|
@ -6,8 +6,6 @@ import dev.struchkov.bot.gitlab.data.jpa.DiscussionJpaRepository;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -45,8 +43,8 @@ public class DiscussionRepositoryImpl implements DiscussionRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<Discussion> findAll(Pageable pagination) {
|
public List<Discussion> findAll() {
|
||||||
return jpaRepository.findAll(pagination);
|
return jpaRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,11 +28,6 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
|
|||||||
return jpaRepository.findAllIdByStateIn(statuses);
|
return jpaRepository.findAllIdByStateIn(statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<MergeRequest> findAllByAssignee(@NonNull Long userId) {
|
|
||||||
return jpaRepository.findAllByAssigneeId(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MergeRequest save(MergeRequest mergeRequest) {
|
public MergeRequest save(MergeRequest mergeRequest) {
|
||||||
return jpaRepository.save(mergeRequest);
|
return jpaRepository.save(mergeRequest);
|
||||||
@ -44,8 +39,8 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MergeRequest> findAll(Pageable pagination) {
|
public List<MergeRequest> findAll() {
|
||||||
return jpaRepository.findAll(pagination);
|
return jpaRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user