From e985fe2cbd18985445f20931e495fe92dc421a48 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 5 Dec 2022 16:41:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D0=B2=D0=BD=D1=8B=D1=85=20=D0=9F=D0=A0=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../context/repository/MergeRequestRepository.java | 3 +++ .../gitlab/context/service/MergeRequestsService.java | 2 ++ .../core/service/impl/MergeRequestsServiceImpl.java | 5 +++++ .../gitlab/data/impl/MergeRequestRepositoryImpl.java | 5 +++++ .../gitlab/data/jpa/MergeRequestJpaRepository.java | 9 +++++---- .../bot/gitlab/telegram/unit/MenuConfig.java | 11 +++++------ 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java index cbe8d6a..921520b 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/repository/MergeRequestRepository.java @@ -30,4 +30,7 @@ public interface MergeRequestRepository { void deleteByIds(Set mergeRequestIds); Page filter(Filter filter, Pageable pageable); + + List findAllByReviewerId(Long personId); + } diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java index d7a22e2..1b42371 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/service/MergeRequestsService.java @@ -38,4 +38,6 @@ public interface MergeRequestsService { void deleteAllById(@NonNull Set mergeRequestIds); + List getAllByReviewerId(@NonNull Long personId); + } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index eeb8051..312fdda 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -209,6 +209,11 @@ public class MergeRequestsServiceImpl implements MergeRequestsService { repository.deleteByIds(mergeRequestIds); } + @Override + public List getAllByReviewerId(@NonNull Long personId) { + return repository.findAllByReviewerId(personId); + } + private void notifyUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { if ( !personInformation.getId().equals(mergeRequest.getAuthor().getId()) diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java index dcb21ef..41473da 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java @@ -63,4 +63,9 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository { return jpaRepository.findAll(filter.>build(), pageable); } + @Override + public List findAllByReviewerId(Long personId) { + return jpaRepository.findAllByReviewersIn(personId); + } + } diff --git a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestJpaRepository.java b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestJpaRepository.java index 6fd0c40..ef4184c 100644 --- a/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestJpaRepository.java +++ b/bot-data/src/main/java/dev/struchkov/bot/gitlab/data/jpa/MergeRequestJpaRepository.java @@ -18,19 +18,20 @@ import java.util.Set; public interface MergeRequestJpaRepository extends JpaRepositoryImplementation { - Set findAllByIdIn(Set ids); - void deleteAllByIdIn(Collection id); @Query("SELECT new dev.struchkov.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.twoId, p.projectId, p.state) FROM MergeRequest p WHERE p.state IN :states") Set findAllIdByStateIn(@Param("states") Set states); - @Query("SELECT p.id from MergeRequest p") + @Query("SELECT p.id FROM MergeRequest p") Set findAllIds(); - @Query("SELECT p.author.id from MergeRequest p WHERE p.id = :id") + @Query("SELECT p.author.id FROM MergeRequest p WHERE p.id = :id") Optional findAuthorById(@Param("id") Long id); List findAllByAssigneeId(Long userId); + @Query("SELECT mr FROM MergeRequest mr LEFT JOIN mr.reviewers r WHERE r.id = :reviewerId") + List findAllByReviewersIn(@Param("reviewerId") Long reviewerId); + } diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java index 2bd93b3..a79a07f 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/unit/MenuConfig.java @@ -13,9 +13,8 @@ import dev.struchkov.godfather.main.domain.annotation.Unit; import dev.struchkov.godfather.main.domain.content.Mail; import dev.struchkov.godfather.simple.core.unit.AnswerText; import dev.struchkov.godfather.simple.core.unit.MainUnit; +import dev.struchkov.haiti.utils.Checker; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Component; import java.text.MessageFormat; @@ -136,10 +135,9 @@ public class MenuConfig { return AnswerText.builder() .triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST) .answer(() -> { - final Long userId = personInformation.getId(); - final Page sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PageRequest.of(0, 20)); - if (sheet.hasContent()) { - final List mergeRequests = sheet.getContent(); + final Long gitlabUserId = personInformation.getId(); + final List mergeRequests = mergeRequestsService.getAllByReviewerId(gitlabUserId); + if (Checker.checkNotEmpty(mergeRequests)) { final String text = mergeRequests.stream() .map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl())) .collect(Collectors.joining("\n")); @@ -150,6 +148,7 @@ public class MenuConfig { .build(); } + private MergeRequestFilter getAssigneeFilter(Long userId) { final MergeRequestFilter mergeRequestFilter = new MergeRequestFilter(); mergeRequestFilter.setAssignee(userId);