From 82a730c61683dce15b3a001ab2940d7b9de41eed Mon Sep 17 00:00:00 2001 From: uPagge Date: Sat, 13 Feb 2021 01:16:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=87=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D1=81=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/scheduler/SchedulerService.java | 1 + bot-app/src/main/resources/application.yaml | 3 ++- .../v.1.0.0/2021-01-14-create-tables.xml | 3 --- .../context/domain/entity/Discussion.java | 2 ++ .../gitlab/context/domain/entity/Note.java | 3 +++ .../config/properties/GitlabProperty.java | 2 ++ .../core/service/convert/NoteJsonConvert.java | 1 + .../service/impl/DiscussionServiceImpl.java | 11 +++++---- .../core/service/parser/DiscussionParser.java | 24 +++++++++++++++++++ .../bot/gitlab/sdk/domain/NoteJson.java | 2 +- .../bot/gitlab/telegram/unit/UnitConfig.java | 2 +- 11 files changed, 44 insertions(+), 10 deletions(-) diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java index 8585921..8c10320 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java @@ -36,6 +36,7 @@ public class SchedulerService { @Scheduled(cron = "*/30 * * * * *") public void newDiscussion() { + discussionParser.scanOldDiscussions(); discussionParser.scanNewDiscussion(); } diff --git a/bot-app/src/main/resources/application.yaml b/bot-app/src/main/resources/application.yaml index 744944f..f65c6a5 100644 --- a/bot-app/src/main/resources/application.yaml +++ b/bot-app/src/main/resources/application.yaml @@ -41,4 +41,5 @@ gitlab-bot: url-pipeline: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines/{1,number,#}" url-commit: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/commits?&page=1&per_page=1" url-new-note: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}/notes?body={3}" - url-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,integer}&per_page=100" \ No newline at end of file + url-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,integer}&per_page=100" + url-one-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}" \ No newline at end of file diff --git a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml index 06d4f44..c718ad9 100644 --- a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml +++ b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml @@ -173,9 +173,6 @@ - - - diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Discussion.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Discussion.java index 5d3939a..08d899c 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Discussion.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Discussion.java @@ -8,6 +8,7 @@ import org.sadtech.haiti.context.domain.BasicEntity; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -46,6 +47,7 @@ public class Discussion implements BasicEntity { @OneToMany( mappedBy = "discussion", + fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java index 31518a3..a1e4197 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Note.java @@ -55,6 +55,9 @@ public class Note implements BasicEntity { @Column(name = "web_url") private String webUrl; + @Column(name = "resolvable") + private boolean resolvable; + @Column(name = "resolved") private Boolean resolved; diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java index 7c97064..d967e2f 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java @@ -58,4 +58,6 @@ public class GitlabProperty { private String urlDiscussion; + private String urlOneDiscussion; + } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/NoteJsonConvert.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/NoteJsonConvert.java index 30f6240..e4b6178 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/NoteJsonConvert.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/NoteJsonConvert.java @@ -31,6 +31,7 @@ public class NoteJsonConvert implements Converter { note.setNoteableIid(source.getNoteableIid()); note.setSystem(source.isSystem()); note.setResolved(source.getResolved()); + note.setResolvable(source.isResolvable()); if (source.getResolvedBy() != null) { note.setResolvedBy(personConverter.convert(source.getResolvedBy())); } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/DiscussionServiceImpl.java index fdd72b7..67f81a6 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/DiscussionServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/DiscussionServiceImpl.java @@ -69,10 +69,13 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService noteMap = discussionRepository.findById(discussion.getId()).orElseThrow(() -> new NotFoundException("Дискуссия не найдена")) + final Discussion oldDiscussion = discussionRepository.findById(discussion.getId()).orElseThrow(() -> new NotFoundException("Дискуссия не найдена")); + final Map noteMap = oldDiscussion .getNotes().stream() .collect(Collectors.toMap(Note::getId, note -> note)); + discussion.setMergeRequest(oldDiscussion.getMergeRequest()); + discussion.setResponsible(oldDiscussion.getResponsible()); discussion.getNotes().forEach(note -> updateNote(note, noteMap)); return discussionRepository.save(discussion); @@ -81,9 +84,9 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService noteMap) { if (noteMap.containsKey(note.getId())) { final Note oldNote = noteMap.get(note.getId()); - if (!oldNote.getUpdated().equals(note.getUpdated())) { - note.setWebUrl(oldNote.getWebUrl()); - } + note.setWebUrl(oldNote.getWebUrl()); + } else { + notificationPersonal(note); } } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/DiscussionParser.java index 2d9d3ea..616513a 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/DiscussionParser.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/parser/DiscussionParser.java @@ -9,6 +9,7 @@ import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.sdk.domain.DiscussionJson; import org.sadtech.haiti.context.domain.ExistsContainer; +import org.sadtech.haiti.context.exception.ConvertException; import org.sadtech.haiti.context.page.Sheet; import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.utils.network.HttpParse; @@ -104,4 +105,27 @@ public class DiscussionParser { .executeList(DiscussionJson.class); } + public void scanOldDiscussions() { + int page = 0; + Sheet discussionSheet = discussionService.getAll(PaginationImpl.of(page, 100)); + + while (discussionSheet.hasContent()) { + final List 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); + } + + discussionSheet = discussionService.getAll(PaginationImpl.of(++page, 100)); + } + + + } + } diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/NoteJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/NoteJson.java index 16d3ebc..0a8f3ec 100644 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/NoteJson.java +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/NoteJson.java @@ -35,7 +35,7 @@ public class NoteJson { @JsonProperty("noteable_type") private String noteableType; - private Boolean resolvable; + private boolean resolvable; private Boolean resolved; diff --git a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java index 4c7d014..8a38070 100644 --- a/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java +++ b/telegram-bot/src/main/java/org/sadtech/bot/gitlab/telegram/unit/UnitConfig.java @@ -95,7 +95,7 @@ public class UnitConfig { final String discussionId = note.getDiscussion().getId(); discussionService.answer(discussionId, MessageFormat.format("@{0}, {1}", note.getAuthor().getUserName(), message.getText())); } - return BoxAnswer.of("Победа"); + return BoxAnswer.of(""); } } return BoxAnswer.of("Ошибка");