diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java index 8304ca2..a7dc402 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/config/AppConfig.java @@ -1,5 +1,10 @@ package org.sadtech.bot.gitlab.app.config; +import org.sadtech.bot.gitlab.context.domain.PersonInformation; +import org.sadtech.bot.gitlab.context.exception.NotFoundException; +import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; +import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; +import org.sadtech.haiti.utils.network.HttpParse; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.ConversionService; @@ -13,6 +18,10 @@ import java.util.Arrays; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import static org.sadtech.haiti.utils.network.HttpParse.ACCEPT; +import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION; +import static org.sadtech.haiti.utils.network.HttpParse.BEARER; + /** * Общий файл настройки всего приложения. * @@ -44,4 +53,18 @@ public class AppConfig { return defaultConversionService; } + @Bean + public PersonInformation personInformation( + PersonProperty personProperty, + GitlabProperty gitlabProperty + ) { + final PersonInformation personInformation = HttpParse.request(gitlabProperty.getUserUrl()) + .header(ACCEPT) + .header(AUTHORIZATION, BEARER + personProperty.getToken()) + .execute(PersonInformation.class) + .orElseThrow(() -> new NotFoundException("Пользователь не найден")); + personInformation.setTelegramId(personProperty.getTelegramId()); + return personInformation; + } + } diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java index cb04621..cc42b15 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/scheduler/SchedulerService.java @@ -2,6 +2,7 @@ package org.sadtech.bot.gitlab.app.scheduler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.sadtech.bot.gitlab.app.service.parser.MergeRequestParser; import org.sadtech.bot.gitlab.app.service.parser.ProjectParser; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -17,15 +18,16 @@ import org.springframework.stereotype.Service; public class SchedulerService { private final ProjectParser projectParser; + private final MergeRequestParser mergeRequestParser; - @Scheduled(cron = "0 */1 * * * *") + @Scheduled(cron = "*/30 * * * * *") public void newProjectParse() { projectParser.parseNewProject(); } - @Scheduled(cron = "0 */1 * * * *") + @Scheduled(cron = "*/30 * * * * *") public void newMergeRequest() { - + mergeRequestParser.parsingNewMergeRequest(); } } diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java index 5ec642e..68b9f88 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/ExecutorScanner.java @@ -7,6 +7,7 @@ import org.sadtech.bot.gitlab.app.service.executor.DataScan; import org.sadtech.bot.gitlab.app.service.executor.Executor; import org.sadtech.bot.gitlab.app.service.executor.Seeker; import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; +import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.sdk.domain.CommentJson; import org.springframework.stereotype.Service; @@ -26,12 +27,13 @@ public class ExecutorScanner implements Executor { private final ExecutorService executorService; private List>> resultList = new ArrayList<>(); private final GitlabProperty gitlabProperty; + private final PersonProperty personProperty; @Override public boolean registration(@NonNull List dataScans) { resultList.addAll( dataScans.stream() - .map(dataScan -> new Seeker(dataScan, gitlabProperty.getToken())) + .map(dataScan -> new Seeker(dataScan, personProperty.getToken())) .map(executorService::submit) .collect(Collectors.toList()) ); diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/convert/MergeRequestJsonConverter.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/convert/MergeRequestJsonConverter.java new file mode 100644 index 0000000..829c949 --- /dev/null +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/convert/MergeRequestJsonConverter.java @@ -0,0 +1,63 @@ +package org.sadtech.bot.gitlab.app.service.convert; + +import org.sadtech.bot.gitlab.context.domain.MergeRequestState; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson; +import org.sadtech.bot.gitlab.sdk.domain.MergeRequestStateJson; +import org.sadtech.bot.gitlab.sdk.domain.PersonJson; +import org.sadtech.haiti.context.exception.ConvertException; +import org.springframework.core.convert.converter.Converter; +import org.springframework.stereotype.Component; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +@Component +public class MergeRequestJsonConverter implements Converter { + + @Override + public MergeRequest convert(MergeRequestJson source) { + final MergeRequest mergeRequest = new MergeRequest(); + mergeRequest.setConflict(source.isConflicts()); + mergeRequest.setTitle(source.getTitle()); + mergeRequest.setCreatedDate(source.getCreatedDate()); + mergeRequest.setDescription(source.getDescription()); + mergeRequest.setId(source.getId()); + mergeRequest.setTwoId(source.getTwoId()); + mergeRequest.setUpdatedDate(source.getUpdatedDate()); + mergeRequest.setState(convertState(source.getState())); + mergeRequest.setProjectId(source.getProjectId()); + mergeRequest.setWebUrl(source.getWebUrl()); + mergeRequest.setLabels(source.getLabels()); + mergeRequest.setAssignee(convertPerson(source.getAssignee())); + mergeRequest.setAuthor(convertPerson(source.getAssignee())); + return mergeRequest; + } + + private Person convertPerson(PersonJson personJson) { + final Person person = new Person(); + person.setId(personJson.getId()); + person.setName(personJson.getName()); + person.setUserName(personJson.getUsername()); + person.setWebUrl(personJson.getWebUrl()); + return person; + } + + private MergeRequestState convertState(MergeRequestStateJson state) { + switch (state) { + case CLOSED: + return MergeRequestState.CLOSED; + case LOCKED: + return MergeRequestState.LOCKED; + case MERGED: + return MergeRequestState.MERGED; + case OPENED: + return MergeRequestState.OPENED; + } + throw new ConvertException("Статус ПР не найден"); + } + +} diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/CommentAndTaskParser.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/CommentAndTaskParser.java index e5aa184..88d53e1 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/CommentAndTaskParser.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/CommentAndTaskParser.java @@ -6,7 +6,7 @@ import org.sadtech.bot.gitlab.app.service.ExecutorScanner; import org.sadtech.bot.gitlab.app.service.executor.DataScan; import org.sadtech.bot.gitlab.context.domain.entity.Comment; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; -import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini; import org.sadtech.bot.gitlab.context.domain.entity.Task; import org.sadtech.bot.gitlab.context.exception.NotFoundException; import org.sadtech.bot.gitlab.context.service.CommentService; @@ -125,10 +125,10 @@ public class CommentAndTaskParser { .map(resultScan -> conversionService.convert(resultScan, Comment.class)) .peek( comment -> { - final PullRequestMini pullRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId()) + final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId()) .orElseThrow(() -> new NotFoundException("Автор ПР не найден")); - comment.setUrl(generateUrl(comment.getId(), pullRequestMini.getUrl())); - comment.setResponsible(pullRequestMini.getAuthorLogin()); + comment.setUrl(generateUrl(comment.getId(), mergeRequestMini.getWebUrl())); +// comment.setResponsible(mergeRequestMini.getAuthor()); } ) .collect(Collectors.toList()); @@ -140,10 +140,10 @@ public class CommentAndTaskParser { .map(resultScan -> conversionService.convert(resultScan, Task.class)) .peek( task -> { - final PullRequestMini pullRequestMini = mergeRequestsService.getMiniInfo(task.getPullRequestId()) + final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(task.getPullRequestId()) .orElseThrow(() -> new NotFoundException("Автор ПР не найден")); - task.setResponsible(pullRequestMini.getAuthorLogin()); - task.setUrl(generateUrl(task.getId(), pullRequestMini.getUrl())); +// task.setResponsible(mergeRequestMini.getAuthorLogin()); + task.setUrl(generateUrl(task.getId(), mergeRequestMini.getWebUrl())); } ) .collect(Collectors.toList()); diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParserImpl.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParser.java similarity index 59% rename from bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParserImpl.java rename to bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParser.java index 43446ac..ec8b415 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParserImpl.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/MergeRequestParser.java @@ -3,13 +3,22 @@ package org.sadtech.bot.gitlab.app.service.parser; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.sadtech.bot.gitlab.context.domain.MergeRequestState; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.sadtech.bot.gitlab.context.domain.entity.Project; import org.sadtech.bot.gitlab.context.service.MergeRequestsService; +import org.sadtech.bot.gitlab.context.service.ProjectService; import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; +import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson; +import org.sadtech.haiti.context.domain.ExistsContainer; +import org.sadtech.haiti.context.page.Sheet; +import org.sadtech.haiti.core.page.PaginationImpl; import org.sadtech.haiti.utils.network.HttpHeader; import org.sadtech.haiti.utils.network.HttpParse; import org.springframework.core.convert.ConversionService; +import org.springframework.stereotype.Service; +import java.text.MessageFormat; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -20,37 +29,63 @@ import static org.sadtech.haiti.utils.network.HttpParse.AUTHORIZATION; import static org.sadtech.haiti.utils.network.HttpParse.BEARER; @Slf4j -//@Service +@Service @RequiredArgsConstructor -public class MergeRequestParserImpl { +public class MergeRequestParser { - private static final Set OLD_STATUSES = Stream.of(MergeRequestState.MERGED, MergeRequestState.OPENED, MergeRequestState.CLOSED).collect(Collectors.toSet()); + + public static final Integer COUNT = 100; + private static final Set OLD_STATUSES = Stream.of( + MergeRequestState.MERGED, MergeRequestState.OPENED, MergeRequestState.CLOSED + ).collect(Collectors.toSet()); private final GitlabProperty gitlabProperty; private final MergeRequestsService mergeRequestsService; + private final ProjectService projectService; private final ConversionService conversionService; + private final PersonProperty personProperty; public void parsingOldPullRequest() { // processingOldPullRequests(gitlabProperty.getUrlPullRequestOpen(), gitlabProperty.getUrlPullRequestClose()); } - public void parsingNewPullRequest() { - final List mergeRequestJsons = HttpParse.request(gitlabProperty.getUrlPullRequestOpen()) - .header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken())) - .header(ACCEPT) - .executeList(MergeRequestJson.class); + public void parsingNewMergeRequest() { + + int page = 0; + + Sheet projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT)); + while (projectSheet.hasContent()) { + final List projects = projectSheet.getContent(); + + for (Project project : projects) { + final List mergeRequestJsons = HttpParse.request( + MessageFormat.format(gitlabProperty.getUrlPullRequestOpen(), project.getId()) + ) + .header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken())) + .header(ACCEPT) + .executeList(MergeRequestJson.class); + + if (!mergeRequestJsons.isEmpty()) { + + final Set jsonIds = mergeRequestJsons.stream() + .map(MergeRequestJson::getId) + .collect(Collectors.toSet()); + + final ExistsContainer existsContainer = mergeRequestsService.existsById(jsonIds); + if (!existsContainer.isAllFound()) { + final List newMergeRequests = mergeRequestJsons.stream() + .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) + .map(json -> conversionService.convert(json, MergeRequest.class)) + .collect(Collectors.toList()); + mergeRequestsService.createAll(newMergeRequests); + } + } + } + + projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT)); + } + -// while (mergeRequestJsons != null && !mergeRequestJsons.isEmpty()) { -// final List newPullRequest = mergeRequestJsons.stream() -// .collect(Collectors.toMap(mergeRequestJson -> new Pair<>(mergeRequestJson.getId(), mergeRequestJson.getFromRef().getRepository().getId()), mergeRequestJson -> mergeRequestJson)) -// .values() -// .stream() -// .filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson))) -// .map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class)) -// .collect(Collectors.toList()); -// -// pullRequestsService.createAll(newPullRequest); -// } } // private Set getExistsPullRequestIds(String bitbucketUrl) { @@ -99,11 +134,5 @@ public class MergeRequestParserImpl { // .collect(Collectors.toList()); // } // -// private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) { -// return PullRequestFilter.builder() -// .bitbucketId(json.getId()) -// .bitbucketRepositoryId(json.getFromRef().getRepository().getId()) -// .build(); -// } } diff --git a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/ProjectParser.java b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/ProjectParser.java index a050fdd..07700ca 100644 --- a/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/ProjectParser.java +++ b/bot-app/src/main/java/org/sadtech/bot/gitlab/app/service/parser/ProjectParser.java @@ -7,6 +7,7 @@ import org.sadtech.bot.gitlab.context.domain.entity.Project; import org.sadtech.bot.gitlab.context.service.ProjectService; import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty; import org.sadtech.bot.gitlab.core.config.properties.InitProperty; +import org.sadtech.bot.gitlab.core.config.properties.PersonProperty; import org.sadtech.bot.gitlab.sdk.domain.ProjectJson; import org.sadtech.haiti.context.domain.ExistsContainer; import org.sadtech.haiti.utils.network.HttpHeader; @@ -38,6 +39,7 @@ public class ProjectParser { private final ConversionService conversionService; private final GitlabProperty gitlabProperty; + private final PersonProperty personProperty; private final CommentSchedulerProperty commentSchedulerProperty; private final InitProperty initProperty; @@ -45,7 +47,7 @@ public class ProjectParser { public void parseNewProject() { final List projectJsons = HttpParse.request(gitlabProperty.getUrlProject()) .header(ACCEPT) - .header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken())) + .header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken())) .executeList(ProjectJson.class); final Set jsonIds = projectJsons.stream() diff --git a/bot-app/src/main/resources/application.yaml b/bot-app/src/main/resources/application.yaml index e9da648..4fcfb57 100644 --- a/bot-app/src/main/resources/application.yaml +++ b/bot-app/src/main/resources/application.yaml @@ -28,15 +28,16 @@ gitlab-bot: settings: no-comment-count: 20 comment-count: 100 - gitlab: + person: + telegram-id: ${TELEGRAM_PERSON_ID} token: ${GITLAB_PERSONAL_TOKEN} - username: ${GITLAB_USERNAME} - full-name: ${GITLAB_FULLNAME} + gitlab: url-project: ${GITLAB_URL}/api/v4/projects url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened url-pull-request-close: ${GITLAB_URL} url-pull-request-comment: ${GITLAB_URL} url-pull-request: ${GITLAB_URL} + user-url: ${GITLAB_URL}/api/v4/user teamcity: token: ${TEAMCITY_ADMIN_TOKEN} project-url: ${TEAMCITY_URL}/app/rest/projects diff --git a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml index 034b1db..717ac7c 100644 --- a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml +++ b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-01-14-create-tables.xml @@ -19,7 +19,7 @@ - + @@ -34,14 +34,15 @@ - + - - + + - + @@ -66,7 +67,28 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/EntityType.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/EntityType.java deleted file mode 100644 index 6a6fc1d..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/EntityType.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sadtech.bot.gitlab.context.domain; - -/** - * // TODO: 21.09.2020 Добавить описание. - * - * @author upagge 21.09.2020 - */ -public enum EntityType { - - CHAT, - PERSON - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/PersonInformation.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/PersonInformation.java new file mode 100644 index 0000000..0c54df6 --- /dev/null +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/PersonInformation.java @@ -0,0 +1,18 @@ +package org.sadtech.bot.gitlab.context.domain; + +import lombok.Data; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +@Data +public class PersonInformation { + + private String username; + private String name; + private Long id; + private Long telegramId; + +} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java index bce1092..18db9bd 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequest.java @@ -6,16 +6,19 @@ import lombok.Setter; import org.sadtech.bot.gitlab.context.domain.MergeRequestState; import org.sadtech.haiti.context.domain.BasicEntity; +import javax.persistence.CollectionTable; import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Set; /** * Сущность ПуллРеквест. @@ -32,7 +35,6 @@ public class MergeRequest implements BasicEntity { @Id @Column(name = "id") @EqualsAndHashCode.Include - @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "two_id") @@ -57,14 +59,23 @@ public class MergeRequest implements BasicEntity { @Column(name = "updated_date") private LocalDateTime updatedDate; - @ManyToOne(optional = false) - @Column(name = "author_id") - private Person author; - @Column(name = "web_url") private String webUrl; @Column(name = "conflict") - private String conflicts; + private boolean conflict; + + @ManyToOne + @JoinColumn(name = "author_id") + private Person author; + + @ManyToOne + @JoinColumn(name = "assignee_id") + private Person assignee; + + @ElementCollection + @CollectionTable(name = "merge_request_label", joinColumns = @JoinColumn(name = "merge_request_id")) + @Column(name = "label") + private Set labels = new HashSet<>(); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/PullRequestMini.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequestMini.java similarity index 74% rename from bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/PullRequestMini.java rename to bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequestMini.java index 6ee54aa..aa02d2b 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/PullRequestMini.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/MergeRequestMini.java @@ -5,9 +5,11 @@ import lombok.Getter; import lombok.Setter; import javax.persistence.Column; +import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; /** * // TODO: 12.09.2020 Добавить описание. @@ -16,10 +18,10 @@ import javax.persistence.Id; */ @Getter @Setter -//@Entity -//@Table(name = "pull_request") +@Entity +@Table(name = "merge_request") @EqualsAndHashCode(onlyExplicitlyIncluded = true) -public class PullRequestMini { +public class MergeRequestMini { /** * Идентификатор @@ -33,13 +35,13 @@ public class PullRequestMini { /** * Адрес ПР */ - @Column(name = "url") - private String url; + @Column(name = "web_url") + private String webUrl; /** * Автор ПР */ - @Column(name = "author_login") - private String authorLogin; + @Column(name = "author_id") + private Long author; } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java index 8c5d15b..96f133a 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Person.java @@ -2,8 +2,12 @@ package org.sadtech.bot.gitlab.context.domain.entity; import lombok.Getter; import lombok.Setter; +import org.sadtech.haiti.context.domain.BasicEntity; +import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; /** * // TODO: 14.01.2021 Добавить описание. @@ -13,10 +17,20 @@ import javax.persistence.Entity; @Entity @Getter @Setter -public class Person { +@Table(name = "person") +public class Person implements BasicEntity { + @Id + @Column(name = "id") private Long id; + @Column(name = "name") private String name; + @Column(name = "username") + private String userName; + + @Column(name = "web_url") + private String webUrl; + } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java index 44010d7..d3341d9 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/GoodMorningNotify.java @@ -2,14 +2,12 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; import org.sadtech.bot.gitlab.context.utils.MessageUtils; import org.sadtech.bot.gitlab.context.utils.Smile; import org.sadtech.bot.gitlab.context.utils.UpdateDataComparator; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; /** @@ -30,11 +28,9 @@ public class GoodMorningNotify extends Notify { @Builder protected GoodMorningNotify( - Set recipients, List mergeRequestsReviews, List mergeRequestsNeedWork, String personName, String version) { - super(EntityType.PERSON, recipients); this.mergeRequestsReviews = mergeRequestsReviews; this.mergeRequestsNeedWork = mergeRequestsNeedWork; this.personName = personName; diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java index 60f8d18..9faa899 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/Notify.java @@ -3,7 +3,6 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Getter; import lombok.NonNull; import lombok.Setter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import java.util.Set; import java.util.stream.Collectors; @@ -17,14 +16,6 @@ public abstract class Notify { '\\', '+', '`', '[', ']', '\"', '~', '*', '#', '=', '_', '>', '<' ).collect(Collectors.toSet()); - protected EntityType entityType; - protected Set recipients; - - protected Notify(EntityType entityType, Set recipients) { - this.entityType = entityType; - this.recipients = recipients; - } - public abstract String generateMessage(); public static String escapeMarkdown(@NonNull String s) { diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java index 8f74d43..066f875 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/SimpleTextNotify.java @@ -2,9 +2,6 @@ package org.sadtech.bot.gitlab.context.domain.notify; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; - -import java.util.Set; /** * // TODO: 20.09.2020 Добавить описание. @@ -17,8 +14,7 @@ public class SimpleTextNotify extends Notify { private final String message; @Builder - private SimpleTextNotify(EntityType entityType, Set recipients, String message) { - super(entityType, recipients); + private SimpleTextNotify(String message) { this.message = message; } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java index 4105b53..6a9c609 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/AnswerCommentNotify.java @@ -3,13 +3,11 @@ package org.sadtech.bot.gitlab.context.domain.notify.comment; import lombok.Builder; import lombok.Getter; import org.sadtech.bot.gitlab.context.domain.Answer; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.notify.Notify; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; import java.util.List; -import java.util.Set; import java.util.stream.Collectors; @Getter @@ -21,12 +19,10 @@ public class AnswerCommentNotify extends Notify { @Builder protected AnswerCommentNotify( - Set recipients, String youMessage, String url, List answers ) { - super(EntityType.PERSON, recipients); this.youMessage = youMessage; this.url = url; this.answers = answers; diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java index e1280d4..8bd30ae 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/comment/CommentNotify.java @@ -2,12 +2,10 @@ package org.sadtech.bot.gitlab.context.domain.notify.comment; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.notify.Notify; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; @Getter public class CommentNotify extends Notify { @@ -18,12 +16,10 @@ public class CommentNotify extends Notify { @Builder private CommentNotify( - Set recipients, String url, String authorName, String message ) { - super(EntityType.PERSON, recipients); this.authorName = authorName; this.message = message; this.url = url; diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java index 411c15b..15773a9 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ConflictPrNotify.java @@ -5,29 +5,26 @@ import lombok.Getter; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; @Getter public class ConflictPrNotify extends PrNotify { @Builder private ConflictPrNotify( - Set recipients, String name, String url, - String projectKey, - String repositorySlug + String projectKey ) { - super(recipients, projectKey, repositorySlug, name, url); + super(projectKey, name, url); } @Override public String generateMessage() { return MessageFormat.format( - "{0} *Внимание конфликт в ПР | {4} | {5}*" + + "{0} *Внимание конфликт в ПР | {4}*" + "{1}" + "[{2}]({3})\n\n", - Smile.DANGEROUS, Smile.HR, title, url, projectKey, repositorySlug + Smile.DANGEROUS, Smile.HR, title, url, projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java index 9d90d81..1b213c1 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/ForgottenSmartPrNotify.java @@ -5,7 +5,6 @@ import lombok.Getter; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; /** * // TODO: 11.10.2020 Добавить описание. @@ -17,21 +16,20 @@ public class ForgottenSmartPrNotify extends PrNotify { @Builder protected ForgottenSmartPrNotify( - Set recipients, String title, String url, - String projectKey, + String projectName, String repositorySlug ) { - super(recipients, projectKey, repositorySlug, title, url); + super(projectName, title, url); } @Override public String generateMessage() { return MessageFormat.format( - "{0} *Напоминание о просмотре PullRequest | {4} | {5}*" + + "{0} *Напоминание о просмотре PullRequest | {4}*" + "{3}[{1}]({2})", - Smile.SMART, title, url, Smile.HR, projectKey, repositorySlug + Smile.SMART, title, url, Smile.HR, projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java index 7fb3013..ba371ae 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/NewPrNotify.java @@ -6,37 +6,45 @@ import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; import java.util.Set; +import java.util.stream.Collectors; @Getter public class NewPrNotify extends PrNotify { private final String description; private final String author; + private final Set labels; @Builder private NewPrNotify( - Set recipients, String title, String url, String description, String author, - String projectKey, - String repositorySlug - ) { - super(recipients, projectKey, repositorySlug, title, url); + String projectName, + Set labels) { + super(projectName, title, url); this.description = description; this.author = author; + this.labels = labels; } @Override public String generateMessage() { + String labelText = labels.stream() + .map(label -> "#" + label) + .collect(Collectors.joining(" ")); + if (!labelText.isEmpty()) { + labelText = "\n\n" + labelText; + } return MessageFormat.format( - "{0} *Новый PullRequest | {7} | {8}*{1}" + - "[{2}]({3})" + - "{1}{4}{5}: {6}\n\n", - Smile.FUN, Smile.HR, title, url, + "{0} *Новый PullRequest | {1}*{2}" + + "[{3}]({4})" + + "{5}" + + "{2}{7}: {8}\n\n", + Smile.FUN, projectName, Smile.HR, title, url, labelText, (description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "", - Smile.AUTHOR, author, projectKey, repositorySlug + Smile.AUTHOR, author ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java index 89cf87e..5f43196 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/PrNotify.java @@ -1,29 +1,21 @@ package org.sadtech.bot.gitlab.context.domain.notify.pullrequest; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.notify.Notify; -import java.util.Set; - @Getter public abstract class PrNotify extends Notify { - protected final String projectKey; - protected final String repositorySlug; + protected final String projectName; protected final String title; protected final String url; protected PrNotify( - Set recipients, - String projectKey, - String repositorySlug, + String projectName, String title, String url ) { - super(EntityType.PERSON, recipients); - this.projectKey = projectKey; - this.repositorySlug = repositorySlug; + this.projectName = projectName; this.title = title; this.url = url; } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java index fca58e5..2f263ca 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/SmartPrNotify.java @@ -6,7 +6,6 @@ import org.sadtech.bot.gitlab.context.domain.entity.Reviewer; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; /** * // TODO: 11.10.2020 Добавить описание. @@ -20,26 +19,25 @@ public class SmartPrNotify extends PrNotify { @Builder protected SmartPrNotify( - Set recipients, String title, String url, - String projectKey, + String projectName, String repositorySlug, Reviewer reviewerTriggered ) { - super(recipients, projectKey, repositorySlug, title, url); + super(projectName, title, url); this.reviewerTriggered = reviewerTriggered; } @Override public String generateMessage() { return MessageFormat.format( - "{0} *Напоминание о PullRequest | {6} | {7}*" + + "{0} *Напоминание о PullRequest | {6}*" + "{3}[{1}]({2})" + "{3}" + "{4} изменил свое решение на {5}\n\n", Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(), - projectKey, repositorySlug + projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java index c82996a..9f23094 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/StatusPrNotify.java @@ -6,7 +6,6 @@ import org.sadtech.bot.gitlab.context.domain.MergeRequestState; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; @Getter public class StatusPrNotify extends PrNotify { @@ -16,15 +15,13 @@ public class StatusPrNotify extends PrNotify { @Builder private StatusPrNotify( - Set recipients, String name, String url, - String projectKey, - String repositorySlug, + String projectName, MergeRequestState oldStatus, MergeRequestState newStatus ) { - super(recipients, projectKey, repositorySlug, name, url); + super(projectName, name, url); this.oldStatus = oldStatus; this.newStatus = newStatus; } @@ -32,10 +29,10 @@ public class StatusPrNotify extends PrNotify { @Override public String generateMessage() { return MessageFormat.format( - "{0} *Изменился статус PullRequest | {7} | {8}*{1}" + + "{0} *Изменился статус PullRequest | {7}*{1}" + "[{2}]({3}){1}" + "{4} {5} {6}\n\n", - Smile.PEN, Smile.HR, title, url, oldStatus.name(), Smile.ARROW, newStatus.name(), projectKey, repositorySlug + Smile.PEN, Smile.HR, title, url, oldStatus.name(), Smile.ARROW, newStatus.name(), projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java index f22b935..ea4975d 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/pullrequest/UpdatePrNotify.java @@ -5,7 +5,6 @@ import lombok.Getter; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; @Getter public class UpdatePrNotify extends PrNotify { @@ -14,25 +13,23 @@ public class UpdatePrNotify extends PrNotify { @Builder private UpdatePrNotify( - Set recipients, String name, String url, String author, - String projectKey, - String repositorySlug + String projectKey ) { - super(recipients, projectKey, repositorySlug, name, url); + super(projectKey, name, url); this.author = author; } @Override public String generateMessage() { return MessageFormat.format( - "{0} *Обновление PullRequest | {6} | {7}*{3}" + + "{0} *Обновление PullRequest | {6}*{3}" + "[{1}]({2})" + "{3}" + "{4}: {5}\n\n", - Smile.UPDATE, title, url, Smile.HR, Smile.AUTHOR, author, projectKey, repositorySlug + Smile.UPDATE, title, url, Smile.HR, Smile.AUTHOR, author, projectName ); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java index da0e2fc..2851040 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskCloseNotify.java @@ -4,7 +4,6 @@ import lombok.Builder; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; /** * // TODO: 10.09.2020 Добавить описание. @@ -15,12 +14,11 @@ public class TaskCloseNotify extends TaskNotify { @Builder protected TaskCloseNotify( - Set recipients, String authorName, String url, String messageTask ) { - super(recipients, authorName, url, messageTask); + super(authorName, url, messageTask); } @Override diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java index f5937b0..b8e87c9 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNewNotify.java @@ -5,7 +5,6 @@ import lombok.Getter; import org.sadtech.bot.gitlab.context.utils.Smile; import java.text.MessageFormat; -import java.util.Set; /** * // TODO: 10.09.2020 Добавить описание. @@ -17,12 +16,11 @@ public class TaskNewNotify extends TaskNotify { @Builder protected TaskNewNotify( - Set recipients, String authorName, String url, String messageTask ) { - super(recipients, authorName, url, messageTask); + super(authorName, url, messageTask); } @Override diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNotify.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNotify.java index 23b831b..2cfc12f 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNotify.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/notify/task/TaskNotify.java @@ -2,11 +2,8 @@ package org.sadtech.bot.gitlab.context.domain.notify.task; import lombok.EqualsAndHashCode; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.notify.Notify; -import java.util.Set; - @Getter @EqualsAndHashCode(callSuper = true) public abstract class TaskNotify extends Notify { @@ -16,12 +13,10 @@ public abstract class TaskNotify extends Notify { protected final String messageTask; protected TaskNotify( - Set recipients, String authorName, String url, String messageTask ) { - super(EntityType.PERSON, recipients); this.authorName = authorName; this.url = url; this.messageTask = messageTask; diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PullRequestsRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/MergeRequestRepository.java similarity index 74% rename from bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PullRequestsRepository.java rename to bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/MergeRequestRepository.java index 456972f..cfdfae3 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PullRequestsRepository.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/MergeRequestRepository.java @@ -4,17 +4,17 @@ import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; import org.sadtech.bot.gitlab.context.domain.MergeRequestState; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; -import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini; import org.sadtech.haiti.context.repository.SimpleManagerRepository; import org.sadtech.haiti.filter.FilterOperation; import java.util.Optional; import java.util.Set; -public interface PullRequestsRepository extends SimpleManagerRepository, FilterOperation { +public interface MergeRequestRepository extends SimpleManagerRepository, FilterOperation { Set findAllIdByStatusIn(Set statuses); - Optional findMiniInfoById(@NonNull Long id); + Optional findMiniInfoById(@NonNull Long id); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/NotifySettingRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/NotifySettingRepository.java index 660fc4a..887cf55 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/NotifySettingRepository.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/NotifySettingRepository.java @@ -1,11 +1,8 @@ package org.sadtech.bot.gitlab.context.repository; -import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; import org.sadtech.haiti.context.repository.SimpleManagerRepository; -import java.util.Set; - /** * // TODO: 20.09.2020 Добавить описание. * @@ -13,8 +10,4 @@ import java.util.Set; */ public interface NotifySettingRepository extends SimpleManagerRepository { - boolean isNotification(@NonNull String login); - - Set isNotification(@NonNull Set logins); - } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java new file mode 100644 index 0000000..f712c06 --- /dev/null +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/repository/PersonRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.gitlab.context.repository; + +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.sadtech.haiti.context.repository.SimpleManagerRepository; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +public interface PersonRepository extends SimpleManagerRepository { + +} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/ChatService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/ChatService.java deleted file mode 100644 index 3cc3f22..0000000 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/ChatService.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.bot.gitlab.context.service; - -import lombok.NonNull; - -import java.util.Set; - -/** - * // TODO: 11.10.2020 Добавить описание. - * - * @author upagge 11.10.2020 - */ -public interface ChatService { - - Set getAllTelegramIdByKey(@NonNull Set keys); - -} diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/MergeRequestsService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/MergeRequestsService.java index fc8fddc..d49d86c 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/MergeRequestsService.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/MergeRequestsService.java @@ -4,7 +4,7 @@ import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; import org.sadtech.bot.gitlab.context.domain.MergeRequestState; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; -import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini; import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter; import org.sadtech.haiti.context.service.SimpleManagerService; import org.sadtech.haiti.filter.FilterService; @@ -22,6 +22,6 @@ public interface MergeRequestsService extends SimpleManagerService getAllId(Set statuses); - Optional getMiniInfo(@NonNull Long pullRequestId); + Optional getMiniInfo(@NonNull Long pullRequestId); } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NotifyService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NotifyService.java index 961bd4f..a229665 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NotifyService.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/NotifyService.java @@ -1,11 +1,7 @@ package org.sadtech.bot.gitlab.context.service; -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; import org.sadtech.bot.gitlab.context.domain.notify.Notify; -import java.util.Optional; - /** * Сервис по работе с изменениями в битбакете. * @@ -16,16 +12,4 @@ public interface NotifyService { void send(T notify); - /** - * Сохранить настройки уведомлений - */ - void saveSettings(@NonNull NotifySetting setting); - - /** - * Получить настройки уведомлений по логину. - * - * @param login Логин пользователя - */ - Optional getSetting(@NonNull String login); - } diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java new file mode 100644 index 0000000..031c8c6 --- /dev/null +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/service/PersonService.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.gitlab.context.service; + +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.sadtech.haiti.context.service.SimpleManagerService; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +public interface PersonService extends SimpleManagerService { + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java index 2bd4870..93190f7 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/GitlabProperty.java @@ -16,12 +16,6 @@ import org.springframework.stereotype.Component; @ConfigurationProperties("gitlab-bot.gitlab") public class GitlabProperty { - private String username; - - private String fullName; - - private String token; - /** * Адрес, по которому можно получить открытые ПР */ @@ -44,4 +38,6 @@ public class GitlabProperty { private String urlProject; + private String userUrl; + } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/PersonProperty.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/PersonProperty.java new file mode 100644 index 0000000..063d453 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/config/properties/PersonProperty.java @@ -0,0 +1,23 @@ +package org.sadtech.bot.gitlab.core.config.properties; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ + +@Getter +@Setter +@Configuration +@ConfigurationProperties(prefix = "gitlab-bot.person") +public class PersonProperty { + + private String token; + private Long telegramId; + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/ChatServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/ChatServiceImpl.java deleted file mode 100644 index ea66584..0000000 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/ChatServiceImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sadtech.bot.gitlab.core.service.impl; - -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.repository.ChatRepository; -import org.sadtech.bot.gitlab.context.service.ChatService; - -import java.util.Set; - -/** - * // TODO: 11.10.2020 Добавить описание. - * - * @author upagge 11.10.2020 - */ -//@Service -@RequiredArgsConstructor -public class ChatServiceImpl implements ChatService { - - private final ChatRepository chatRepository; - - @Override - public Set getAllTelegramIdByKey(@NonNull Set keys) { - return chatRepository.findAllTelegramIdByKey(keys); - } - -} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java index d639dca..f3ff91e 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/CommentServiceImpl.java @@ -19,7 +19,6 @@ import org.springframework.core.convert.ConversionService; import java.time.LocalDateTime; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -81,7 +80,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService implements MergeRequestsService { - protected final NotifyService notifyService; - protected final PullRequestsRepository pullRequestsRepository; - protected final FilterService filterService; + private final NotifyService notifyService; + private final MergeRequestRepository mergeRequestRepository; + private final PersonService personService; + private final FilterService filterService; + private final ProjectService projectService; + private final PersonInformation personInformation; protected MergeRequestsServiceImpl( - PullRequestsRepository pullRequestsRepository, + MergeRequestRepository mergeRequestRepository, NotifyService notifyService, - @Qualifier("pullRequestFilterService") FilterService pullRequestsFilterService + PersonService personService, + @Qualifier("mergeRequestFilterService") FilterService filterService, + ProjectService projectService, + PersonInformation personInformation ) { - super(pullRequestsRepository); + super(mergeRequestRepository); this.notifyService = notifyService; - this.pullRequestsRepository = pullRequestsRepository; - this.filterService = pullRequestsFilterService; + this.mergeRequestRepository = mergeRequestRepository; + this.personService = personService; + this.filterService = filterService; + this.projectService = projectService; + this.personInformation = personInformation; } @Override public MergeRequest create(@NonNull MergeRequest mergeRequest) { - Assert.isNull(mergeRequest.getId(), "При создании идентификатор должен быть пустым"); + personService.create(mergeRequest.getAuthor()); + personService.create(mergeRequest.getAssignee()); + final MergeRequest newMergeRequest = mergeRequestRepository.save(mergeRequest); - final MergeRequest newMergeRequest = pullRequestsRepository.save(mergeRequest); - - notifyService.send( - NewPrNotify.builder() - .author(newMergeRequest.getAuthor().getName()) - .description(newMergeRequest.getDescription()) - .title(newMergeRequest.getTitle()) - .url(newMergeRequest.getWebUrl()) - .build() - ); - + if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) { + final String projectName = projectService.getById(newMergeRequest.getProjectId()) + .orElseThrow(() -> new NotFoundException("Проект не найден")) + .getName(); + notifyService.send( + NewPrNotify.builder() + .projectName(projectName) + .labels(newMergeRequest.getLabels()) + .author(newMergeRequest.getAuthor().getName()) + .description(newMergeRequest.getDescription()) + .title(newMergeRequest.getTitle()) + .url(newMergeRequest.getWebUrl()) + .build() + ); + } return newMergeRequest; } @@ -66,16 +85,14 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService new NotFoundException("Проект не найден")); + notifyStatus(oldMergeRequest, mergeRequest, project); + notifyConflict(oldMergeRequest, mergeRequest, project); - return pullRequestsRepository.save(oldMergeRequest); + return mergeRequestRepository.save(mergeRequest); } protected void forgottenNotification(MergeRequest mergeRequest) { @@ -103,138 +120,39 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService oldReviewers = oldMergeRequest.getReviewers().stream() -// .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer)); -// final Map newReviewers = newMergeRequest.getReviewers().stream() -// .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer)); -// final List reviewerChanges = new ArrayList<>(); -// for (Reviewer newReviewer : newReviewers.values()) { -// if (oldReviewers.containsKey(newReviewer.getPersonLogin())) { -// final Reviewer oldReviewer = oldReviewers.get(newReviewer.getPersonLogin()); -// final ReviewerStatus oldStatus = oldReviewer.getStatus(); -// final ReviewerStatus newStatus = newReviewer.getStatus(); -// if (!oldStatus.equals(newStatus)) { -// reviewerChanges.add(ReviewerChange.ofOld(oldReviewer.getPersonLogin(), oldStatus, newStatus)); -// oldReviewer.setStatus(newStatus); -// oldReviewer.setDateChange(LocalDateTime.now()); -// smartNotifyAfterReviewerDecision(newReviewer, oldMergeRequest); -// } -// } else { -// reviewerChanges.add(ReviewerChange.ofNew(newReviewer.getPersonLogin(), newReviewer.getStatus())); -// newReviewer.setMergeRequest(oldMergeRequest); -// newReviewer.setDateChange(LocalDateTime.now()); -// oldMergeRequest.getReviewers().add(newReviewer); -// } -// } -// final Set oldIds = oldReviewers.keySet(); -// oldIds.removeAll(newReviewers.keySet()); -// reviewerChanges.addAll( -// oldReviewers.entrySet().stream() -// .filter(e -> oldIds.contains(e.getKey())) -// .map(e -> ReviewerChange.ofDeleted(e.getValue().getPersonLogin())) -// .collect(Collectors.toList()) -// ); -// oldMergeRequest.getReviewers() -// .removeIf(reviewer -> oldIds.contains(reviewer.getPersonLogin())); -// if (!reviewerChanges.isEmpty()) { -// notifyService.send( -// ReviewersPrNotify.builder() -// .title(newMergeRequest.getTitle()) -// .url(newMergeRequest.getUrl()) -// .projectKey(newMergeRequest.getProjectKey()) -// .repositorySlug(newMergeRequest.getRepositorySlug()) -// .recipients(Collections.singleton(newMergeRequest.getAuthorLogin())) -// .reviewerChanges(reviewerChanges) -// .build() -// ); -// } - } - - /** - * Умное уведомление ревьюверов, после того, как кто-то изменил свое решение. - */ - protected void smartNotifyAfterReviewerDecision(Reviewer newReviewer, MergeRequest oldMergeRequest) { -// final ReviewerStatus newStatus = newReviewer.getStatus(); -// if (!ReviewerStatus.NEEDS_WORK.equals(newStatus) && enoughTimHasPassedSinceUpdatePr(oldMergeRequest.getUpdateDate())) { -// final List smartReviewers = oldMergeRequest.getReviewers().stream() -// .filter(reviewer -> LocalDateTime.now().isAfter(reviewer.getDateChange().plusHours(2L))) -// .collect(Collectors.toList()); -// if (!smartReviewers.isEmpty()) { -// notifyService.send( -// SmartPrNotify.builder() -// .reviewerTriggered(newReviewer) -// .title(oldMergeRequest.getTitle()) -// .url(oldMergeRequest.getUrl()) -// .projectKey(oldMergeRequest.getProjectKey()) -// .repositorySlug(oldMergeRequest.getRepositorySlug()) -// .recipients( -// smartReviewers.stream() -// .map(Reviewer::getPersonLogin) -// .collect(Collectors.toSet()) -// ) -// .build() -// ); -// } -// } + protected void notifyStatus(MergeRequest oldMergeRequest, MergeRequest newMergeRequest, Project project) { + final MergeRequestState oldStatus = oldMergeRequest.getState(); + final MergeRequestState newStatus = newMergeRequest.getState(); + if ( + !oldStatus.equals(newStatus) + && oldMergeRequest.getAuthor().getId().equals(personInformation.getId()) + ) { + notifyService.send( + StatusPrNotify.builder() + .name(newMergeRequest.getTitle()) + .url(oldMergeRequest.getWebUrl()) + .projectName(project.getName()) + .newStatus(newStatus) + .oldStatus(oldStatus) + .build() + ); + } } protected boolean enoughTimHasPassedSinceUpdatePr(LocalDateTime updateDate) { @@ -247,8 +165,8 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService getMiniInfo(@NonNull Long pullRequestId) { - return pullRequestsRepository.findMiniInfoById(pullRequestId); + public Optional getMiniInfo(@NonNull Long pullRequestId) { + return mergeRequestRepository.findMiniInfoById(pullRequestId); } @Override @@ -282,9 +200,4 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService existsById(@NonNull Collection collection) { - return null; - } - } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NotifyServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NotifyServiceImpl.java index da65187..795bed4 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NotifyServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/NotifyServiceImpl.java @@ -1,42 +1,20 @@ package org.sadtech.bot.gitlab.core.service.impl; -import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.bot.gitlab.context.domain.EntityType; -import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; import org.sadtech.bot.gitlab.context.domain.notify.Notify; -import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository; import org.sadtech.bot.gitlab.context.service.MessageSendService; import org.sadtech.bot.gitlab.context.service.NotifyService; +import org.springframework.stereotype.Service; -import java.util.Optional; -import java.util.Set; - -//@Service +@Service @RequiredArgsConstructor public class NotifyServiceImpl implements NotifyService { - private final NotifySettingRepository settingRepository; - private final MessageSendService messageSendService; @Override public void send(T notify) { - if (EntityType.PERSON.equals(notify.getEntityType())) { - final Set recipientLogins = settingRepository.isNotification(notify.getRecipients()); - notify.setRecipients(recipientLogins); - } messageSendService.send(notify); } - @Override - public void saveSettings(@NonNull NotifySetting setting) { - settingRepository.save(setting); - } - - @Override - public Optional getSetting(@NonNull String login) { - return settingRepository.findById(login); - } - } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java new file mode 100644 index 0000000..d1d6726 --- /dev/null +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PersonServiceImpl.java @@ -0,0 +1,35 @@ +package org.sadtech.bot.gitlab.core.service.impl; + +import lombok.NonNull; +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.sadtech.bot.gitlab.context.repository.PersonRepository; +import org.sadtech.bot.gitlab.context.service.PersonService; +import org.sadtech.haiti.core.service.AbstractSimpleManagerService; +import org.springframework.stereotype.Service; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +@Service +public class PersonServiceImpl extends AbstractSimpleManagerService implements PersonService { + + private final PersonRepository personRepository; + + public PersonServiceImpl(PersonRepository personRepository) { + super(personRepository); + this.personRepository = personRepository; + } + + @Override + public Person create(@NonNull Person person) { + return personRepository.save(person); + } + + @Override + public Person update(@NonNull Person person) { + return personRepository.save(person); + } + +} diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java index 1c266d7..8ef19fe 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/TaskServiceImpl.java @@ -23,7 +23,6 @@ import org.springframework.core.convert.ConversionService; import java.time.LocalDateTime; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -95,7 +94,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im .messageTask(task.getDescription()) .authorName(oldTask.getAuthor()) .url(oldTask.getUrl()) - .recipients(Collections.singleton(oldTask.getResponsible())) .build() ); break; @@ -105,7 +103,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im .messageTask(oldTask.getDescription()) .authorName(oldTask.getAuthor()) .url(oldTask.getUrl()) - .recipients(Collections.singleton(oldTask.getAuthor())) .build() ); break; @@ -129,7 +126,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im if (!newAnswers.isEmpty()) { notifyService.send( AnswerCommentNotify.builder() - .recipients(Collections.singleton(oldTask.getAuthor())) .url(oldTask.getUrl()) .youMessage(oldTask.getDescription()) .answers( @@ -192,7 +188,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService im CommentNotify.builder() .authorName(task.getAuthor()) .url(task.getUrl()) - .recipients(recipientsLogins) .message(task.getDescription()) .build() ); diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/PullRequestFilterService.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/MergeRequestFilterService.java similarity index 77% rename from bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/PullRequestFilterService.java rename to bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/MergeRequestFilterService.java index a3208d7..f5cc496 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/PullRequestFilterService.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/filter/MergeRequestFilterService.java @@ -3,17 +3,18 @@ package org.sadtech.bot.gitlab.core.service.impl.filter; import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter; -import org.sadtech.bot.gitlab.context.repository.PullRequestsRepository; +import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository; import org.sadtech.haiti.core.service.AbstractFilterService; import org.sadtech.haiti.filter.Filter; import org.sadtech.haiti.filter.FilterQuery; import org.sadtech.haiti.filter.criteria.CriteriaFilter; import org.sadtech.haiti.filter.criteria.CriteriaQuery; +import org.springframework.stereotype.Service; -//@Service -public class PullRequestFilterService extends AbstractFilterService { +@Service +public class MergeRequestFilterService extends AbstractFilterService { - public PullRequestFilterService(PullRequestsRepository filterOperation) { + public MergeRequestFilterService(MergeRequestRepository filterOperation) { super(filterOperation); } diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java new file mode 100644 index 0000000..e68eed4 --- /dev/null +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/MergeRequestRepositoryImpl.java @@ -0,0 +1,39 @@ +package org.sadtech.bot.gitlab.data.impl; + +import lombok.NonNull; +import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; +import org.sadtech.bot.gitlab.context.domain.MergeRequestState; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini; +import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository; +import org.sadtech.bot.gitlab.data.jpa.MergeRequestJpaRepository; +import org.sadtech.bot.gitlab.data.jpa.MergeRequestMiniJpaRepository; +import org.sadtech.haiti.database.repository.manager.FilterManagerRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.Set; + +@Repository +public class MergeRequestRepositoryImpl extends FilterManagerRepository implements MergeRequestRepository { + + private final MergeRequestJpaRepository repositoryJpa; + private final MergeRequestMiniJpaRepository mergeRequestMiniJpaRepository; + + public MergeRequestRepositoryImpl(MergeRequestJpaRepository jpaRepository, MergeRequestMiniJpaRepository mergeRequestMiniJpaRepository) { + super(jpaRepository); + repositoryJpa = jpaRepository; + this.mergeRequestMiniJpaRepository = mergeRequestMiniJpaRepository; + } + + @Override + public Set findAllIdByStatusIn(Set statuses) { + return repositoryJpa.findAllIdByStateIn(statuses); + } + + @Override + public Optional findMiniInfoById(@NonNull Long id) { + return mergeRequestMiniJpaRepository.findById(id); + } + +} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java index 1b10627..c9317c3 100644 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/NotifySettingRepositoryImpl.java @@ -1,14 +1,10 @@ package org.sadtech.bot.gitlab.data.impl; -import lombok.NonNull; import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting; import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository; import org.sadtech.bot.gitlab.data.jpa.NotifySettingJpaRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import java.time.LocalDateTime; -import java.util.Set; - /** * // TODO: 20.09.2020 Добавить описание. * @@ -24,14 +20,4 @@ public class NotifySettingRepositoryImpl extends AbstractSimpleManagerRepository this.jpaRepository = jpaRepository; } - @Override - public boolean isNotification(@NonNull String login) { - return jpaRepository.findByLoginAndStartReceivingAfter(login, LocalDateTime.now()); - } - - @Override - public Set isNotification(@NonNull Set logins) { - return jpaRepository.findAllByLoginInAndStartReceivingAfter(logins, LocalDateTime.now()); - } - } diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java new file mode 100644 index 0000000..f16991a --- /dev/null +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PersonRepositoryImpl.java @@ -0,0 +1,21 @@ +package org.sadtech.bot.gitlab.data.impl; + +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.sadtech.bot.gitlab.context.repository.PersonRepository; +import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +@Repository +public class PersonRepositoryImpl extends AbstractSimpleManagerRepository implements PersonRepository { + + public PersonRepositoryImpl(JpaRepository jpaRepository) { + super(jpaRepository); + } + +} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PullRequestsRepositoryImpl.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PullRequestsRepositoryImpl.java deleted file mode 100644 index cc84299..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/impl/PullRequestsRepositoryImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sadtech.bot.gitlab.data.impl; - -import lombok.NonNull; -import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; -import org.sadtech.bot.gitlab.context.domain.MergeRequestState; -import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; -import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; -import org.sadtech.bot.gitlab.context.repository.PullRequestsRepository; -import org.sadtech.bot.gitlab.data.jpa.PullRequestMiniRepositoryJpa; -import org.sadtech.bot.gitlab.data.jpa.PullRequestsRepositoryJpa; -import org.sadtech.haiti.database.repository.manager.FilterManagerRepository; - -import java.util.Optional; -import java.util.Set; - -//@Repository -public class PullRequestsRepositoryImpl extends FilterManagerRepository implements PullRequestsRepository { - - private final PullRequestsRepositoryJpa repositoryJpa; - private final PullRequestMiniRepositoryJpa pullRequestMiniRepositoryJpa; - - public PullRequestsRepositoryImpl(PullRequestsRepositoryJpa jpaRepository, PullRequestMiniRepositoryJpa pullRequestMiniRepositoryJpa) { - super(jpaRepository); - repositoryJpa = jpaRepository; - this.pullRequestMiniRepositoryJpa = pullRequestMiniRepositoryJpa; - } - - - @Override - public Set findAllIdByStatusIn(Set statuses) { - return repositoryJpa.findAllIdByStatusIn(statuses); - } - - @Override - public Optional findMiniInfoById(@NonNull Long id) { - return pullRequestMiniRepositoryJpa.findById(id); - } - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestJpaRepository.java new file mode 100644 index 0000000..17325a3 --- /dev/null +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestJpaRepository.java @@ -0,0 +1,33 @@ +package org.sadtech.bot.gitlab.data.jpa; + +import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; +import org.sadtech.bot.gitlab.context.domain.MergeRequestState; +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; +import org.springframework.data.repository.query.Param; + +import java.util.Collection; +import java.util.Optional; +import java.util.Set; + +/** + * @author upagge [31.01.2020] + */ + +public interface MergeRequestJpaRepository extends JpaRepositoryImplementation { + + Set findAllByIdIn(Set ids); + + void deleteAllByIdIn(Collection id); + + @Query("SELECT new org.sadtech.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.state) FROM MergeRequest p WHERE p.state IN :statuses") + Set findAllIdByStateIn(@Param("statuses") Set statuses); + + @Query("SELECT p.id from MergeRequest p") + Set findAllIds(); + + @Query("SELECT p.author.id from MergeRequest p WHERE p.id = :id") + Optional findAuthorById(@Param("id") Long id); + +} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestMiniJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestMiniJpaRepository.java new file mode 100644 index 0000000..fbd543a --- /dev/null +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/MergeRequestMiniJpaRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.gitlab.data.jpa; + +import org.sadtech.bot.gitlab.context.domain.entity.MergeRequestMini; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * // TODO: 12.09.2020 Добавить описание. + * + * @author upagge 12.09.2020 + */ +public interface MergeRequestMiniJpaRepository extends JpaRepository { + +} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java new file mode 100644 index 0000000..30477a2 --- /dev/null +++ b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PersonJpaRepository.java @@ -0,0 +1,13 @@ +package org.sadtech.bot.gitlab.data.jpa; + +import org.sadtech.bot.gitlab.context.domain.entity.Person; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * // TODO: 15.01.2021 Добавить описание. + * + * @author upagge 15.01.2021 + */ +public interface PersonJpaRepository extends JpaRepository { + +} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestMiniRepositoryJpa.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestMiniRepositoryJpa.java deleted file mode 100644 index f205272..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestMiniRepositoryJpa.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.bot.gitlab.data.jpa; - -import org.sadtech.bot.gitlab.context.domain.entity.PullRequestMini; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.NoRepositoryBean; - -/** - * // TODO: 12.09.2020 Добавить описание. - * - * @author upagge 12.09.2020 - */ - -@NoRepositoryBean -public interface PullRequestMiniRepositoryJpa extends JpaRepository { - -} diff --git a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestsRepositoryJpa.java b/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestsRepositoryJpa.java deleted file mode 100644 index 7354fc0..0000000 --- a/bot-data/src/main/java/org/sadtech/bot/gitlab/data/jpa/PullRequestsRepositoryJpa.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.sadtech.bot.gitlab.data.jpa; - -import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr; -import org.sadtech.bot.gitlab.context.domain.MergeRequestState; -import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest; -import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; -import org.springframework.data.repository.NoRepositoryBean; -import org.springframework.data.repository.query.Param; - -import java.util.Collection; -import java.util.Optional; -import java.util.Set; - -/** - * @author upagge [31.01.2020] - */ - -@NoRepositoryBean -public interface PullRequestsRepositoryJpa extends JpaRepositoryImplementation { - - Set findAllByIdIn(Set ids); - - Boolean existsByBitbucketIdAndRepositoryId(Long bitbucketId, Long repositoryId); - - // @Query("SELECT p.id FROM PullRequest p WHERE p.bitbucketId=:bitbucketId AND p.repositoryId=:repositoryId") - Optional findIdByBitbucketIdAndRepositoryId(@Param("bitbucketId") Long bitbucketId, @Param("repositoryId") Long repositoryId); - - void deleteAllByIdIn(Collection id); - - // @Query("SELECT new org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses") - Set findAllIdByStatusIn(@Param("statuses") Set statuses); - - // @Query("SELECT p.id from PullRequest p") - Set findAllIds(); - - // @Query("SELECT p.authorLogin from PullRequest p WHERE p.id = :id") - Optional findAuthorById(@Param("id") Long id); - -} diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestJson.java index 8f67e75..78b4669 100644 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestJson.java +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestJson.java @@ -2,10 +2,13 @@ package org.sadtech.bot.gitlab.sdk.domain; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import lombok.Data; -import org.sadtech.bot.gitlab.sdk.utils.LocalDateTimeFromEpochDeserializer; import java.time.LocalDateTime; +import java.util.Set; /** * TODO: Добавить описание класса. @@ -24,22 +27,27 @@ public class MergeRequestJson { private Long projectId; private String title; private String description; - private PullRequestState state; + private MergeRequestStateJson state; + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) @JsonProperty("created_at") - @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class) private LocalDateTime createdDate; @JsonProperty("updated_at") - @JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class) + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonDeserialize(using = LocalDateTimeDeserializer.class) private LocalDateTime updatedDate; - private AuthorJson author; + private PersonJson author; + private PersonJson assignee; @JsonProperty("web_url") private String webUrl; @JsonProperty("has_conflicts") - private String conflicts; + private boolean conflicts; + + private Set labels; } diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java new file mode 100644 index 0000000..946b713 --- /dev/null +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/MergeRequestStateJson.java @@ -0,0 +1,21 @@ +package org.sadtech.bot.gitlab.sdk.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * TODO: Добавить комментарий енума. + * + * @author upagge [01.02.2020] + */ +public enum MergeRequestStateJson { + + @JsonProperty("opened") + OPENED, + @JsonProperty("closed") + CLOSED, + @JsonProperty("locked") + LOCKED, + @JsonProperty("merger") + MERGED + +} diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/AuthorJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PersonJson.java similarity index 85% rename from gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/AuthorJson.java rename to gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PersonJson.java index 1d65a00..e95cf86 100644 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/AuthorJson.java +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PersonJson.java @@ -9,11 +9,11 @@ import lombok.Data; * @author upagge [31.01.2020] */ @Data -public class AuthorJson { +public class PersonJson { private Long id; private String name; - private String userName; + private String username; @JsonProperty("web_url") private String webUrl; diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java deleted file mode 100644 index f1d1719..0000000 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PullRequestState.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sadtech.bot.gitlab.sdk.domain; - -/** - * TODO: Добавить комментарий енума. - * - * @author upagge [01.02.2020] - */ -public enum PullRequestState { - - OPENED, MERGED, DECLINED - -} diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java index 01cacf9..18f8ea7 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/TeamcityBuildNotify.java @@ -2,14 +2,12 @@ package org.sadtech.bot.gitlab.teamcity.core.domain; import lombok.Builder; import lombok.Getter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.bot.gitlab.context.domain.notify.Notify; import org.sadtech.bot.gitlab.context.utils.Smile; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.BuildShort; import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus; import java.text.MessageFormat; -import java.util.Set; /** * // TODO: 21.09.2020 Добавить описание. @@ -22,8 +20,7 @@ public class TeamcityBuildNotify extends Notify { private final BuildShort buildShort; @Builder - private TeamcityBuildNotify(EntityType entityType, Set recipients, BuildShort buildShort) { - super(entityType, recipients); + private TeamcityBuildNotify(BuildShort buildShort) { this.buildShort = buildShort; } diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/entity/TeamcitySetting.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/entity/TeamcitySetting.java index 00b0e33..9f97707 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/entity/TeamcitySetting.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/domain/entity/TeamcitySetting.java @@ -3,17 +3,12 @@ package org.sadtech.bot.gitlab.teamcity.core.domain.entity; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.sadtech.bot.gitlab.context.domain.EntityType; import org.sadtech.haiti.context.domain.BasicEntity; import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.Table; /** * // TODO: 21.09.2020 Добавить описание. @@ -22,8 +17,8 @@ import javax.persistence.Table; */ @Getter @Setter -@Entity -@Table(name = "teamcity_setting") +//@Entity +//@Table(name = "teamcity_setting") @EqualsAndHashCode(onlyExplicitlyIncluded = true) public class TeamcitySetting implements BasicEntity { @@ -36,10 +31,6 @@ public class TeamcitySetting implements BasicEntity { @Column(name = "recipient_id") private String recipientId; - @Enumerated(EnumType.STRING) - @Column(name = "recipient_type") - private EntityType recipientType; - @Column(name = "project_id") private String projectId; diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/impl/TeamcitySettingRepositoryImpl.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/impl/TeamcitySettingRepositoryImpl.java index 59e7ea1..e3a7d5c 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/impl/TeamcitySettingRepositoryImpl.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/impl/TeamcitySettingRepositoryImpl.java @@ -5,7 +5,6 @@ import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcitySetting; import org.sadtech.bot.gitlab.teamcity.core.repository.TeamcitySettingRepository; import org.sadtech.bot.gitlab.teamcity.core.repository.jpa.TeamcitySettingJpaRepository; import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository; -import org.springframework.stereotype.Repository; import java.util.List; @@ -14,7 +13,7 @@ import java.util.List; * * @author upagge 21.09.2020 */ -@Repository +//@Repository public class TeamcitySettingRepositoryImpl extends AbstractSimpleManagerRepository implements TeamcitySettingRepository { private final TeamcitySettingJpaRepository jpaRepository; diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/jpa/TeamcitySettingJpaRepository.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/jpa/TeamcitySettingJpaRepository.java index b102cb1..152d11b 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/jpa/TeamcitySettingJpaRepository.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/repository/jpa/TeamcitySettingJpaRepository.java @@ -2,6 +2,7 @@ package org.sadtech.bot.gitlab.teamcity.core.repository.jpa; import org.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcitySetting; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.NoRepositoryBean; import java.util.List; @@ -10,6 +11,7 @@ import java.util.List; * * @author upagge 21.09.2020 */ +@NoRepositoryBean public interface TeamcitySettingJpaRepository extends JpaRepository { List findAllByProjectId(String projectId); diff --git a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/impl/BuildShortServiceImpl.java b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/impl/BuildShortServiceImpl.java index 1120ac7..7823e56 100644 --- a/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/impl/BuildShortServiceImpl.java +++ b/teamcity/teamcity-core/src/main/java/org/sadtech/bot/gitlab/teamcity/core/service/impl/BuildShortServiceImpl.java @@ -13,7 +13,6 @@ import org.sadtech.haiti.context.domain.ExistsContainer; import org.sadtech.haiti.core.service.AbstractSimpleManagerService; import java.util.Collection; -import java.util.Collections; import java.util.Set; /** @@ -54,8 +53,6 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService telegramIds = getTelegramIds(notify); - telegramIds.forEach( - telegramId -> sending.send(telegramId, BoxAnswer.of(notify.generateMessage())) - ); - } - - private Set getTelegramIds(Notify notify) { -// switch (notify.getEntityType()) { -// case PERSON: -// return personService.getAllTelegramIdByLogin(notify.getRecipients()); -// case CHAT: -// return chatService.getAllTelegramIdByKey(notify.getRecipients()); -// default: -// throw new NotFoundException("Отправка сообщения этому типу не возможна"); -// } - return Collections.emptySet(); + sending.send(personInformation.getTelegramId(), BoxAnswer.of(notify.generateMessage())); } }