Compare commits

..

No commits in common. "bbc9093769ac1366ae1a85bcd87943be9d38d9ef" and "643e79dcaab4b8e9deac58d4113ce2cd6a4e7816" have entirely different histories.

2 changed files with 11 additions and 22 deletions

View File

@ -25,7 +25,6 @@ import java.util.stream.Collectors;
import static dev.struchkov.bot.gitlab.core.utils.HttpParse.ACCEPT; import static dev.struchkov.bot.gitlab.core.utils.HttpParse.ACCEPT;
import static dev.struchkov.haiti.context.exception.ConvertException.convertException; import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
import static java.util.Collections.singleton;
/** /**
* Парсер проектов. * Парсер проектов.
@ -92,15 +91,12 @@ public class ProjectParser {
.header(ACCEPT) .header(ACCEPT)
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken()) .header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(ProjectJson.class) .execute(ProjectJson.class)
.orElseThrow(convertException("Ошибка получения репозитория.")); .orElseThrow(convertException("Ошибка получения проекта"));
if (!projectService.existsById(projectJson.getId())) { if (!projectService.existsById(projectJson.getId())) {
createNewPersons(List.of(projectJson)); createNewPersons(List.of(projectJson));
final Project newProject = conversionService.convert(projectJson, Project.class); final Project newProject = conversionService.convert(projectJson, Project.class);
projectService.create(newProject); projectService.create(newProject);
} else {
projectService.notification(true, singleton(projectJson.getId()));
projectService.processing(true, singleton(projectJson.getId()));
} }
} }

View File

@ -14,9 +14,8 @@ import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Mail; import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.simple.core.unit.AnswerText; import dev.struchkov.godfather.simple.core.unit.AnswerText;
import dev.struchkov.godfather.simple.core.unit.MainUnit; import dev.struchkov.godfather.simple.core.unit.MainUnit;
import dev.struchkov.godfather.telegram.domain.attachment.LinkAttachment; import dev.struchkov.godfather.simple.data.StorylineContext;
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard; import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import dev.struchkov.haiti.utils.Checker; import dev.struchkov.haiti.utils.Checker;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@ -24,7 +23,6 @@ import org.springframework.stereotype.Component;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ACCESS_ERROR; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.ACCESS_ERROR;
@ -35,12 +33,10 @@ import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.GET_TASKS;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.SETTINGS; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.SETTINGS;
import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_ADD_NEW_PROJECT; import static dev.struchkov.bot.gitlab.telegram.utils.UnitName.TEXT_ADD_NEW_PROJECT;
import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.main.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.godfather.main.domain.BoxAnswer.replaceBoxAnswer;
import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton; import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.simpleButton;
import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine; import static dev.struchkov.godfather.main.domain.keyboard.simple.SimpleKeyBoardLine.simpleLine;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.clickButtonRaw; import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.clickButtonRaw;
import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.isLinks;
/** /**
* // TODO: 16.01.2021 Добавить описание. * // TODO: 16.01.2021 Добавить описание.
@ -51,7 +47,9 @@ import static dev.struchkov.godfather.telegram.simple.core.util.TriggerChecks.is
@RequiredArgsConstructor @RequiredArgsConstructor
public class MenuConfig { public class MenuConfig {
private final StorylineContext context;
private final TelegramSending sending; private final TelegramSending sending;
private final ProjectParser projectParser; private final ProjectParser projectParser;
private final GitlabProperty gitlabProperty; private final GitlabProperty gitlabProperty;
private final PersonInformation personInformation; private final PersonInformation personInformation;
@ -59,8 +57,6 @@ public class MenuConfig {
private final MergeRequestsService mergeRequestsService; private final MergeRequestsService mergeRequestsService;
private final AppSettingService settingService; private final AppSettingService settingService;
private final ScheduledExecutorService scheduledExecutorService;
@Unit(value = ACCESS_ERROR, main = true) @Unit(value = ACCESS_ERROR, main = true)
public AnswerText<Mail> accessError() { public AnswerText<Mail> accessError() {
return AnswerText.<Mail>builder() return AnswerText.<Mail>builder()
@ -119,7 +115,7 @@ public class MenuConfig {
) { ) {
return AnswerText.<Mail>builder() return AnswerText.<Mail>builder()
.triggerCheck(clickButtonRaw(TEXT_ADD_NEW_PROJECT)) .triggerCheck(clickButtonRaw(TEXT_ADD_NEW_PROJECT))
.answer(replaceBoxAnswer("Send me links to repositories you want to track")) .answer(boxAnswer("Copy the url of the project and send it to me"))
.next(addNewProject) .next(addNewProject)
.build(); .build();
} }
@ -127,16 +123,13 @@ public class MenuConfig {
@Unit(ADD_NEW_PROJECT) @Unit(ADD_NEW_PROJECT)
public AnswerText<Mail> addNewProject() { public AnswerText<Mail> addNewProject() {
return AnswerText.<Mail>builder() return AnswerText.<Mail>builder()
.triggerCheck(isLinks())
.answer(mail -> { .answer(mail -> {
final List<LinkAttachment> links = Attachments.findAllLinks(mail.getAttachments()); final String mailText = mail.getText();
for (LinkAttachment link : links) { final String projectUrl = gitlabProperty.getProjectAddUrl() + mailText.replace(gitlabProperty.getBaseUrl(), "")
final String projectUrl = gitlabProperty.getProjectAddUrl() + link.getUrl().replace(gitlabProperty.getBaseUrl(), "")
.substring(1) .substring(1)
.replace("/", "%2F"); .replace("/", "%2F");
projectParser.parseByUrl(projectUrl); projectParser.parseByUrl(projectUrl);
} return boxAnswer("Project added successfully");
return boxAnswer("\uD83D\uDC4D Projects added successfully!");
}) })
.build(); .build();
} }