diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java index 02f6c49..bcee415 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/parser/MergeRequestParser.java @@ -12,7 +12,6 @@ import dev.struchkov.bot.gitlab.core.utils.StringUtils; import dev.struchkov.bot.gitlab.sdk.domain.CommitJson; import dev.struchkov.bot.gitlab.sdk.domain.MergeRequestJson; import dev.struchkov.haiti.context.domain.ExistsContainer; -import dev.struchkov.haiti.context.exception.NotFoundException; import dev.struchkov.haiti.context.page.Sheet; import dev.struchkov.haiti.context.page.impl.PaginationImpl; import dev.struchkov.haiti.utils.network.HttpParse; @@ -23,6 +22,7 @@ import org.springframework.stereotype.Service; import java.text.MessageFormat; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -48,17 +48,18 @@ public class MergeRequestParser { final Set existIds = mergeRequestsService.getAllId(OLD_STATUSES); for (IdAndStatusPr existId : existIds) { - final MergeRequest mergeRequest = HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPullRequest(), existId.getProjectId(), existId.getTwoId())) + final String mrUrl = MessageFormat.format(gitlabProperty.getUrlPullRequest(), existId.getProjectId(), existId.getTwoId()); + final Optional json = HttpParse.request(mrUrl) .header(ACCEPT) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) - .execute(MergeRequestJson.class) - .map(json -> { - final MergeRequest newMergeRequest = conversionService.convert(json, MergeRequest.class); + .execute(MergeRequestJson.class); + final Optional mergeRequest = json + .map(mergeRequestJson -> { + final MergeRequest newMergeRequest = conversionService.convert(mergeRequestJson, MergeRequest.class); parsingCommits(newMergeRequest); return newMergeRequest; - }) - .orElseThrow(NotFoundException.supplier("МержРеквест не найден, возможно удален")); - mergeRequestsService.update(mergeRequest); + }); + mergeRequest.ifPresent(mergeRequestsService::update); } } @@ -98,7 +99,6 @@ public class MergeRequestParser { return mergeRequest; }) .toList(); - mergeRequestsService.createAll(newMergeRequests); } diff --git a/gitlab-app/src/main/resources/application.yaml b/gitlab-app/src/main/resources/application.yaml index 4526bc2..c62ea14 100644 --- a/gitlab-app/src/main/resources/application.yaml +++ b/gitlab-app/src/main/resources/application.yaml @@ -32,8 +32,8 @@ gitlab-bot: url-project: ${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100 url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests?state=opened&page={1, number, integer}&per_page=100 url-pull-request-close: ${GITLAB_URL} - url-pull-request-comment: "${GITLAB_URL}/api/v4/projects/{0,number,integer}/merge_requests/{1,number,integer}/notes?&page={2,number,integer}&per_page=100" - url-pull-request: ${GITLAB_URL}/api/v4/projects/{0, number, integer}/merge_requests/{1, number, integer}?page={2, number, integer}&per_page=100 + url-pull-request-comment: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes?&page={2,number,#}&per_page=100" + url-pull-request: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}" url-merge-request-add: ${GITLAB_URL}/api/v4/projects/{0}%2F{1} user-url: ${GITLAB_URL}/api/v4/user users-url: ${GITLAB_URL}/api/v4/users @@ -43,5 +43,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" + url-discussion: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/discussions?&page={2,number,#}&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/pom.xml b/pom.xml index f0db406..50ab930 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 3.1.0 3.1.0 - 0.0.5 + 1.0.0 0.0.2 2.2