Уведомление об обновлении пр

This commit is contained in:
uPagge 2021-01-17 00:36:20 +03:00
parent ea0cc8897a
commit 31f59fc0d5
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
4 changed files with 64 additions and 16 deletions

View File

@ -19,6 +19,4 @@ public interface NoteService extends SimpleManagerService<Note, Long> {
Note convert(@NonNull Task task); Note convert(@NonNull Task task);
Set<Long> existsById(@NonNull Set<Long> ids);
} }

View File

@ -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.ConflictPrNotify;
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.NewPrNotify; 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.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.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.MergeRequestsService;
import org.sadtech.bot.gitlab.context.service.NotifyService; import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.PersonService;
@ -37,7 +37,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
private final PersonService personService; private final PersonService personService;
private final FilterService<MergeRequest, PullRequestFilter> filterService; private final FilterService<MergeRequest, PullRequestFilter> filterService;
private final ProjectService projectService; private final ProjectService projectService;
private final AppSettingService settingService;
private final PersonInformation personInformation; private final PersonInformation personInformation;
@ -47,7 +46,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
PersonService personService, PersonService personService,
@Qualifier("mergeRequestFilterService") FilterService<MergeRequest, PullRequestFilter> filterService, @Qualifier("mergeRequestFilterService") FilterService<MergeRequest, PullRequestFilter> filterService,
ProjectService projectService, ProjectService projectService,
AppSettingService settingService,
PersonInformation personInformation PersonInformation personInformation
) { ) {
super(mergeRequestRepository); super(mergeRequestRepository);
@ -56,7 +54,6 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
this.personService = personService; this.personService = personService;
this.filterService = filterService; this.filterService = filterService;
this.projectService = projectService; this.projectService = projectService;
this.settingService = settingService;
this.personInformation = personInformation; this.personInformation = personInformation;
} }
@ -101,13 +98,31 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
// forgottenNotification(oldMergeRequest); // forgottenNotification(oldMergeRequest);
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())) {
final Project project = projectService.getById(mergeRequest.getProjectId()) final Project project = projectService.getById(mergeRequest.getProjectId())
.orElseThrow(() -> new NotFoundException("Проект не найден")); .orElseThrow(() -> new NotFoundException("Проект не найден"));
notifyStatus(oldMergeRequest, mergeRequest, project); notifyStatus(oldMergeRequest, mergeRequest, project);
notifyConflict(oldMergeRequest, mergeRequest, project); notifyConflict(oldMergeRequest, mergeRequest, project);
notifyUpdate(oldMergeRequest, mergeRequest, project);
return mergeRequestRepository.save(mergeRequest); 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) { protected void forgottenNotification(MergeRequest mergeRequest) {
// if (LocalDateTime.now().isAfter(mergeRequest.getUpdateDate().plusHours(2L))) { // if (LocalDateTime.now().isAfter(mergeRequest.getUpdateDate().plusHours(2L))) {

View File

@ -13,6 +13,7 @@ import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
@ -22,7 +23,7 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
//@Service @Service
public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> implements NoteService { public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> implements NoteService {
private static final Pattern PATTERN = Pattern.compile("@[\\w]+"); private static final Pattern PATTERN = Pattern.compile("@[\\w]+");

View File

@ -2,19 +2,24 @@ package org.sadtech.bot.gitlab.core.service.parser;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; 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.MergeRequestsService;
import org.sadtech.bot.gitlab.context.service.NoteService;
import org.sadtech.bot.gitlab.context.service.ProjectService; 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.GitlabProperty;
import org.sadtech.bot.gitlab.core.config.properties.InitProperty; import org.sadtech.bot.gitlab.core.config.properties.InitProperty;
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
import org.sadtech.bot.gitlab.sdk.domain.NoteJson; 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.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.core.page.PaginationImpl;
import org.sadtech.haiti.utils.network.HttpParse; import org.sadtech.haiti.utils.network.HttpParse;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT; import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT;
@ -25,7 +30,7 @@ import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
* <p>Поиск новых комментариев и задач.</p> * <p>Поиск новых комментариев и задач.</p>
* <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p> * <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p>
*/ */
//@Component @Component
public class NoteParser { public class NoteParser {
public static final int COUNT = 100; public static final int COUNT = 100;
@ -37,23 +42,27 @@ public class NoteParser {
private final GitlabProperty gitlabProperty; private final GitlabProperty gitlabProperty;
private final InitProperty initProperty; private final InitProperty initProperty;
private final PersonProperty personProperty; private final PersonProperty personProperty;
private final NoteService noteService;
public NoteParser( public NoteParser(
ProjectService projectService, MergeRequestsService mergeRequestsService, ProjectService projectService, MergeRequestsService mergeRequestsService,
ConversionService conversionService, ConversionService conversionService,
GitlabProperty gitlabProperty, GitlabProperty gitlabProperty,
InitProperty initProperty, InitProperty initProperty,
PersonProperty personProperty) { PersonProperty personProperty,
NoteService noteService
) {
this.projectService = projectService; this.projectService = projectService;
this.mergeRequestsService = mergeRequestsService; this.mergeRequestsService = mergeRequestsService;
this.conversionService = conversionService; this.conversionService = conversionService;
this.gitlabProperty = gitlabProperty; this.gitlabProperty = gitlabProperty;
this.initProperty = initProperty; this.initProperty = initProperty;
this.personProperty = personProperty; this.personProperty = personProperty;
this.noteService = noteService;
} }
public void scanNewCommentAndTask() { public void scanNewCommentAndTask() {
int page = 0; int page = 1;
Sheet<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT)); Sheet<MergeRequest> mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(page, COUNT));
while (mergeRequestSheet.hasContent()) { while (mergeRequestSheet.hasContent()) {
@ -68,6 +77,9 @@ public class NoteParser {
.filter(noteJson -> !noteJson.isSystem()) .filter(noteJson -> !noteJson.isSystem())
.collect(Collectors.toList()); .collect(Collectors.toList());
createNewComment(noteJsons);
createNewTask(noteJsons);
} }
mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT)); mergeRequestSheet = mergeRequestsService.getAll(PaginationImpl.of(++page, COUNT));
@ -75,6 +87,28 @@ public class NoteParser {
} }
private void createNewComment(List<NoteJson> noteJsons) {
final List<NoteJson> newJsons = noteJsons.stream()
.filter(json -> json.getType() == null)
.collect(Collectors.toList());
final Set<Long> jsonIds = newJsons.stream()
.map(NoteJson::getId)
.collect(Collectors.toSet());
final ExistsContainer<Note, Long> existsContainer = noteService.existsById(jsonIds);
if (!existsContainer.isAllFound()) {
final List<Note> 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<DataScan> generatingLinksToPossibleComments(@NonNull Long commentId) { // private List<DataScan> generatingLinksToPossibleComments(@NonNull Long commentId) {
// List<DataScan> commentUrls = new ArrayList<>(); // List<DataScan> commentUrls = new ArrayList<>();
// for (int i = 0; i < 5; i++) { // for (int i = 0; i < 5; i++) {