diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NoteService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NoteService.java index e898f46..fb2079d 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NoteService.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NoteService.java @@ -19,6 +19,4 @@ public interface NoteService extends SimpleManagerService { Note convert(@NonNull Task task); - Set existsById(@NonNull Set ids); - } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java index c983652..911fbe2 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/MergeRequestsServiceImpl.java @@ -11,8 +11,8 @@ import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter; 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; +import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.UpdatePrNotify; import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository; -import org.sadtech.bot.gitlab.context.service.AppSettingService; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.PersonService; @@ -37,7 +37,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService filterService; private final ProjectService projectService; - private final AppSettingService settingService; private final PersonInformation personInformation; @@ -47,7 +46,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService filterService, ProjectService projectService, - AppSettingService settingService, PersonInformation personInformation ) { super(mergeRequestRepository); @@ -56,7 +54,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден")); - notifyStatus(oldMergeRequest, mergeRequest, project); - notifyConflict(oldMergeRequest, mergeRequest, project); + if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())) { + final Project project = projectService.getById(mergeRequest.getProjectId()) + .orElseThrow(() -> new NotFoundException("Проект не найден")); - return mergeRequestRepository.save(mergeRequest); + notifyStatus(oldMergeRequest, mergeRequest, project); + notifyConflict(oldMergeRequest, mergeRequest, project); + notifyUpdate(oldMergeRequest, mergeRequest, project); + + return mergeRequestRepository.save(mergeRequest); + } + return oldMergeRequest; + } + + private void notifyUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) { + if (!personInformation.getId().equals(mergeRequest.getAuthor().getId())) { + notifyService.send( + UpdatePrNotify.builder() + .author(oldMergeRequest.getAuthor().getName()) + .name(oldMergeRequest.getTitle()) + .projectKey(project.getName()) + .url(oldMergeRequest.getWebUrl()) + .build() + ); + } } protected void forgottenNotification(MergeRequest mergeRequest) { diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NoteServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NoteServiceImpl.java index 1d211c9..cad894a 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NoteServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NoteServiceImpl.java @@ -13,6 +13,7 @@ import org.sadtech.haiti.context.domain.ExistsContainer; import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.springframework.context.annotation.Lazy; import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.Collection; @@ -22,7 +23,7 @@ import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -//@Service +@Service public class NoteServiceImpl extends AbstractSimpleManagerService implements NoteService { private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java index 6ee857a..6c0e00c 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/NoteParser.java @@ -2,19 +2,24 @@ package org.sadtech.bot.gitlab.core.service.parser; import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.sadtech.bot.gitlab.context.domain.entity.Note; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; +import org.sadtech.bot.gitlab.context.service.NoteService; import org.sadtech.bot.gitlab.context.service.ProjectService; import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.core.config.properties.InitProperty; import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.sdk.domain.NoteJson; +import org.sadtech.haiti.context.domain.ExistsContainer; import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.utils.network.HttpParse; import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Component; import java.text.MessageFormat; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT; @@ -25,7 +30,7 @@ import static org.sadtech.haiti.utils.network.HttpParse.BEARER; *

Поиск новых комментариев и задач.

*

К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом

*/ -//@Component +@Component public class NoteParser { public static final int COUNT = 100; @@ -37,23 +42,27 @@ public class NoteParser { private final GitlabProperty gitlabProperty; private final InitProperty initProperty; private final PersonProperty personProperty; + private final NoteService noteService; public NoteParser( ProjectService projectService, MergeRequestsService mergeRequestsService, ConversionService conversionService, GitlabProperty gitlabProperty, InitProperty initProperty, - PersonProperty personProperty) { + PersonProperty personProperty, + NoteService noteService + ) { this.projectService = projectService; this.mergeRequestsService = mergeRequestsService; this.conversionService = conversionService; this.gitlabProperty = gitlabProperty; this.initProperty = initProperty; this.personProperty = personProperty; + this.noteService = noteService; } public void scanNewCommentAndTask() { - int page = 0; + int page = 1; Sheet mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT)); while (mergeRequestSheet.hasContent()) { @@ -68,6 +77,9 @@ public class NoteParser { .filter(noteJson -> !noteJson.isSystem()) .collect(Collectors.toList()); + createNewComment(noteJsons); + createNewTask(noteJsons); + } mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT)); @@ -75,6 +87,28 @@ public class NoteParser { } + private void createNewComment(List noteJsons) { + final List newJsons = noteJsons.stream() + .filter(json -> json.getType() == null) + .collect(Collectors.toList()); + + final Set jsonIds = newJsons.stream() + .map(NoteJson::getId) + .collect(Collectors.toSet()); + + final ExistsContainer existsContainer = noteService.existsById(jsonIds); + + if (!existsContainer.isAllFound()) { + final List newNotes = newJsons.stream() + .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .map(json -> conversionService.convert(json, Note.class)) + .collect(Collectors.toList()); + + noteService.createAll(newNotes); + } + + } + // private List generatingLinksToPossibleComments(@NonNull Long commentId) { // List commentUrls = new ArrayList<>(); // for (int i = 0; i < 5; i++) {