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

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> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>bitbucketbot</finalName>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </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.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; 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 Добавить описание. * // 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 Добавить описание. * // 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 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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; 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 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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; 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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; 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.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.sadtech.basic.context.page.Sheet; import org.sadtech.basic.context.page.Sheet;
import org.sadtech.basic.core.page.PaginationImpl; 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.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; 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.BitbucketProperty;
import org.sadtech.bot.vcs.core.config.properties.CommentSchedulerProperty; import org.sadtech.bot.vcs.core.config.properties.CommentSchedulerProperty;
import org.sadtech.bot.vcs.core.config.properties.InitProperty; 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.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; 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.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.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.springframework.stereotype.Service; 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; 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.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; 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 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.Outcome;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Properties; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Properties;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson; 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.bitbucket.sdk.domain.UserJson;
import org.sadtech.bot.vcs.core.domain.entity.Person; 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; 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; 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.Getter;
import lombok.RequiredArgsConstructor; 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 lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; 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 lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson; 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.NonNull;
import lombok.RequiredArgsConstructor; 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.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -24,12 +24,10 @@ bitbucketbot:
no-comment-count: 20 no-comment-count: 20
comment-count: 100 comment-count: 100
init: init:
start-comment-id: 7807 start-comment-id: 7914
use: true use: false
server-send:
url: http://188.225.35.149:8080/api/send
bitbucket: 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-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-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} 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 non_contextual_creation: true
bitbucketbot: bitbucketbot:
scheduler: scheduler:
person: 0 */1 * * * * person: 0 0 0 */1 * *
comment: comment:
settings: settings:
no-comment-count: 20 no-comment-count: 20
comment-count: 100 comment-count: 100
init: init:
start-comment-id: 7807 start-comment-id: 7807
use: true use: false
server-send:
url: http://188.225.35.149:8080/api/send
bitbucket: 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-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-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} 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: server:
port: 8018 port: 8018
telegram-config: telegram-config:
bot-username: tsc_test_two_bot bot-username: ${TELEGRAM_BOT_USERNAME}
bot-token: 1304335862:AAFXGxRkTZBiL9Gjce_oFoP2cOn7j8qEwDI bot-token: ${TELEGRAM_BOT_TOKEN}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,8 @@
package org.sadtech.bot.vcs.core.repository; package org.sadtech.bot.vcs.core.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository; 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 org.sadtech.bot.vcs.core.domain.entity.Task;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -13,4 +15,6 @@ public interface TaskRepository extends SimpleManagerRepository<Task, Long> {
List<Task> findByCreateDateBetween(LocalDateTime dateFrom, LocalDateTime dateTo); 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); 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; package org.sadtech.bot.vcs.core.repository.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository; 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.domain.entity.Task;
import org.sadtech.bot.vcs.core.repository.TaskRepository; import org.sadtech.bot.vcs.core.repository.TaskRepository;
import org.sadtech.bot.vcs.core.repository.jpa.TaskRepositoryJpa; 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); 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 org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; 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") @Query("SELECT u.telegramId FROM Person u WHERE u.login IN :logins AND u.telegramId IS NOT NULL")
Set<Long> findAllTelegramIdByLogin(Set<String> logins); 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; package org.sadtech.bot.vcs.core.repository.jpa;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository; 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> 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); 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> { 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> getAllByReviewerAndStatuses(@NonNull String login, @NonNull ReviewerStatus reviewerStatus, @NonNull Set<PullRequestStatus> pullRequestStatuses);
List<PullRequest> getAllByAuthorAndReviewerStatus(@NonNull String login, @NonNull ReviewerStatus status); 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 lombok.NonNull;
import org.sadtech.basic.context.service.SimpleManagerService; 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.Comment;
import org.sadtech.bot.vcs.core.domain.entity.Task; 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> 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()); 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); 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) { private void notifyNewTask(Task task) {
final PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId()) final PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId())
.orElseThrow(() -> new NotFoundException("ПР не найден")); .orElseThrow(() -> new NotFoundException("ПР не найден"));

