Настройка пр

This commit is contained in:
uPagge 2021-02-05 15:06:02 +03:00
parent 290a49c263
commit 6946a63da4
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
11 changed files with 99 additions and 61 deletions

View File

@ -15,6 +15,8 @@ menu.add_project_success=Project added successfully
ui.menu.setting.text=This is the settings menu
ui.menu.setting.language=Language settings
ui.menu.setting.language.text=Choose your language
ui.answer.no_task=No tasks found
ui.answer.no_mr=You are not assigned in charge of MR
notify.pr.new={0} *New MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
notify.pr.forgotten={0} *MergeRequest Review Reminder | {4}*{3}[{1}]({2})
notify.pr.conflict={0} *Attention! MergeRequest conflict | {4}*{1}[{2}]({3})

View File

@ -15,6 +15,8 @@ menu.add_project_success=Проект успешно добавлен
ui.menu.setting.text=Это меню настроек
ui.menu.setting.language=Настройки языка
ui.menu.setting.language.text=Выберете язык
ui.answer.no_task=Задачи не найдены
ui.answer.no_mr=Вы не назначены ответственным за MR
notify.pr.new={0} *Новый MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
notify.pr.forgotten={0} *Напоминание о просмотре PullRequest | {4}*{3}[{1}]({2})
notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3})

View File

@ -6,15 +6,18 @@ import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import java.util.Set;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class PullRequestFilter {
public class MergeRequestFilter {
private Long bitbucketId;
private Long bitbucketRepositoryId;
private Long assignee;
private Set<MergeRequestState> states;
}

View File

@ -4,17 +4,16 @@ import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
import org.sadtech.haiti.filter.FilterOperation;
import java.util.Optional;
import java.util.List;
import java.util.Set;
public interface MergeRequestRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> {
Set<IdAndStatusPr> findAllIdByStateIn(Set<MergeRequestState> states);
Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id);
List<MergeRequest> findAllByAssignee(@NonNull Long userId);
}

View File

