фиксация
This commit is contained in:
parent
dcd91b8c01
commit
3df376d0f1
@ -24,34 +24,14 @@ public class SchedulerService {
|
||||
private final CleanService cleanService;
|
||||
private final DiscussionParser discussionParser;
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
@Scheduled(cron = "0 */1 * * * *")
|
||||
public void newMergeRequest() {
|
||||
mergeRequestParser.parsingNewMergeRequest();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void oldMergeRequest() {
|
||||
mergeRequestParser.parsingOldMergeRequest();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newDiscussion() {
|
||||
mergeRequestParser.parsingNewMergeRequest();
|
||||
pipelineParser.scanOldPipeline();
|
||||
pipelineParser.scanNewPipeline();
|
||||
discussionParser.scanOldDiscussions();
|
||||
discussionParser.scanNewDiscussion();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void newPipeline() {
|
||||
pipelineParser.scanNewPipeline();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "*/30 * * * * *")
|
||||
public void oldPipeline() {
|
||||
pipelineParser.scanOldPipeline();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 */1 * * * *")
|
||||
public void clean() {
|
||||
cleanService.cleanOldPipelines();
|
||||
cleanService.cleanMergedPullRequests();
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
@ -13,6 +15,8 @@ import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||
*/
|
||||
public interface NoteRepository extends SimpleManagerRepository<Note, Long> {
|
||||
|
||||
List<Note> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved);
|
||||
|
||||
Sheet<Note> findAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -6,8 +6,12 @@ import org.sadtech.haiti.context.page.Pagination;
|
||||
import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NoteService extends SimpleManagerService<Note, Long> {
|
||||
|
||||
List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved);
|
||||
|
||||
Sheet<Note> getAllByResolved(boolean resolved, @NonNull Pagination pagination);
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.sadtech.bot.gitlab.context.domain.entity.Discussion;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.Note;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.comment.CommentNotify;
|
||||
import org.sadtech.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
|
||||
import org.sadtech.bot.gitlab.context.repository.DiscussionRepository;
|
||||
import org.sadtech.bot.gitlab.context.service.DiscussionService;
|
||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||
@ -85,11 +86,35 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
|
||||
if (noteMap.containsKey(note.getId())) {
|
||||
final Note oldNote = noteMap.get(note.getId());
|
||||
note.setWebUrl(oldNote.getWebUrl());
|
||||
|
||||
if (note.isResolvable()) {
|
||||
updateTask(note, oldNote);
|
||||
}
|
||||
|
||||
} else {
|
||||
notificationPersonal(note);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTask(Note note, Note oldNote) {
|
||||
if (isResolved(note, oldNote)) {
|
||||
notifyService.send(
|
||||
TaskCloseNotify.builder()
|
||||
.authorName(oldNote.getAuthor().getName())
|
||||
.messageTask(oldNote.getBody())
|
||||
.url(oldNote.getWebUrl())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isResolved(Note note, Note oldNote) {
|
||||
return oldNote.getResolvedBy() == null
|
||||
&& note.getResolvedBy() != null
|
||||
&& personInformation.getId().equals(oldNote.getAuthor().getId())
|
||||
&& !note.getResolvedBy().getId().equals(oldNote.getAuthor().getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void answer(@NonNull String discussionId, @NonNull String text) {
|
||||
|
@ -10,6 +10,8 @@ import org.sadtech.haiti.context.page.Sheet;
|
||||
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> implements NoteService {
|
||||
@ -37,4 +39,9 @@ public class NoteServiceImpl extends AbstractSimpleManagerService<Note, Long> im
|
||||
return noteRepository.findAllByResolved(resolved, pagination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> getAllPersonTask(@NonNull Long userId, boolean resolved) {
|
||||
return noteRepository.findAllByResponsibleIdAndResolved(userId, resolved);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -113,13 +113,17 @@ public class DiscussionParser {
|
||||
final List<Discussion> discussions = discussionSheet.getContent();
|
||||
|
||||
for (Discussion discussion : discussions) {
|
||||
final Discussion newDiscussion = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlOneDiscussion(), discussion.getMergeRequest().getProjectId(), discussion.getMergeRequest().getTwoId(), discussion.getId()))
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(DiscussionJson.class)
|
||||
.map(json -> conversionService.convert(json, Discussion.class))
|
||||
.orElseThrow(() -> new ConvertException("Ошибка парсинга дискуссии"));
|
||||
discussionService.update(newDiscussion);
|
||||
if (discussion.getMergeRequest() != null) {
|
||||
final Discussion newDiscussion = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlOneDiscussion(), discussion.getMergeRequest().getProjectId(), discussion.getMergeRequest().getTwoId(), discussion.getId()))
|
||||
.header(ACCEPT)
|
||||
.header(AUTHORIZATION, BEARER + personProperty.getToken())
|
||||
.execute(DiscussionJson.class)
|
||||
.map(json -> conversionService.convert(json, Discussion.class))
|
||||
.orElseThrow(() -> new ConvertException("Ошибка парсинга дискуссии"));
|
||||
discussionService.update(newDiscussion);
|
||||
} else {
|
||||
discussionService.deleteById(discussion.getId());
|
||||
}
|
||||
}
|
||||
|
||||
discussionSheet = discussionService.getAll(PaginationImpl.of(++page, 100));
|
||||
|
@ -10,6 +10,8 @@ import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerReposi
|
||||
import org.sadtech.haiti.database.util.Converter;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* // TODO: 08.09.2020 Добавить описание.
|
||||
*
|
||||
@ -32,4 +34,10 @@ public class NoteRepositoryImpl extends AbstractSimpleManagerRepository<Note, Lo
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Note> findAllByResponsibleIdAndResolved(@NonNull Long userId, boolean resolved) {
|
||||
return repositoryJpa.findAllByDiscussionResponsibleIdAndResolved(userId, resolved);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,12 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NoteRepositoryJpa extends JpaRepository<Note, Long> {
|
||||
|
||||
Page<Note> findAllByResolved(boolean resolved, Pageable pageable);
|
||||
|
||||
List<Note> findAllByDiscussionResponsibleIdAndResolved(Long responsibleId, boolean resolved);
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
|
||||
import org.sadtech.bot.gitlab.context.service.AppSettingService;
|
||||
import org.sadtech.bot.gitlab.context.service.DiscussionService;
|
||||
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
|
||||
import org.sadtech.bot.gitlab.context.service.NoteService;
|
||||
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;
|
||||
@ -129,36 +129,27 @@ public class MenuConfig {
|
||||
|
||||
@Bean
|
||||
public AnswerText getTasks(
|
||||
DiscussionService discussionService,
|
||||
AppSettingService settingService,
|
||||
PersonInformation personInformation
|
||||
PersonInformation personInformation,
|
||||
NoteService noteService
|
||||
) {
|
||||
return AnswerText.builder()
|
||||
.boxAnswer(message ->
|
||||
{
|
||||
final Long userId = personInformation.getId();
|
||||
final String text = "test";
|
||||
// taskService.getAllPersonTask(userId, false).stream()
|
||||
// .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"));
|
||||
final String text = noteService.getAllPersonTask(userId, false).stream()
|
||||
.map(note -> MessageFormat.format("- [{0}]({1})", trim(note.getBody()).replace("\n", " "), note.getWebUrl()))
|
||||
.collect(Collectors.joining("\n"));
|
||||
return BoxAnswer.of("".equals(text) ? settingService.getMessage("ui.answer.no_task") : text);
|
||||
})
|
||||
.phrase(settingService.getMessage("ui.menu.task"))
|
||||
.build();
|
||||
}
|
||||
|
||||
private String trim(String body) {
|
||||
return body.length() > 31 ? body.substring(0, 30) : body;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AnswerText getAssigneeMergeRequest(
|
||||
MergeRequestsService mergeRequestsService,
|
||||
|
@ -62,7 +62,7 @@ public class UnitConfig {
|
||||
message -> {
|
||||
Mail mail = (Mail) message;
|
||||
final List<Mail> forwardMails = mail.getForwardMail();
|
||||
if (forwardMails.size() == 1) {
|
||||
if (forwardMails != null && forwardMails.size() == 1) {
|
||||
final Mail forwardMail = forwardMails.get(0);
|
||||
return forwardMail.getAttachments().stream()
|
||||
.anyMatch(attachment -> AttachmentType.LINK.equals(attachment.getType()));
|
||||
|
Loading…
Reference in New Issue
Block a user