From a611e46479f4fa85afb9ee8e96e4b8e3e4eb320e Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 20 Dec 2022 22:19:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=D0=B0=20=D0=B4=D0=B8=D1=81=D0=BA=D1=83=D1=81=D1=81=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/service/parser/DiscussionParser.java | 26 ++++++++++--------- .../GetAllDiscussionForMergeRequestTask.java | 2 +- .../GetAllMergeRequestForProjectTask.java | 2 +- .../parser/forktask/GetPipelineShortTask.java | 2 +- gitlab-app/src/main/resources/application.yml | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java index 346f92e..14eb805 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/DiscussionParser.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static dev.struchkov.bot.gitlab.core.utils.StringUtils.H_PRIVATE_TOKEN; +import static dev.struchkov.haiti.utils.Checker.checkFalse; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; @@ -42,6 +43,8 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT; @Component public class DiscussionParser { + public static final int PAGE_COUNT = 100; + private final DiscussionService discussionService; private final MergeRequestsService mergeRequestsService; @@ -75,22 +78,20 @@ public class DiscussionParser { log.debug("Старт обработки новых дискуссий"); final List mergeRequests = mergeRequestsService.getAllForDiscussion(); - for (MergeRequestForDiscussion mergeRequest : mergeRequests) { - processingMergeRequest(mergeRequest); - } + mergeRequests.forEach(this::processingNewDiscussion); log.debug("Конец обработки новых дискуссий"); } - private void processingMergeRequest(MergeRequestForDiscussion mergeRequest) { + private void processingNewDiscussion(MergeRequestForDiscussion mergeRequest) { int page = 1; - List discussionJson = getDiscussionJson(mergeRequest, page); - - while (!discussionJson.isEmpty()) { + final List discussionJson = getDiscussionJson(mergeRequest, page); + if (checkNotEmpty(discussionJson)) { + while (discussionJson.size() == PAGE_COUNT) { + discussionJson.addAll(getDiscussionJson(mergeRequest, ++page)); + } createNewDiscussion(discussionJson, mergeRequest); - - discussionJson = getDiscussionJson(mergeRequest, ++page); } } @@ -100,9 +101,10 @@ public class DiscussionParser { .collect(Collectors.toUnmodifiableSet()); final ExistContainer existContainer = discussionService.existsById(discussionIds); - if (!existContainer.isAllFound()) { + final Set notFoundIds = existContainer.getIdNoFound(); + if (checkFalse(existContainer.isAllFound())) { final List newDiscussions = discussionJson.stream() - .filter(json -> existContainer.getIdNoFound().contains(json.getId())) + .filter(json -> notFoundIds.contains(json.getId())) .map(json -> { final Discussion discussion = conversionService.convert(json, Discussion.class); discussion.setMergeRequest(mergeRequest); @@ -201,7 +203,7 @@ public class DiscussionParser { } private List getDiscussionJson(MergeRequestForDiscussion mergeRequest, int page) { - return HttpParse.request(MessageFormat.format(gitlabProperty.getDiscussionsUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId(), page)) + return HttpParse.request(MessageFormat.format(gitlabProperty.getDiscussionsUrl(), mergeRequest.getProjectId(), mergeRequest.getTwoId(), page, PAGE_COUNT)) .header(ACCEPT) .header(H_PRIVATE_TOKEN, personProperty.getToken()) .executeList(DiscussionJson.class); diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetAllDiscussionForMergeRequestTask.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetAllDiscussionForMergeRequestTask.java index 660a73d..d821542 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetAllDiscussionForMergeRequestTask.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/forktask/GetAllDiscussionForMergeRequestTask.java @@ -24,7 +24,7 @@ public class GetAllDiscussionForMergeRequestTask extends RecursiveTask> private final String urlPipelines; private final long projectId; - private int pageNumber = 0; + private int pageNumber = 1; private final LocalDateTime lastUpdate; private final String gitlabToken; diff --git a/gitlab-app/src/main/resources/application.yml b/gitlab-app/src/main/resources/application.yml index b69a3cd..f0a2367 100644 --- a/gitlab-app/src/main/resources/application.yml +++ b/gitlab-app/src/main/resources/application.yml @@ -49,5 +49,5 @@ gitlab-bot: pipeline-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines/{1,number,#}" last-commit-of-merge-request-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/commits?&page=1&per_page=1" new-note-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}/notes?body={3}" - discussions-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,#}&per_page=100" + discussions-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,#}&per_page={3,number,#}" discussion-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions/{2}" \ No newline at end of file