View File

@ -26,7 +26,7 @@ public enum Smile {
DAY_3("\uD83C\uDF18"), DAY_3("\uD83C\uDF18"),
DAY_4("\uD83C\uDF11"), DAY_4("\uD83C\uDF11"),
DAY_5("\uD83C\uDF1A"), DAY_5("\uD83C\uDF1A"),
TASK("\uD83E\uDD39\uD83C\uDFFB\u200D♂"), TASK("\uD83D\uDCBC"),
MEGA_FUN("\uD83D\uDE02"), MEGA_FUN("\uD83D\uDE02"),
DANGEROUS("⚠️"), DANGEROUS("⚠️"),
BELL("\uD83D\uDECE"), 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.UnitPointerRepository;
import org.sadtech.autoresponder.repository.UnitPointerRepositoryMap; 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.domain.content.Mail;
import org.sadtech.social.core.repository.impl.local.MailRepositoryList; import org.sadtech.social.core.repository.impl.local.MailRepositoryList;
import org.sadtech.social.core.service.MailService; import org.sadtech.social.core.service.MailService;
@ -43,13 +44,13 @@ public class TelegramBotConfig {
@Bean @Bean
public MessageAutoresponderTelegram messageAutoresponderTelegram( public MessageAutoresponderTelegram messageAutoresponderTelegram(
AnswerProcessing<Mail> menu, AnswerCheck regCheck,
Sending sending, Sending sending,
MessageService<Mail> messageService, MessageService<Mail> messageService,
UnitPointerRepository unitPointerRepository UnitPointerRepository unitPointerRepository
) { ) {
return new MessageAutoresponderTelegram( return new MessageAutoresponderTelegram(
Collections.singleton(menu), Collections.singleton(regCheck),
sending, sending,
messageService, messageService,
unitPointerRepository unitPointerRepository
@ -57,8 +58,13 @@ public class TelegramBotConfig {
} }
@Bean @Bean
public Sending sending(TelegramConnect telegramConnect) { public Sending sending(
return new TelegramSender(telegramConnect); TelegramConnect telegramConnect,
ReplaceUrlLocalhost replaceUrlLocalhost
) {
final TelegramSender telegramSender = new TelegramSender(telegramConnect);
telegramSender.setSendPreProcessing(replaceUrlLocalhost);
return telegramSender;
} }
@Bean @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.bot.vcs.core.service.MessageSendService;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.service.sender.Sending; import org.sadtech.social.core.service.sender.Sending;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
@ -14,7 +13,7 @@ import org.springframework.stereotype.Service;
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Profile("prod") //@Profile("prod")
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class MessageSendTelegramService implements MessageSendService { 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.domain.MessageSend;
import org.sadtech.bot.vcs.core.service.MessageSendService; import org.sadtech.bot.vcs.core.service.MessageSendService;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
/** /**
* // TODO: 17.09.2020 Добавить описание. * // TODO: 17.09.2020 Добавить описание.
* *
* @author upagge 17.09.2020 * @author upagge 17.09.2020
*/ */
@Service //@Service
@Profile("dev") @Profile("dev")
public class MessageSendTestService implements MessageSendService { 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; 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.AnswerProcessing;
import org.sadtech.social.bot.domain.unit.AnswerText;
import org.sadtech.social.core.domain.BoxAnswer; import org.sadtech.social.core.domain.BoxAnswer;
import org.sadtech.social.core.domain.content.Mail; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -12,10 +20,67 @@ import org.springframework.context.annotation.Configuration;
* @author upagge [30.01.2020] * @author upagge [30.01.2020]
*/ */
@Configuration @Configuration
@RequiredArgsConstructor
public class UnitConfig { public class UnitConfig {
private final PersonService personService;
@Bean @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() return AnswerProcessing.<Mail>builder()
.processingData(message -> .processingData(message ->
BoxAnswer.builder() BoxAnswer.builder()