Рабочая версия

This commit is contained in:
upagge 2020-09-18 08:34:55 +03:00
parent 23da158ba9
commit 8b0fadc1f7
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
46 changed files with 322 additions and 65 deletions

View File

@ -59,6 +59,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>bitbucketbot</finalName>
</configuration>
</plugin>
</plugins>
</build>

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket;
package org.sadtech.bot.vcs.bitbucket.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.exception;
package org.sadtech.bot.vcs.bitbucket.app.exception;
/**
* // TODO: 16.09.2020 Добавить описание.

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.exception;
package org.sadtech.bot.vcs.bitbucket.app.exception;
/**
* // TODO: 16.09.2020 Добавить описание.

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.bitbucket.scheduler;
package org.sadtech.bot.vcs.bitbucket.app.scheduler;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.service.CommentAndTaskParser;
import org.sadtech.bot.vcs.bitbucket.app.service.CommentAndTaskParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.bitbucket.scheduler;
package org.sadtech.bot.vcs.bitbucket.app.scheduler;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.service.parser.PersonBitbucketParser;
import org.sadtech.bot.vcs.bitbucket.app.service.parser.PersonBitbucketParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.scheduler;
package org.sadtech.bot.vcs.bitbucket.app.scheduler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,12 +1,12 @@
package org.sadtech.bot.vcs.bitbucket.service;
package org.sadtech.bot.vcs.bitbucket.app.service;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.sadtech.basic.context.page.Sheet;
import org.sadtech.basic.core.page.PaginationImpl;
import org.sadtech.bot.vcs.bitbucket.app.service.executor.DataScan;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.bitbucket.service.executor.DataScan;
import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.sadtech.bot.vcs.core.config.properties.CommentSchedulerProperty;
import org.sadtech.bot.vcs.core.config.properties.InitProperty;

View File

@ -1,12 +1,12 @@
package org.sadtech.bot.vcs.bitbucket.service;
package org.sadtech.bot.vcs.bitbucket.app.service;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vcs.bitbucket.app.service.executor.DataScan;
import org.sadtech.bot.vcs.bitbucket.app.service.executor.Executor;
import org.sadtech.bot.vcs.bitbucket.app.service.executor.Seeker;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.service.executor.DataScan;
import org.sadtech.bot.vcs.bitbucket.service.executor.Executor;
import org.sadtech.bot.vcs.bitbucket.service.executor.Seeker;
import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.springframework.stereotype.Service;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.converter;
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.bitbucket.service.converter;
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
import org.sadtech.bot.vcs.bitbucket.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.bitbucket.service.converter;
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Outcome;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Properties;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.converter;
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson;
import org.sadtech.bot.vcs.core.domain.entity.Person;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.executor;
package org.sadtech.bot.vcs.bitbucket.app.service.executor;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.executor;
package org.sadtech.bot.vcs.bitbucket.app.service.executor;
import lombok.NonNull;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.executor;
package org.sadtech.bot.vcs.bitbucket.app.service.executor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.executor;
package org.sadtech.bot.vcs.bitbucket.app.service.executor;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.parser;
package org.sadtech.bot.vcs.bitbucket.app.service.parser;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.service.parser;
package org.sadtech.bot.vcs.bitbucket.app.service.parser;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.bitbucket.utils;
package org.sadtech.bot.vcs.bitbucket.app.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

View File

@ -24,12 +24,10 @@ bitbucketbot:
no-comment-count: 20
comment-count: 100
init:
start-comment-id: 7807
use: true
server-send:
url: http://188.225.35.149:8080/api/send
start-comment-id: 7914
use: false
bitbucket:
token: Nzg5NjUyNDQwMzk2OlA+6naQz02+GxOG0Q9li/jnsn7E
token: ${BITBUCKET_ADMIN_TOKEN}
url-pull-request-open: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN
url-pull-request-close: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400
url-pull-request-comment: http://192.168.236.164:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId}

View File

@ -18,18 +18,16 @@ spring:
non_contextual_creation: true
bitbucketbot:
scheduler:
person: 0 */1 * * * *
person: 0 0 0 */1 * *
comment:
settings:
no-comment-count: 20
comment-count: 100
init:
start-comment-id: 7807
use: true
server-send:
url: http://188.225.35.149:8080/api/send
use: false
bitbucket:
token: Nzg5NjUyNDQwMzk2OlA+6naQz02+GxOG0Q9li/jnsn7E
token: ${BITBUCKET_ADMIN_TOKEN}
url-pull-request-open: http://localhost:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN
url-pull-request-close: http://localhost:7990/rest/api/1.0/dashboard/pull-requests?limit=150&closedSince=86400
url-pull-request-comment: http://localhost:7990/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/comments/{commentId}