@ -1,18 +1,16 @@
package org.sadtech.bot.gitlab.context.service;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.haiti.context.service.SimpleManagerService;
import org.sadtech.haiti.filter.FilterService;
import java.util.Optional;
import java.util.List;
import java.util.Set;
public interface MergeRequestsService extends SimpleManagerService<MergeRequest, Long>, FilterService<MergeRequest, PullRequestFilter> {
public interface MergeRequestsService extends SimpleManagerService<MergeRequest, Long>, FilterService<MergeRequest, MergeRequestFilter> {
/**
* Получить все идентификаторы вместе со статусами.
@ -22,6 +20,6 @@ public interface MergeRequestsService extends SimpleManagerService<MergeRequest,
*/
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
Optional<MergeRequestMini> getMiniInfo(@NonNull Long pullRequestId);
List<MergeRequest> getAllByAssignee(Long userId);
}

View File

@ -5,9 +5,8 @@ import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.ConflictPrNotify;
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.NewPrNotify;
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.StatusPrNotify;
@ -25,7 +24,7 @@ import org.sadtech.haiti.filter.FilterService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@ -35,7 +34,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
private final NotifyService notifyService;
private final MergeRequestRepository mergeRequestRepository;
private final PersonService personService;
private final FilterService<MergeRequest, PullRequestFilter> filterService;
private final FilterService<MergeRequest, MergeRequestFilter> filterService;
private final ProjectService projectService;
private final PersonInformation personInformation;
@ -44,7 +43,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
MergeRequestRepository mergeRequestRepository,
NotifyService notifyService,
PersonService personService,
@Qualifier("mergeRequestFilterService") FilterService<MergeRequest, PullRequestFilter> filterService,
@Qualifier("mergeRequestFilterService") FilterService<MergeRequest, MergeRequestFilter> filterService,
ProjectService projectService,
PersonInformation personInformation
) {
@ -197,38 +196,34 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
}
}
protected boolean enoughTimHasPassedSinceUpdatePr(LocalDateTime updateDate) {
return LocalDateTime.now().isAfter(updateDate.plusHours(4L));
}
@Override
public Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses) {
return mergeRequestRepository.findAllIdByStateIn(statuses);
}
@Override
public Optional<MergeRequestMini> getMiniInfo(@NonNull Long pullRequestId) {
return mergeRequestRepository.findMiniInfoById(pullRequestId);
public List<MergeRequest> getAllByAssignee(@NonNull Long userId) {
return mergeRequestRepository.findAllByAssignee(userId);
}
@Override
public Sheet<MergeRequest> getAll(@NonNull PullRequestFilter filter, Pagination pagination) {
public Sheet<MergeRequest> getAll(@NonNull MergeRequestFilter filter, Pagination pagination) {
return filterService.getAll(filter, pagination);
}
@Override
public Optional<MergeRequest> getFirst(@NonNull PullRequestFilter pullRequestFilter) {
return filterService.getFirst(pullRequestFilter);
public Optional<MergeRequest> getFirst(@NonNull MergeRequestFilter mergeRequestFilter) {
return filterService.getFirst(mergeRequestFilter);
}
@Override
public boolean exists(@NonNull PullRequestFilter filter) {
public boolean exists(@NonNull MergeRequestFilter filter) {
return filterService.exists(filter);
}
@Override
public long count(@NonNull PullRequestFilter pullRequestFilter) {
return filterService.count(pullRequestFilter);
public long count(@NonNull MergeRequestFilter mergeRequestFilter) {
return filterService.count(mergeRequestFilter);
}
}

View File

@ -2,7 +2,8 @@ package org.sadtech.bot.gitlab.core.service.impl.filter;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest_;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository;
import org.sadtech.haiti.core.service.AbstractFilterService;
import org.sadtech.haiti.filter.Filter;
@ -12,23 +13,24 @@ import org.sadtech.haiti.filter.criteria.CriteriaQuery;
import org.springframework.stereotype.Service;
@Service
public class MergeRequestFilterService extends AbstractFilterService<MergeRequest, PullRequestFilter> {
public class MergeRequestFilterService extends AbstractFilterService<MergeRequest, MergeRequestFilter> {
public MergeRequestFilterService(MergeRequestRepository filterOperation) {
super(filterOperation);
}
@Override
protected Filter createFilter(@NonNull PullRequestFilter filter) {
protected Filter createFilter(@NonNull MergeRequestFilter filter) {
return CriteriaFilter.<MergeRequest>create()
.and(
convertFilter(filter)
);
}
private FilterQuery convertFilter(@NonNull PullRequestFilter filter) {
private FilterQuery convertFilter(@NonNull MergeRequestFilter filter) {
return CriteriaQuery.<MergeRequest>create()
.matchPhrase("hyita", filter.getBitbucketId())
.matchPhrase("hyita", filter.getBitbucketRepositoryId());
.matchPhrase(MergeRequest_.ASSIGNEE, filter.getAssignee())
.matchPhrase(MergeRequest_.STATE, filter.getStates());
}
}

View File

@ -4,26 +4,22 @@ import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository;
import org.sadtech.bot.gitlab.data.jpa.MergeRequestJpaRepository;
import org.sadtech.bot.gitlab.data.jpa.MergeRequestMiniJpaRepository;
import org.sadtech.haiti.database.repository.manager.FilterManagerRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import java.util.List;
import java.util.Set;
@Repository
public class MergeRequestRepositoryImpl extends FilterManagerRepository<MergeRequest, Long> implements MergeRequestRepository {
private final MergeRequestJpaRepository repositoryJpa;
private final MergeRequestMiniJpaRepository mergeRequestMiniJpaRepository;
public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository, MergeRequestMiniJpaRepository mergeRequestMiniJpaRepository) {
public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository) {
super(jpaRepository);
repositoryJpa = jpaRepository;
this.mergeRequestMiniJpaRepository = mergeRequestMiniJpaRepository;
}
@Override
@ -32,8 +28,8 @@ public class MergeRequestRepositoryImpl extends FilterManagerRepository<MergeReq
}
@Override
public Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id) {
return mergeRequestMiniJpaRepository.findById(id);
public List<MergeRequest> findAllByAssignee(@NonNull Long userId) {
return repositoryJpa.findAllByAssigneeId(userId);
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.support.JpaRepositoryImplementati
import org.springframework.data.repository.query.Param;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@ -30,4 +31,6 @@ public interface MergeRequestJpaRepository extends JpaRepositoryImplementation<M
@Query("SELECT p.author.id from MergeRequest p WHERE p.id = :id")
Optional<String> findAuthorById(@Param("id") Long id);
List<MergeRequest> findAllByAssigneeId(Long userId);
}

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* // TODO: 12.09.2020 Добавить описание.
*
* @author upagge 12.09.2020
*/
public interface MergeRequestMiniJpaRepository extends JpaRepository<MergeRequestMini, Long> {
}

View File

@ -1,10 +1,17 @@
package org.sadtech.bot.gitlab.telegram.unit;
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.entity.Task;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
import org.sadtech.bot.gitlab.context.service.TaskService;
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
import org.sadtech.bot.gitlab.core.service.parser.ProjectParser;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl;
import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.keyboard.KeyBoard;
@ -16,6 +23,7 @@ import org.springframework.context.annotation.Configuration;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -32,7 +40,8 @@ public class MenuConfig {
AppSettingService settingService,
AnswerText settings,
AnswerText textAddNewProject,
AnswerText getTasks
AnswerText getTasks,
AnswerText getAssigneeMergeRequest
) {
return AnswerText.builder()
.boxAnswer(message ->
@ -70,6 +79,7 @@ public class MenuConfig {
.nextUnit(settings)
.nextUnit(textAddNewProject)
.nextUnit(getTasks)
.nextUnit(getAssigneeMergeRequest)
.build();
}
@ -129,13 +139,54 @@ public class MenuConfig {
{
final Long userId = personInformation.getId();
final String text = taskService.getAllPersonTask(userId, false).stream()
// .collect(Collectors.groupingBy())
.map(note -> MessageFormat.format("[{0}]({1})", note.getBody(), note.getWebUrl()))
.collect(Collectors.joining("\n"));
return BoxAnswer.of(text);
.collect(Collectors.groupingBy(Task::getMergeRequest))
.entrySet()
.stream()
.map(node -> {
final String mrTitle = node.getKey().getTitle();
final String mrUrl = node.getKey().getWebUrl();
final String taskText = node.getValue().stream()
.map(task -> MessageFormat.format("[{0}]({1})", task.getBody(), task.getWebUrl()))
.collect(Collectors.joining("\n"));
return MessageFormat.format("- [{0}]({1}):\n{2}", mrTitle, mrUrl, taskText);
})
.collect(Collectors.joining("\n\n"));
return BoxAnswer.of("".equals(text) ? settingService.getMessage("ui.answer.no_task") : text);
})
.phrase(settingService.getMessage("ui.menu.task"))
.build();
}
@Bean
public AnswerText getAssigneeMergeRequest(
MergeRequestsService mergeRequestsService,
PersonInformation personInformation,
AppSettingService settingService
) {
return AnswerText.builder()
.boxAnswer(message -> {
final Long userId = personInformation.getId();
final Sheet<MergeRequest> sheet = mergeRequestsService.getAll(getAssigneeFilter(userId), PaginationImpl.of(0, 20));
if (sheet.hasContent()) {
final List<MergeRequest> mergeRequests = sheet.getContent();
final String text = mergeRequests.stream()
.map(mergeRequest -> MessageFormat.format("[{0}]({1})", mergeRequest.getTitle(), mergeRequest.getWebUrl()))
.collect(Collectors.joining("\n"));
return BoxAnswer.of(text);
}
return BoxAnswer.of(settingService.getMessage("ui.answer.no_mr"));
})
.phrase(settingService.getMessage("ui.menu.mr"))
.build();
}
private MergeRequestFilter getAssigneeFilter(Long userId) {
final MergeRequestFilter mergeRequestFilter = new MergeRequestFilter();
mergeRequestFilter.setAssignee(userId);
mergeRequestFilter.setStates(Collections.singleton(MergeRequestState.OPENED));
return mergeRequestFilter;
}
}