Поправил поиск активных ПРов на ревью

This commit is contained in:
Struchkov Mark 2022-12-05 16:41:31 +03:00
parent 55b1565089
commit e985fe2cbd
6 changed files with 25 additions and 10 deletions

View File

@ -30,4 +30,7 @@ public interface MergeRequestRepository {
void deleteByIds(Set<Long> mergeRequestIds); void deleteByIds(Set<Long> mergeRequestIds);
Page<MergeRequest> filter(Filter filter, Pageable pageable); Page<MergeRequest> filter(Filter filter, Pageable pageable);
List<MergeRequest> findAllByReviewerId(Long personId);
} }

View File

@ -38,4 +38,6 @@ public interface MergeRequestsService {
void deleteAllById(@NonNull Set<Long> mergeRequestIds); void deleteAllById(@NonNull Set<Long> mergeRequestIds);
List<MergeRequest> getAllByReviewerId(@NonNull Long personId);
} }

View File

@ -209,6 +209,11 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
repository.deleteByIds(mergeRequestIds); repository.deleteByIds(mergeRequestIds);
} }
@Override
public List<MergeRequest> getAllByReviewerId(@NonNull Long personId) {
return repository.findAllByReviewerId(personId);
}
private void notifyUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { private void notifyUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
if ( if (
!personInformation.getId().equals(mergeRequest.getAuthor().getId()) !personInformation.getId().equals(mergeRequest.getAuthor().getId())

View File

@ -63,4 +63,9 @@ public class MergeRequestRepositoryImpl implements MergeRequestRepository {
return jpaRepository.findAll(filter.<Specification<MergeRequest>>build(), pageable); return jpaRepository.findAll(filter.<Specification<MergeRequest>>build(), pageable);
} }
@Override
public List<MergeRequest> findAllByReviewerId(Long personId) {
return jpaRepository.findAllByReviewersIn(personId);
}
} }

View File

@ -18,19 +18,20 @@ import java.util.Set;
public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<MergeRequest, Long> { public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<MergeRequest, Long> {
Set<MergeRequest> findAllByIdIn(Set<Long> ids);
void deleteAllByIdIn(Collection<Long> id); void deleteAllByIdIn(Collection<Long> 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") @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<IdAndStatusPr> findAllIdByStateIn(@Param("states") Set<MergeRequestState> states); Set<IdAndStatusPr> findAllIdByStateIn(@Param("states") Set<MergeRequestState> states);
@Query("SELECT p.id from MergeRequest p") @Query("SELECT p.id FROM MergeRequest p")
Set<Long> findAllIds(); Set<Long> 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<String> findAuthorById(@Param("id") Long id); Optional<String> findAuthorById(@Param("id") Long id);
List<MergeRequest> findAllByAssigneeId(Long userId); List<MergeRequest> findAllByAssigneeId(Long userId);
@Query("SELECT mr FROM MergeRequest mr LEFT JOIN mr.reviewers r WHERE r.id = :reviewerId")
List<MergeRequest> findAllByReviewersIn(@Param("reviewerId") Long reviewerId);
} }

View File

@ -13,9 +13,8 @@ import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail; import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText; import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.core.unit.MainUnit; import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.haiti.utils.Checker;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
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;
@ -136,10 +135,9 @@ public class MenuConfig {
return AnswerText.<Mail>builder() return AnswerText.<Mail>builder()
.triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST) .triggerPhrase(GET_ASSIGNEE_MERGE_REQUEST)
.answer(() -> { .answer(() -> {
final Long userId = personInformation.getId(); final Long gitlabUserId = personInformation.getId();
final Page<MergeRequest> sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PageRequest.of(0, 20)); final List<MergeRequest> mergeRequests = mergeRequestsService.getAllByReviewerId(gitlabUserId);
if (sheet.hasContent()) { if (Checker.checkNotEmpty(mergeRequests)) {
final List<MergeRequest> mergeRequests = sheet.getContent();
final String text = mergeRequests.stream() final String text = mergeRequests.stream()
.map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl())) .map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl()))
.collect(Collectors.joining("\n")); .collect(Collectors.joining("\n"));
@ -150,6 +148,7 @@ public class MenuConfig {
.build(); .build();
} }
private MergeRequestFilter getAssigneeFilter(Long userId) { private MergeRequestFilter getAssigneeFilter(Long userId) {
final MergeRequestFilter mergeRequestFilter = new MergeRequestFilter(); final MergeRequestFilter mergeRequestFilter = new MergeRequestFilter();
mergeRequestFilter.setAssignee(userId); mergeRequestFilter.setAssignee(userId);