View File

@ -1,5 +1,5 @@
server:
port: 8018
telegram-config:
bot-username: tsc_test_two_bot
bot-token: 1304335862:AAFXGxRkTZBiL9Gjce_oFoP2cOn7j8qEwDI
bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: ${TELEGRAM_BOT_TOKEN}

View File

@ -18,7 +18,7 @@
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>

View File

@ -10,11 +10,11 @@ import lombok.Getter;
@Getter
public enum ReviewerStatus {
NEEDS_WORK("'NEEDS WORK'"),
APPROVED("'APPROVED'"),
UNAPPROVED("'UNAPPROVED'");
NEEDS_WORK("NEEDS WORK"),
APPROVED("APPROVED"),
UNAPPROVED("UNAPPROVED");
private String value;
private final String value;
ReviewerStatus(String value) {
this.value = value;

View File

@ -31,12 +31,10 @@ public class NewPrChange extends PrChange {
@Override
public String generateMessage() {
return MessageFormat.format(
"{0} *Новый Pull Request*\n" +
"[{1}]({2})" +
"{3}\n" +
"{4}" +
"{5}: {6}\n\n",
Smile.FUN, title, url, Smile.HR,
"{0} *Новый Pull Request*{1}" +
"[{2}]({3})" +
"{4}{5}{6}: {7}\n\n",
Smile.FUN, Smile.HR, title, url, Smile.HR,
(description != null && !"".equals(description)) ? description + Smile.HR : "",
Smile.AUTHOR, author
);

View File

@ -33,9 +33,9 @@ public class StatusPrChange extends PrChange {
public String generateMessage() {
return MessageFormat.format(
"{0} *Изменился статус вашего ПР*{1}" +
"[{2}]({3})\n" +
"{4} -> {5}\n\n",
Smile.PEN, Smile.HR, title, url, oldStatus.name(), newStatus.name()
"[{2}]({3}){4}" +
"{5} -> {6}\n\n",
Smile.PEN, Smile.HR, title, url, Smile.HR, oldStatus.name(), newStatus.name()
);
}

View File

@ -28,4 +28,6 @@ public interface PersonRepository {
Optional<Person> findByLogin(@NonNull String login);
Optional<Person> findByTelegramId(@NonNull Long telegramId);
}

View File

@ -1,6 +1,8 @@
package org.sadtech.bot.vcs.core.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import java.time.LocalDateTime;
@ -13,4 +15,6 @@ public interface TaskRepository extends SimpleManagerRepository<Task, Long> {
List<Task> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo);
List<Task> findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status);
}

View File

@ -71,4 +71,9 @@ public class PersonRepositoryImpl implements PersonRepository {
return jpaRepository.findById(login);
}
@Override
public Optional<Person> findByTelegramId(@NonNull Long telegramId) {
return jpaRepository.findByTelegramId(telegramId);
}
}

View File

@ -1,6 +1,8 @@
package org.sadtech.bot.vcs.core.repository.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.repository.TaskRepository;
import org.sadtech.bot.vcs.core.repository.jpa.TaskRepositoryJpa;
@ -30,4 +32,9 @@ public class TaskRepositoryImpl extends AbstractSimpleManagerRepository<Task, Lo
return taskRepositoryJpa.findByCreateDateBetween(dateFrom, dateTo);
}
@Override
public List<Task> findAllByResponsibleAndStatus(@NonNull String responsibleLogin, @NonNull TaskStatus status) {
return taskRepositoryJpa.findAllByResponsibleAndStatus(responsibleLogin, status);
}
}

