From 0704231d48e135819c86360b10cbe14838e6669a Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 27 Aug 2024 19:26:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=B1=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B5,=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=B0=20=D0=BA=20?= =?UTF-8?q?Gitlab=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bot/gitlab/config/AppConfig.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java index 7372a62..71708fc 100644 --- a/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java +++ b/gitlab-app/src/main/java/dev/struchkov/bot/gitlab/config/AppConfig.java @@ -3,7 +3,10 @@ package dev.struchkov.bot.gitlab.config; import dev.struchkov.bot.gitlab.context.domain.PersonInformation; import dev.struchkov.bot.gitlab.context.prop.AppProperty; import dev.struchkov.bot.gitlab.context.prop.PersonProperty; +import dev.struchkov.godfather.simple.domain.BoxAnswer; +import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.sdk.gitlab.core.GitlabSdkManager; +import dev.struchkov.sdk.gitlab.schema.common.PersonJson; import jakarta.persistence.EntityManagerFactory; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -21,6 +24,8 @@ import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ForkJoinPool; +import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN; + /** * Общий файл настройки всего приложения. * @@ -83,17 +88,28 @@ public class AppConfig { @Bean public PersonInformation personInformation( GitlabSdkManager gitlabSdkManager, - PersonProperty personProperty + PersonProperty personProperty, + TelegramSending telegramSender ) { - return Optional.of(gitlabSdkManager.getAuthPerson()) - .map( - authUser -> PersonInformation.builder() - .id(authUser.getId()) - .username(authUser.getUsername()) - .name(authUser.getName()) - .telegramId(personProperty.getTelegramId()) - .build() - ).orElseThrow(); + final Optional optAuthPerson = gitlabSdkManager.getAuthPerson(); + if (optAuthPerson.isPresent()) { + final PersonJson authUser = optAuthPerson.get(); + return PersonInformation.builder() + .id(authUser.getId()) + .username(authUser.getUsername()) + .name(authUser.getName()) + .telegramId(personProperty.getTelegramId()) + .build(); + } else { + telegramSender.send( + BoxAnswer.builder() + .recipientPersonId(personProperty.getTelegramId()) + .message("\uD83D\uDED1 *Ошибка доступа к GitLab APi* \uD83D\uDED1\n-- -- -- -- -- --\nВозможные причины:\n1. Невалидный токен доступа.\n2. Для доступа к GitLab нужно включить VPN.") + .payload(ENABLE_MARKDOWN) + .build() + ); + throw new RuntimeException("Ошибка доступа к GitLab APi."); + } } }