View File

@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
import java.util.Set;
/**
@ -28,4 +29,6 @@ public interface PersonJpaRepository extends JpaRepository<Person, String> {
@Query("SELECT u.telegramId FROM Person u WHERE u.login IN :logins AND u.telegramId IS NOT NULL")
Set<Long> findAllTelegramIdByLogin(Set<String> logins);
Optional<Person> findByTelegramId(Long telegramId);
}

View File

@ -1,6 +1,7 @@
package org.sadtech.bot.vcs.core.repository.jpa;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository;
@ -14,4 +15,6 @@ public interface TaskRepositoryJpa extends JpaRepository<Task, Long> {
List<Task> findByCreateDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
List<Task> findAllByResponsibleAndStatus(String login, TaskStatus taskStatus);
}

View File

@ -28,4 +28,8 @@ public interface PersonService {
List<Person> createAll(Collection<Person> newUsers);
boolean existsByTelegram(Long telegramId);
Optional<Person> getByTelegramId(@NonNull Long telegramId);
}

View File

@ -16,7 +16,13 @@ import java.util.Set;
public interface PullRequestsService extends SimpleManagerService<PullRequest, Long>, FilterService<PullRequest, PullRequestFilter> {
@NonNull
/**
* Получить все пулреквесты ревьювера с определенным статусом.
*
* @param login Логин ревьювера
* @param reviewerStatus Статус ревьювера в ПР
* @param pullRequestStatuses Статус ПР
*/
List<PullRequest> getAllByReviewerAndStatuses(@NonNull String login, @NonNull ReviewerStatus reviewerStatus, @NonNull Set<PullRequestStatus> pullRequestStatuses);
List<PullRequest> getAllByAuthorAndReviewerStatus(@NonNull String login, @NonNull ReviewerStatus status);

View File

@ -2,6 +2,7 @@ package org.sadtech.bot.vcs.core.service;
import lombok.NonNull;
import org.sadtech.basic.context.service.SimpleManagerService;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.domain.entity.Task;
@ -16,4 +17,6 @@ public interface TaskService extends SimpleManagerService<Task, Long> {
List<Task> getAllBetweenDate(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
List<Task> getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus open);
}

View File

@ -89,4 +89,14 @@ public class PersonServiceImpl implements PersonService {
return newPersons.stream().map(this::create).collect(Collectors.toList());
}
@Override
public boolean existsByTelegram(Long telegramId) {
return personRepository.existsByTelegramId(telegramId);
}
@Override
public Optional<Person> getByTelegramId(@NonNull Long telegramId) {
return personRepository.findByTelegramId(telegramId);
}
}

View File

@ -169,6 +169,11 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
return taskRepository.findByCreateDateBetween(dateFrom, dateTo);
}
@Override
public List<Task> getAllByResponsibleAndStatus(@NonNull String login, @NonNull TaskStatus status) {
return taskRepository.findAllByResponsibleAndStatus(login, status);
}
private void notifyNewTask(Task task) {
final PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId())
.orElseThrow(() -> new NotFoundException("ПР не найден"));

View File

@ -26,7 +26,7 @@ public enum Smile {
DAY_3("\uD83C\uDF18"),
DAY_4("\uD83C\uDF11"),
DAY_5("\uD83C\uDF1A"),
TASK("\uD83E\uDD39\uD83C\uDFFB\u200D♂"),
TASK("\uD83D\uDCBC"),
MEGA_FUN("\uD83D\uDE02"),
DANGEROUS("⚠️"),
BELL("\uD83D\uDECE"),

View File

@ -2,7 +2,8 @@ package org.sadtech.bot.vcs.telegram.config;
import org.sadtech.autoresponder.repository.UnitPointerRepository;
import org.sadtech.autoresponder.repository.UnitPointerRepositoryMap;
import org.sadtech.social.bot.domain.unit.AnswerProcessing;
import org.sadtech.bot.vcs.telegram.service.ReplaceUrlLocalhost;
import org.sadtech.social.bot.domain.unit.AnswerCheck;
import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.impl.local.MailRepositoryList;
import org.sadtech.social.core.service.MailService;
@ -43,13 +44,13 @@ public class TelegramBotConfig {
@Bean
public MessageAutoresponderTelegram messageAutoresponderTelegram(
AnswerProcessing<Mail> menu,
AnswerCheck regCheck,
Sending sending,
MessageService<Mail> messageService,
UnitPointerRepository unitPointerRepository
) {
return new MessageAutoresponderTelegram(
Collections.singleton(menu),
Collections.singleton(regCheck),
sending,
messageService,
unitPointerRepository
@ -57,8 +58,13 @@ public class TelegramBotConfig {
}
@Bean
public Sending sending(TelegramConnect telegramConnect) {
return new TelegramSender(telegramConnect);
public Sending sending(
TelegramConnect telegramConnect,
ReplaceUrlLocalhost replaceUrlLocalhost
) {
final TelegramSender telegramSender = new TelegramSender(telegramConnect);
telegramSender.setSendPreProcessing(replaceUrlLocalhost);
return telegramSender;
}
@Bean

View File

@ -6,7 +6,6 @@ import org.sadtech.bot.vcs.core.domain.MessageSend;
import org.sadtech.bot.vcs.core.service.MessageSendService;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.service.sender.Sending;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
/**
@ -14,7 +13,7 @@ import org.springframework.stereotype.Service;
*
* @author upagge 17.09.2020
*/
@Profile("prod")
//@Profile("prod")
@Service
@RequiredArgsConstructor
public class MessageSendTelegramService implements MessageSendService {

View File

@ -4,14 +4,13 @@ import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.MessageSend;
import org.sadtech.bot.vcs.core.service.MessageSendService;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
/**
* // TODO: 17.09.2020 Добавить описание.
*
* @author upagge 17.09.2020
*/
@Service
//@Service
@Profile("dev")
public class MessageSendTestService implements MessageSendService {

View File

@ -0,0 +1,19 @@
package org.sadtech.bot.vcs.telegram.service;
import org.sadtech.telegram.bot.service.SendPreProcessing;
import org.springframework.stereotype.Component;
/**
* // TODO: 18.09.2020 Добавить описание.
*
* @author upagge 18.09.2020
*/
@Component
public class ReplaceUrlLocalhost implements SendPreProcessing {
@Override
public String pretreatment(String s) {
return s.replace("localhost", "192.168.236.164");
}
}

View File

@ -0,0 +1,62 @@
package org.sadtech.bot.vcs.telegram.service.unit;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.exception.NotFoundException;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.core.service.PullRequestsService;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.social.bot.service.usercode.ProcessingData;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* // TODO: 17.09.2020 Добавить описание.
*
* @author upagge 17.09.2020
*/
@Component
@RequiredArgsConstructor
public class PullRequestProcessing implements ProcessingData<Message> {
private final PersonService personService;
private final PullRequestsService pullRequestsService;
@Override
public BoxAnswer processing(Message message) {
final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Пользователь не найден"));
final List<PullRequest> pullRequests = pullRequestsService.getAllByReviewerAndStatuses(person.getLogin(), ReviewerStatus.NEEDS_WORK, Collections.singleton(PullRequestStatus.OPEN));
String messageAnswer;
if (pullRequests.isEmpty()) {
messageAnswer = "Все ПР проверены :)";
} else {
final String prAnswer = pullRequests.stream()
.map(this::convert)
.collect(Collectors.joining("\n"));
messageAnswer = MessageFormat.format(
"Вам необходимо посмотреть следующие ПР:{0}{1}",
Smile.HR, prAnswer
);
}
return BoxAnswer.of(messageAnswer);
}
private String convert(PullRequest pullRequest) {
return MessageFormat.format(
"- [{0}]({1})",
pullRequest.getTitle(),
pullRequest.getUrl()
);
}
}

View File

@ -0,0 +1,58 @@
package org.sadtech.bot.vcs.telegram.service.unit;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.exception.NotFoundException;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.core.service.TaskService;
import org.sadtech.social.bot.service.usercode.ProcessingData;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Message;
import org.springframework.stereotype.Component;
import java.text.MessageFormat;
import java.util.List;
import java.util.stream.Collectors;
/**
* // TODO: 17.09.2020 Добавить описание.
*
* @author upagge 17.09.2020
*/
@Component
@RequiredArgsConstructor
public class TaskProcessing implements ProcessingData<Message> {
private final PersonService personService;
private final TaskService taskService;
@Override
public BoxAnswer processing(Message message) {
final Person person = personService.getByTelegramId(message.getPersonId())
.orElseThrow(() -> new NotFoundException("Ошибочка"));
final List<Task> tasks = taskService.getAllByResponsibleAndStatus(person.getLogin(), TaskStatus.OPEN);
String messageText;
if (tasks.isEmpty()) {
messageText = "Задач нет";
} else {
final String tasksString = tasks.stream()
.map(this::createTaskString)
.collect(Collectors.joining("\n"));
messageText = MessageFormat.format(
"Список ваших задач:\n\n{0}",
tasksString
);
}
return BoxAnswer.of(messageText);
}
private String createTaskString(Task task) {
return MessageFormat.format(
"- [{0}]({1})",
task.getDescription(), task.getUrl()
);
}
}

View File

@ -1,8 +1,16 @@
package org.sadtech.bot.vcs.telegram.unit;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.telegram.service.unit.PullRequestProcessing;
import org.sadtech.bot.vcs.telegram.service.unit.TaskProcessing;
import org.sadtech.social.bot.domain.unit.AnswerCheck;
import org.sadtech.social.bot.domain.unit.AnswerProcessing;
import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.domain.content.Message;
import org.sadtech.social.core.utils.KeyBoards;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -12,10 +20,67 @@ import org.springframework.context.annotation.Configuration;
* @author upagge [30.01.2020]
*/
@Configuration
@RequiredArgsConstructor
public class UnitConfig {
private final PersonService personService;
@Bean
public AnswerProcessing<Mail> menu() {
public AnswerCheck regCheck(
AnswerProcessing<Mail> noRegister,
AnswerText menu
) {
return AnswerCheck.builder()
.check(
message -> personService.existsByTelegram(message.getPersonId())
)
.unitFalse(noRegister)
.unitTrue(menu)
.build();
}
@Bean
public AnswerText menu(
AnswerProcessing<Message> getTasks,
AnswerProcessing<Message> getPr
) {
return AnswerText.builder()
.boxAnswer(
BoxAnswer.builder()
.message("Привет, выбери пункт меню!")
.keyBoard(KeyBoards.verticalMenuString(
"Мои задачи", "Проверить ПР"
))
.build()
)
.nextUnit(getTasks)
.nextUnit(getPr)
.build();
}
@Bean
public AnswerProcessing<Message> getTasks(
TaskProcessing taskProcessing
) {
return AnswerProcessing.builder()
.processingData(taskProcessing)
.phrase("Мои задачи")
.build();
}
@Bean
public AnswerProcessing<Message> getPr(
PullRequestProcessing pullRequestProcessing
) {
return AnswerProcessing.builder()
.processingData(pullRequestProcessing)
.phrase("Проверить ПР")
.build();
}
@Bean
public AnswerProcessing<Mail> noRegister() {
return AnswerProcessing.<Mail>builder()
.processingData(message ->
BoxAnswer.builder()