Уведомления по MergeRequest
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
package org.sadtech.bot.gitlab.app.config;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
@@ -13,6 +18,10 @@ import java.util.Arrays;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.sadtech.bot.gitlab.app.scheduler;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.sadtech.bot.gitlab.app.service.parser.ProjectParser;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -17,15 +18,16 @@ import org.springframework.stereotype.Service;
|
|||||||
public class SchedulerService {
|
public class SchedulerService {
|
||||||
|
|
||||||
private final ProjectParser projectParser;
|
private final ProjectParser projectParser;
|
||||||
|
private final MergeRequestParser mergeRequestParser;
|
||||||
|
|
||||||
@Scheduled(cron = "0 */1 * * * *")
|
@Scheduled(cron = "*/30 * * * * *")
|
||||||
public void newProjectParse() {
|
public void newProjectParse() {
|
||||||
projectParser.parseNewProject();
|
projectParser.parseNewProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 */1 * * * *")
|
@Scheduled(cron = "*/30 * * * * *")
|
||||||
public void newMergeRequest() {
|
public void newMergeRequest() {
|
||||||
|
mergeRequestParser.parsingNewMergeRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.Executor;
|
||||||
import org.sadtech.bot.gitlab.app.service.executor.Seeker;
|
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.GitlabProperty;
|
||||||
|
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
|
||||||
import org.sadtech.bot.gitlab.sdk.domain.CommentJson;
|
import org.sadtech.bot.gitlab.sdk.domain.CommentJson;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -26,12 +27,13 @@ public class ExecutorScanner implements Executor<DataScan, CommentJson> {
|
|||||||
private final ExecutorService executorService;
|
private final ExecutorService executorService;
|
||||||
private List<Future<Optional<CommentJson>>> resultList = new ArrayList<>();
|
private List<Future<Optional<CommentJson>>> resultList = new ArrayList<>();
|
||||||
private final GitlabProperty gitlabProperty;
|
private final GitlabProperty gitlabProperty;
|
||||||
|
private final PersonProperty personProperty;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registration(@NonNull List<DataScan> dataScans) {
|
public boolean registration(@NonNull List<DataScan> dataScans) {
|
||||||
resultList.addAll(
|
resultList.addAll(
|
||||||
dataScans.stream()
|
dataScans.stream()
|
||||||
.map(dataScan -> new Seeker(dataScan, gitlabProperty.getToken()))
|
.map(dataScan -> new Seeker(dataScan, personProperty.getToken()))
|
||||||
.map(executorService::submit)
|
.map(executorService::submit)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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<MergeRequestJson, MergeRequest> {
|
||||||
|
|
||||||
|
@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("Статус ПР не найден");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.app.service.executor.DataScan;
|
||||||
import org.sadtech.bot.gitlab.context.domain.entity.Comment;
|
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.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.domain.entity.Task;
|
||||||
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
import org.sadtech.bot.gitlab.context.exception.NotFoundException;
|
||||||
import org.sadtech.bot.gitlab.context.service.CommentService;
|
import org.sadtech.bot.gitlab.context.service.CommentService;
|
||||||
@@ -125,10 +125,10 @@ public class CommentAndTaskParser {
|
|||||||
.map(resultScan -> conversionService.convert(resultScan, Comment.class))
|
.map(resultScan -> conversionService.convert(resultScan, Comment.class))
|
||||||
.peek(
|
.peek(
|
||||||
comment -> {
|
comment -> {
|
||||||
final PullRequestMini pullRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId())
|
final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(comment.getPullRequestId())
|
||||||
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
||||||
comment.setUrl(generateUrl(comment.getId(), pullRequestMini.getUrl()));
|
comment.setUrl(generateUrl(comment.getId(), mergeRequestMini.getWebUrl()));
|
||||||
comment.setResponsible(pullRequestMini.getAuthorLogin());
|
// comment.setResponsible(mergeRequestMini.getAuthor());
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -140,10 +140,10 @@ public class CommentAndTaskParser {
|
|||||||
.map(resultScan -> conversionService.convert(resultScan, Task.class))
|
.map(resultScan -> conversionService.convert(resultScan, Task.class))
|
||||||
.peek(
|
.peek(
|
||||||
task -> {
|
task -> {
|
||||||
final PullRequestMini pullRequestMini = mergeRequestsService.getMiniInfo(task.getPullRequestId())
|
final MergeRequestMini mergeRequestMini = mergeRequestsService.getMiniInfo(task.getPullRequestId())
|
||||||
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
||||||
task.setResponsible(pullRequestMini.getAuthorLogin());
|
// task.setResponsible(mergeRequestMini.getAuthorLogin());
|
||||||
task.setUrl(generateUrl(task.getId(), pullRequestMini.getUrl()));
|
task.setUrl(generateUrl(task.getId(), mergeRequestMini.getWebUrl()));
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|||||||
@@ -3,13 +3,22 @@ package org.sadtech.bot.gitlab.app.service.parser;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
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.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.GitlabProperty;
|
||||||
|
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
|
||||||
import org.sadtech.bot.gitlab.sdk.domain.MergeRequestJson;
|
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.HttpHeader;
|
||||||
import org.sadtech.haiti.utils.network.HttpParse;
|
import org.sadtech.haiti.utils.network.HttpParse;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
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;
|
import static org.sadtech.haiti.utils.network.HttpParse.BEARER;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
//@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MergeRequestParserImpl {
|
public class MergeRequestParser {
|
||||||
|
|
||||||
private static final Set<MergeRequestState> OLD_STATUSES = Stream.of(MergeRequestState.MERGED, MergeRequestState.OPENED, MergeRequestState.CLOSED).collect(Collectors.toSet());
|
|
||||||
|
public static final Integer COUNT = 100;
|
||||||
|
private static final Set<MergeRequestState> OLD_STATUSES = Stream.of(
|
||||||
|
MergeRequestState.MERGED, MergeRequestState.OPENED, MergeRequestState.CLOSED
|
||||||
|
).collect(Collectors.toSet());
|
||||||
|
|
||||||
private final GitlabProperty gitlabProperty;
|
private final GitlabProperty gitlabProperty;
|
||||||
private final MergeRequestsService mergeRequestsService;
|
private final MergeRequestsService mergeRequestsService;
|
||||||
|
private final ProjectService projectService;
|
||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
|
private final PersonProperty personProperty;
|
||||||
|
|
||||||
public void parsingOldPullRequest() {
|
public void parsingOldPullRequest() {
|
||||||
// processingOldPullRequests(gitlabProperty.getUrlPullRequestOpen(), gitlabProperty.getUrlPullRequestClose());
|
// processingOldPullRequests(gitlabProperty.getUrlPullRequestOpen(), gitlabProperty.getUrlPullRequestClose());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parsingNewPullRequest() {
|
public void parsingNewMergeRequest() {
|
||||||
final List<MergeRequestJson> mergeRequestJsons = HttpParse.request(gitlabProperty.getUrlPullRequestOpen())
|
|
||||||
.header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken()))
|
int page = 0;
|
||||||
.header(ACCEPT)
|
|
||||||
.executeList(MergeRequestJson.class);
|
Sheet<Project> projectSheet = projectService.getAll(PaginationImpl.of(page, COUNT));
|
||||||
|
while (projectSheet.hasContent()) {
|
||||||
|
final List<Project> projects = projectSheet.getContent();
|
||||||
|
|
||||||
|
for (Project project : projects) {
|
||||||
|
final List<MergeRequestJson> 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<Long> jsonIds = mergeRequestJsons.stream()
|
||||||
|
.map(MergeRequestJson::getId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
final ExistsContainer<MergeRequest, Long> existsContainer = mergeRequestsService.existsById(jsonIds);
|
||||||
|
if (!existsContainer.isAllFound()) {
|
||||||
|
final List<MergeRequest> 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<PullRequest> 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<Long> getExistsPullRequestIds(String bitbucketUrl) {
|
// private Set<Long> getExistsPullRequestIds(String bitbucketUrl) {
|
||||||
@@ -99,11 +134,5 @@ public class MergeRequestParserImpl {
|
|||||||
// .collect(Collectors.toList());
|
// .collect(Collectors.toList());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) {
|
|
||||||
// return PullRequestFilter.builder()
|
|
||||||
// .bitbucketId(json.getId())
|
|
||||||
// .bitbucketRepositoryId(json.getFromRef().getRepository().getId())
|
|
||||||
// .build();
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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.context.service.ProjectService;
|
||||||
import org.sadtech.bot.gitlab.core.config.properties.GitlabProperty;
|
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.InitProperty;
|
||||||
|
import org.sadtech.bot.gitlab.core.config.properties.PersonProperty;
|
||||||
import org.sadtech.bot.gitlab.sdk.domain.ProjectJson;
|
import org.sadtech.bot.gitlab.sdk.domain.ProjectJson;
|
||||||
import org.sadtech.haiti.context.domain.ExistsContainer;
|
import org.sadtech.haiti.context.domain.ExistsContainer;
|
||||||
import org.sadtech.haiti.utils.network.HttpHeader;
|
import org.sadtech.haiti.utils.network.HttpHeader;
|
||||||
@@ -38,6 +39,7 @@ public class ProjectParser {
|
|||||||
private final ConversionService conversionService;
|
private final ConversionService conversionService;
|
||||||
|
|
||||||
private final GitlabProperty gitlabProperty;
|
private final GitlabProperty gitlabProperty;
|
||||||
|
private final PersonProperty personProperty;
|
||||||
private final CommentSchedulerProperty commentSchedulerProperty;
|
private final CommentSchedulerProperty commentSchedulerProperty;
|
||||||
private final InitProperty initProperty;
|
private final InitProperty initProperty;
|
||||||
|
|
||||||
@@ -45,7 +47,7 @@ public class ProjectParser {
|
|||||||
public void parseNewProject() {
|
public void parseNewProject() {
|
||||||
final List<ProjectJson> projectJsons = HttpParse.request(gitlabProperty.getUrlProject())
|
final List<ProjectJson> projectJsons = HttpParse.request(gitlabProperty.getUrlProject())
|
||||||
.header(ACCEPT)
|
.header(ACCEPT)
|
||||||
.header(HttpHeader.of(AUTHORIZATION, BEARER + gitlabProperty.getToken()))
|
.header(HttpHeader.of(AUTHORIZATION, BEARER + personProperty.getToken()))
|
||||||
.executeList(ProjectJson.class);
|
.executeList(ProjectJson.class);
|
||||||
|
|
||||||
final Set<Long> jsonIds = projectJsons.stream()
|
final Set<Long> jsonIds = projectJsons.stream()
|
||||||
|
|||||||
@@ -28,15 +28,16 @@ gitlab-bot:
|
|||||||
settings:
|
settings:
|
||||||
no-comment-count: 20
|
no-comment-count: 20
|
||||||
comment-count: 100
|
comment-count: 100
|
||||||
gitlab:
|
person:
|
||||||
|
telegram-id: ${TELEGRAM_PERSON_ID}
|
||||||
token: ${GITLAB_PERSONAL_TOKEN}
|
token: ${GITLAB_PERSONAL_TOKEN}
|
||||||
username: ${GITLAB_USERNAME}
|
gitlab:
|
||||||
full-name: ${GITLAB_FULLNAME}
|
|
||||||
url-project: ${GITLAB_URL}/api/v4/projects
|
url-project: ${GITLAB_URL}/api/v4/projects
|
||||||
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened
|
url-pull-request-open: ${GITLAB_URL}/api/v4/projects/{0}/merge_requests?state=opened
|
||||||
url-pull-request-close: ${GITLAB_URL}
|
url-pull-request-close: ${GITLAB_URL}
|
||||||
url-pull-request-comment: ${GITLAB_URL}
|
url-pull-request-comment: ${GITLAB_URL}
|
||||||
url-pull-request: ${GITLAB_URL}
|
url-pull-request: ${GITLAB_URL}
|
||||||
|
user-url: ${GITLAB_URL}/api/v4/user
|
||||||
teamcity:
|
teamcity:
|
||||||
token: ${TEAMCITY_ADMIN_TOKEN}
|
token: ${TEAMCITY_ADMIN_TOKEN}
|
||||||
project-url: ${TEAMCITY_URL}/app/rest/projects
|
project-url: ${TEAMCITY_URL}/app/rest/projects
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<changeSet id="2020-01-14-create-table-person" author="uPagge">
|
<changeSet id="2020-01-14-create-table-person" author="uPagge">
|
||||||
<createTable tableName="person">
|
<createTable tableName="person">
|
||||||
<column name="id">
|
<column name="id" type="int">
|
||||||
<constraints nullable="false" primaryKey="true"/>
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="username" type="varchar(100)">
|
<column name="username" type="varchar(100)">
|
||||||
@@ -34,14 +34,15 @@
|
|||||||
|
|
||||||
<changeSet id="2020-01-14-create-merge-request" author="uPagge">
|
<changeSet id="2020-01-14-create-merge-request" author="uPagge">
|
||||||
<createTable tableName="merge_request">
|
<createTable tableName="merge_request">
|
||||||
<column name="id">
|
<column name="id" type="int">
|
||||||
<constraints nullable="false" primaryKey="true"/>
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="two_id">
|
<column name="two_id" type="int">
|
||||||
<constraints nullable="false" primaryKey="true"/>
|
<constraints nullable="false"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="project_id" type="int">
|
<column name="project_id" type="int">
|
||||||
<constraints nullable="false" foreignKeyName="merge_request_project_id" references="project(id)"/>
|
<constraints nullable="false" foreignKeyName="merge_request_project_id" references="project(id)"
|
||||||
|
deleteCascade="true"/>
|
||||||
</column>
|
</column>
|
||||||
<column name="title" type="varchar(200)">
|
<column name="title" type="varchar(200)">
|
||||||
<constraints nullable="false"/>
|
<constraints nullable="false"/>
|
||||||
@@ -66,7 +67,28 @@
|
|||||||
<constraints nullable="false" foreignKeyName="merge_request_author_id_person_id"
|
<constraints nullable="false" foreignKeyName="merge_request_author_id_person_id"
|
||||||
references="person(id)"/>
|
references="person(id)"/>
|
||||||
</column>
|
</column>
|
||||||
|
<column name="assignee_id" type="int">
|
||||||
|
<constraints nullable="false" foreignKeyName="merge_request_assignee_id_person_id"
|
||||||
|
references="person(id)"/>
|
||||||
|
</column>
|
||||||
</createTable>
|
</createTable>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="2020-01-15-create-table-labels" author="uPagge">
|
||||||
|
<createTable tableName="merge_request_label">
|
||||||
|
<column name="id" type="int" autoIncrement="true">
|
||||||
|
<constraints nullable="false" primaryKey="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="merge_request_id" type="int">
|
||||||
|
<constraints nullable="false" foreignKeyName="merge_request_label_merge_request_id"
|
||||||
|
references="merge_request(id)" deleteCascade="true"/>
|
||||||
|
</column>
|
||||||
|
<column name="label" type="varchar(100)">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<addUniqueConstraint tableName="merge_request_label" columnNames="merge_request_id, label"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -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
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,16 +6,19 @@ import lombok.Setter;
|
|||||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
||||||
import org.sadtech.haiti.context.domain.BasicEntity;
|
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||||
|
|
||||||
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import javax.persistence.Enumerated;
|
import javax.persistence.Enumerated;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сущность ПуллРеквест.
|
* Сущность ПуллРеквест.
|
||||||
@@ -32,7 +35,6 @@ public class MergeRequest implements BasicEntity<Long> {
|
|||||||
@Id
|
@Id
|
||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
@EqualsAndHashCode.Include
|
@EqualsAndHashCode.Include
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "two_id")
|
@Column(name = "two_id")
|
||||||
@@ -57,14 +59,23 @@ public class MergeRequest implements BasicEntity<Long> {
|
|||||||
@Column(name = "updated_date")
|
@Column(name = "updated_date")
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
|
||||||
@Column(name = "author_id")
|
|
||||||
private Person author;
|
|
||||||
|
|
||||||
@Column(name = "web_url")
|
@Column(name = "web_url")
|
||||||
private String webUrl;
|
private String webUrl;
|
||||||
|
|
||||||
@Column(name = "conflict")
|
@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<String> labels = new HashSet<>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 12.09.2020 Добавить описание.
|
* // TODO: 12.09.2020 Добавить описание.
|
||||||
@@ -16,10 +18,10 @@ import javax.persistence.Id;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
//@Entity
|
@Entity
|
||||||
//@Table(name = "pull_request")
|
@Table(name = "merge_request")
|
||||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
public class PullRequestMini {
|
public class MergeRequestMini {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Идентификатор
|
* Идентификатор
|
||||||
@@ -33,13 +35,13 @@ public class PullRequestMini {
|
|||||||
/**
|
/**
|
||||||
* Адрес ПР
|
* Адрес ПР
|
||||||
*/
|
*/
|
||||||
@Column(name = "url")
|
@Column(name = "web_url")
|
||||||
private String url;
|
private String webUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Автор ПР
|
* Автор ПР
|
||||||
*/
|
*/
|
||||||
@Column(name = "author_login")
|
@Column(name = "author_id")
|
||||||
private String authorLogin;
|
private Long author;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,12 @@ package org.sadtech.bot.gitlab.context.domain.entity;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 14.01.2021 Добавить описание.
|
* // TODO: 14.01.2021 Добавить описание.
|
||||||
@@ -13,10 +17,20 @@ import javax.persistence.Entity;
|
|||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Person {
|
@Table(name = "person")
|
||||||
|
public class Person implements BasicEntity<Long> {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Column(name = "username")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
@Column(name = "web_url")
|
||||||
|
private String webUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ package org.sadtech.bot.gitlab.context.domain.notify;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
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.domain.entity.MergeRequest;
|
||||||
import org.sadtech.bot.gitlab.context.utils.MessageUtils;
|
import org.sadtech.bot.gitlab.context.utils.MessageUtils;
|
||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
import org.sadtech.bot.gitlab.context.utils.UpdateDataComparator;
|
import org.sadtech.bot.gitlab.context.utils.UpdateDataComparator;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,11 +28,9 @@ public class GoodMorningNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected GoodMorningNotify(
|
protected GoodMorningNotify(
|
||||||
Set<String> recipients,
|
|
||||||
List<MergeRequest> mergeRequestsReviews,
|
List<MergeRequest> mergeRequestsReviews,
|
||||||
List<MergeRequest> mergeRequestsNeedWork,
|
List<MergeRequest> mergeRequestsNeedWork,
|
||||||
String personName, String version) {
|
String personName, String version) {
|
||||||
super(EntityType.PERSON, recipients);
|
|
||||||
this.mergeRequestsReviews = mergeRequestsReviews;
|
this.mergeRequestsReviews = mergeRequestsReviews;
|
||||||
this.mergeRequestsNeedWork = mergeRequestsNeedWork;
|
this.mergeRequestsNeedWork = mergeRequestsNeedWork;
|
||||||
this.personName = personName;
|
this.personName = personName;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.sadtech.bot.gitlab.context.domain.notify;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.sadtech.bot.gitlab.context.domain.EntityType;
|
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -17,14 +16,6 @@ public abstract class Notify {
|
|||||||
'\\', '+', '`', '[', ']', '\"', '~', '*', '#', '=', '_', '>', '<'
|
'\\', '+', '`', '[', ']', '\"', '~', '*', '#', '=', '_', '>', '<'
|
||||||
).collect(Collectors.toSet());
|
).collect(Collectors.toSet());
|
||||||
|
|
||||||
protected EntityType entityType;
|
|
||||||
protected Set<String> recipients;
|
|
||||||
|
|
||||||
protected Notify(EntityType entityType, Set<String> recipients) {
|
|
||||||
this.entityType = entityType;
|
|
||||||
this.recipients = recipients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract String generateMessage();
|
public abstract String generateMessage();
|
||||||
|
|
||||||
public static String escapeMarkdown(@NonNull String s) {
|
public static String escapeMarkdown(@NonNull String s) {
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ package org.sadtech.bot.gitlab.context.domain.notify;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.sadtech.bot.gitlab.context.domain.EntityType;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 20.09.2020 Добавить описание.
|
* // TODO: 20.09.2020 Добавить описание.
|
||||||
@@ -17,8 +14,7 @@ public class SimpleTextNotify extends Notify {
|
|||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private SimpleTextNotify(EntityType entityType, Set<String> recipients, String message) {
|
private SimpleTextNotify(String message) {
|
||||||
super(entityType, recipients);
|
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ package org.sadtech.bot.gitlab.context.domain.notify.comment;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.sadtech.bot.gitlab.context.domain.Answer;
|
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.domain.notify.Notify;
|
||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -21,12 +19,10 @@ public class AnswerCommentNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected AnswerCommentNotify(
|
protected AnswerCommentNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String youMessage,
|
String youMessage,
|
||||||
String url,
|
String url,
|
||||||
List<Answer> answers
|
List<Answer> answers
|
||||||
) {
|
) {
|
||||||
super(EntityType.PERSON, recipients);
|
|
||||||
this.youMessage = youMessage;
|
this.youMessage = youMessage;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.answers = answers;
|
this.answers = answers;
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package org.sadtech.bot.gitlab.context.domain.notify.comment;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
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.domain.notify.Notify;
|
||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class CommentNotify extends Notify {
|
public class CommentNotify extends Notify {
|
||||||
@@ -18,12 +16,10 @@ public class CommentNotify extends Notify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private CommentNotify(
|
private CommentNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String url,
|
String url,
|
||||||
String authorName,
|
String authorName,
|
||||||
String message
|
String message
|
||||||
) {
|
) {
|
||||||
super(EntityType.PERSON, recipients);
|
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
|||||||
@@ -5,29 +5,26 @@ import lombok.Getter;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ConflictPrNotify extends PrNotify {
|
public class ConflictPrNotify extends PrNotify {
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private ConflictPrNotify(
|
private ConflictPrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String projectKey,
|
String projectKey
|
||||||
String repositorySlug
|
|
||||||
) {
|
) {
|
||||||
super(recipients, projectKey, repositorySlug, name, url);
|
super(projectKey, name, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Внимание конфликт в ПР | {4} | {5}*" +
|
"{0} *Внимание конфликт в ПР | {4}*" +
|
||||||
"{1}" +
|
"{1}" +
|
||||||
"[{2}]({3})\n\n",
|
"[{2}]({3})\n\n",
|
||||||
Smile.DANGEROUS, Smile.HR, title, url, projectKey, repositorySlug
|
Smile.DANGEROUS, Smile.HR, title, url, projectName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import lombok.Getter;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 11.10.2020 Добавить описание.
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
@@ -17,21 +16,20 @@ public class ForgottenSmartPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected ForgottenSmartPrNotify(
|
protected ForgottenSmartPrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String projectKey,
|
String projectName,
|
||||||
String repositorySlug
|
String repositorySlug
|
||||||
) {
|
) {
|
||||||
super(recipients, projectKey, repositorySlug, title, url);
|
super(projectName, title, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Напоминание о просмотре PullRequest | {4} | {5}*" +
|
"{0} *Напоминание о просмотре PullRequest | {4}*" +
|
||||||
"{3}[{1}]({2})",
|
"{3}[{1}]({2})",
|
||||||
Smile.SMART, title, url, Smile.HR, projectKey, repositorySlug
|
Smile.SMART, title, url, Smile.HR, projectName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,37 +6,45 @@ import org.sadtech.bot.gitlab.context.utils.Smile;
|
|||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class NewPrNotify extends PrNotify {
|
public class NewPrNotify extends PrNotify {
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
private final String author;
|
private final String author;
|
||||||
|
private final Set<String> labels;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private NewPrNotify(
|
private NewPrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String description,
|
String description,
|
||||||
String author,
|
String author,
|
||||||
String projectKey,
|
String projectName,
|
||||||
String repositorySlug
|
Set<String> labels) {
|
||||||
) {
|
super(projectName, title, url);
|
||||||
super(recipients, projectKey, repositorySlug, title, url);
|
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
|
this.labels = labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
|
String labelText = labels.stream()
|
||||||
|
.map(label -> "#" + label)
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
|
if (!labelText.isEmpty()) {
|
||||||
|
labelText = "\n\n" + labelText;
|
||||||
|
}
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Новый PullRequest | {7} | {8}*{1}" +
|
"{0} *Новый PullRequest | {1}*{2}" +
|
||||||
"[{2}]({3})" +
|
"[{3}]({4})" +
|
||||||
"{1}{4}{5}: {6}\n\n",
|
"{5}" +
|
||||||
Smile.FUN, Smile.HR, title, url,
|
"{2}{7}: {8}\n\n",
|
||||||
|
Smile.FUN, projectName, Smile.HR, title, url, labelText,
|
||||||
(description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "",
|
(description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "",
|
||||||
Smile.AUTHOR, author, projectKey, repositorySlug
|
Smile.AUTHOR, author
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,21 @@
|
|||||||
package org.sadtech.bot.gitlab.context.domain.notify.pullrequest;
|
package org.sadtech.bot.gitlab.context.domain.notify.pullrequest;
|
||||||
|
|
||||||
import lombok.Getter;
|
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.domain.notify.Notify;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public abstract class PrNotify extends Notify {
|
public abstract class PrNotify extends Notify {
|
||||||
|
|
||||||
protected final String projectKey;
|
protected final String projectName;
|
||||||
protected final String repositorySlug;
|
|
||||||
protected final String title;
|
protected final String title;
|
||||||
protected final String url;
|
protected final String url;
|
||||||
|
|
||||||
protected PrNotify(
|
protected PrNotify(
|
||||||
Set<String> recipients,
|
String projectName,
|
||||||
String projectKey,
|
|
||||||
String repositorySlug,
|
|
||||||
String title,
|
String title,
|
||||||
String url
|
String url
|
||||||
) {
|
) {
|
||||||
super(EntityType.PERSON, recipients);
|
this.projectName = projectName;
|
||||||
this.projectKey = projectKey;
|
|
||||||
this.repositorySlug = repositorySlug;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.sadtech.bot.gitlab.context.domain.entity.Reviewer;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 11.10.2020 Добавить описание.
|
* // TODO: 11.10.2020 Добавить описание.
|
||||||
@@ -20,26 +19,25 @@ public class SmartPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected SmartPrNotify(
|
protected SmartPrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String title,
|
String title,
|
||||||
String url,
|
String url,
|
||||||
String projectKey,
|
String projectName,
|
||||||
String repositorySlug,
|
String repositorySlug,
|
||||||
Reviewer reviewerTriggered
|
Reviewer reviewerTriggered
|
||||||
) {
|
) {
|
||||||
super(recipients, projectKey, repositorySlug, title, url);
|
super(projectName, title, url);
|
||||||
this.reviewerTriggered = reviewerTriggered;
|
this.reviewerTriggered = reviewerTriggered;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Напоминание о PullRequest | {6} | {7}*" +
|
"{0} *Напоминание о PullRequest | {6}*" +
|
||||||
"{3}[{1}]({2})" +
|
"{3}[{1}]({2})" +
|
||||||
"{3}" +
|
"{3}" +
|
||||||
"{4} изменил свое решение на {5}\n\n",
|
"{4} изменил свое решение на {5}\n\n",
|
||||||
Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(),
|
Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(),
|
||||||
projectKey, repositorySlug
|
projectName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class StatusPrNotify extends PrNotify {
|
public class StatusPrNotify extends PrNotify {
|
||||||
@@ -16,15 +15,13 @@ public class StatusPrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private StatusPrNotify(
|
private StatusPrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String projectKey,
|
String projectName,
|
||||||
String repositorySlug,
|
|
||||||
MergeRequestState oldStatus,
|
MergeRequestState oldStatus,
|
||||||
MergeRequestState newStatus
|
MergeRequestState newStatus
|
||||||
) {
|
) {
|
||||||
super(recipients, projectKey, repositorySlug, name, url);
|
super(projectName, name, url);
|
||||||
this.oldStatus = oldStatus;
|
this.oldStatus = oldStatus;
|
||||||
this.newStatus = newStatus;
|
this.newStatus = newStatus;
|
||||||
}
|
}
|
||||||
@@ -32,10 +29,10 @@ public class StatusPrNotify extends PrNotify {
|
|||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Изменился статус PullRequest | {7} | {8}*{1}" +
|
"{0} *Изменился статус PullRequest | {7}*{1}" +
|
||||||
"[{2}]({3}){1}" +
|
"[{2}]({3}){1}" +
|
||||||
"{4} {5} {6}\n\n",
|
"{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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import lombok.Getter;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class UpdatePrNotify extends PrNotify {
|
public class UpdatePrNotify extends PrNotify {
|
||||||
@@ -14,25 +13,23 @@ public class UpdatePrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private UpdatePrNotify(
|
private UpdatePrNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String name,
|
String name,
|
||||||
String url,
|
String url,
|
||||||
String author,
|
String author,
|
||||||
String projectKey,
|
String projectKey
|
||||||
String repositorySlug
|
|
||||||
) {
|
) {
|
||||||
super(recipients, projectKey, repositorySlug, name, url);
|
super(projectKey, name, url);
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
return MessageFormat.format(
|
||||||
"{0} *Обновление PullRequest | {6} | {7}*{3}" +
|
"{0} *Обновление PullRequest | {6}*{3}" +
|
||||||
"[{1}]({2})" +
|
"[{1}]({2})" +
|
||||||
"{3}" +
|
"{3}" +
|
||||||
"{4}: {5}\n\n",
|
"{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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import lombok.Builder;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 10.09.2020 Добавить описание.
|
* // TODO: 10.09.2020 Добавить описание.
|
||||||
@@ -15,12 +14,11 @@ public class TaskCloseNotify extends TaskNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected TaskCloseNotify(
|
protected TaskCloseNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(recipients, authorName, url, messageTask);
|
super(authorName, url, messageTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import lombok.Getter;
|
|||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 10.09.2020 Добавить описание.
|
* // TODO: 10.09.2020 Добавить описание.
|
||||||
@@ -17,12 +16,11 @@ public class TaskNewNotify extends TaskNotify {
|
|||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
protected TaskNewNotify(
|
protected TaskNewNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(recipients, authorName, url, messageTask);
|
super(authorName, url, messageTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,11 +2,8 @@ package org.sadtech.bot.gitlab.context.domain.notify.task;
|
|||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
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.domain.notify.Notify;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public abstract class TaskNotify extends Notify {
|
public abstract class TaskNotify extends Notify {
|
||||||
@@ -16,12 +13,10 @@ public abstract class TaskNotify extends Notify {
|
|||||||
protected final String messageTask;
|
protected final String messageTask;
|
||||||
|
|
||||||
protected TaskNotify(
|
protected TaskNotify(
|
||||||
Set<String> recipients,
|
|
||||||
String authorName,
|
String authorName,
|
||||||
String url,
|
String url,
|
||||||
String messageTask
|
String messageTask
|
||||||
) {
|
) {
|
||||||
super(EntityType.PERSON, recipients);
|
|
||||||
this.authorName = authorName;
|
this.authorName = authorName;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.messageTask = messageTask;
|
this.messageTask = messageTask;
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ import lombok.NonNull;
|
|||||||
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
||||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
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.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.context.repository.SimpleManagerRepository;
|
||||||
import org.sadtech.haiti.filter.FilterOperation;
|
import org.sadtech.haiti.filter.FilterOperation;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface PullRequestsRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> {
|
public interface MergeRequestRepository extends SimpleManagerRepository<MergeRequest, Long>, FilterOperation<MergeRequest> {
|
||||||
|
|
||||||
Set<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses);
|
Set<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses);
|
||||||
|
|
||||||
Optional<PullRequestMini> findMiniInfoById(@NonNull Long id);
|
Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
package org.sadtech.bot.gitlab.context.repository;
|
package org.sadtech.bot.gitlab.context.repository;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting;
|
import org.sadtech.bot.gitlab.context.domain.entity.NotifySetting;
|
||||||
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 20.09.2020 Добавить описание.
|
* // TODO: 20.09.2020 Добавить описание.
|
||||||
*
|
*
|
||||||
@@ -13,8 +10,4 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public interface NotifySettingRepository extends SimpleManagerRepository<NotifySetting, String> {
|
public interface NotifySettingRepository extends SimpleManagerRepository<NotifySetting, String> {
|
||||||
|
|
||||||
boolean isNotification(@NonNull String login);
|
|
||||||
|
|
||||||
Set<String> isNotification(@NonNull Set<String> logins);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Person, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<Long> getAllTelegramIdByKey(@NonNull Set<String> keys);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ import lombok.NonNull;
|
|||||||
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
||||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
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.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.bot.gitlab.context.domain.filter.PullRequestFilter;
|
||||||
import org.sadtech.haiti.context.service.SimpleManagerService;
|
import org.sadtech.haiti.context.service.SimpleManagerService;
|
||||||
import org.sadtech.haiti.filter.FilterService;
|
import org.sadtech.haiti.filter.FilterService;
|
||||||
@@ -22,6 +22,6 @@ public interface MergeRequestsService extends SimpleManagerService<MergeRequest,
|
|||||||
*/
|
*/
|
||||||
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
|
Set<IdAndStatusPr> getAllId(Set<MergeRequestState> statuses);
|
||||||
|
|
||||||
Optional<PullRequestMini> getMiniInfo(@NonNull Long pullRequestId);
|
Optional<MergeRequestMini> getMiniInfo(@NonNull Long pullRequestId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package org.sadtech.bot.gitlab.context.service;
|
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 org.sadtech.bot.gitlab.context.domain.notify.Notify;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сервис по работе с изменениями в битбакете.
|
* Сервис по работе с изменениями в битбакете.
|
||||||
*
|
*
|
||||||
@@ -16,16 +12,4 @@ public interface NotifyService {
|
|||||||
|
|
||||||
<T extends Notify> void send(T notify);
|
<T extends Notify> void send(T notify);
|
||||||
|
|
||||||
/**
|
|
||||||
* Сохранить настройки уведомлений
|
|
||||||
*/
|
|
||||||
void saveSettings(@NonNull NotifySetting setting);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить настройки уведомлений по логину.
|
|
||||||
*
|
|
||||||
* @param login Логин пользователя
|
|
||||||
*/
|
|
||||||
Optional<NotifySetting> getSetting(@NonNull String login);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Person, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,12 +16,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@ConfigurationProperties("gitlab-bot.gitlab")
|
@ConfigurationProperties("gitlab-bot.gitlab")
|
||||||
public class GitlabProperty {
|
public class GitlabProperty {
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
private String fullName;
|
|
||||||
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Адрес, по которому можно получить открытые ПР
|
* Адрес, по которому можно получить открытые ПР
|
||||||
*/
|
*/
|
||||||
@@ -44,4 +38,6 @@ public class GitlabProperty {
|
|||||||
|
|
||||||
private String urlProject;
|
private String urlProject;
|
||||||
|
|
||||||
|
private String userUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<Long> getAllTelegramIdByKey(@NonNull Set<String> keys) {
|
|
||||||
return chatRepository.findAllTelegramIdByKey(keys);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ import org.springframework.core.convert.ConversionService;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -81,7 +80,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
|||||||
CommentNotify.builder()
|
CommentNotify.builder()
|
||||||
.authorName(comment.getAuthor())
|
.authorName(comment.getAuthor())
|
||||||
.url(comment.getUrl())
|
.url(comment.getUrl())
|
||||||
.recipients(recipientsLogins)
|
|
||||||
.message(comment.getMessage())
|
.message(comment.getMessage())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
@@ -131,7 +129,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
|||||||
if (!newAnswers.isEmpty()) {
|
if (!newAnswers.isEmpty()) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
AnswerCommentNotify.builder()
|
AnswerCommentNotify.builder()
|
||||||
.recipients(Collections.singleton(newComment.getAuthor()))
|
|
||||||
.url(oldComment.getUrl())
|
.url(oldComment.getUrl())
|
||||||
.youMessage(newComment.getMessage())
|
.youMessage(newComment.getMessage())
|
||||||
.answers(
|
.answers(
|
||||||
|
|||||||
@@ -3,62 +3,81 @@ package org.sadtech.bot.gitlab.core.service.impl;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
import org.sadtech.bot.gitlab.context.domain.IdAndStatusPr;
|
||||||
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
|
||||||
|
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
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.Reviewer;
|
import org.sadtech.bot.gitlab.context.domain.entity.Project;
|
||||||
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
|
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
|
||||||
|
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.ConflictPrNotify;
|
||||||
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.NewPrNotify;
|
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.NewPrNotify;
|
||||||
import org.sadtech.bot.gitlab.context.repository.PullRequestsRepository;
|
import org.sadtech.bot.gitlab.context.domain.notify.pullrequest.StatusPrNotify;
|
||||||
|
import org.sadtech.bot.gitlab.context.repository.MergeRequestRepository;
|
||||||
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
|
import org.sadtech.bot.gitlab.context.service.MergeRequestsService;
|
||||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||||
import org.sadtech.haiti.context.domain.ExistsContainer;
|
import org.sadtech.bot.gitlab.context.service.PersonService;
|
||||||
|
import org.sadtech.bot.gitlab.context.service.ProjectService;
|
||||||
|
import org.sadtech.haiti.context.exception.NotFoundException;
|
||||||
import org.sadtech.haiti.context.page.Pagination;
|
import org.sadtech.haiti.context.page.Pagination;
|
||||||
import org.sadtech.haiti.context.page.Sheet;
|
import org.sadtech.haiti.context.page.Sheet;
|
||||||
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
||||||
import org.sadtech.haiti.core.util.Assert;
|
|
||||||
import org.sadtech.haiti.filter.FilterService;
|
import org.sadtech.haiti.filter.FilterService;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
//@Service
|
@Service
|
||||||
public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<MergeRequest, Long> implements MergeRequestsService {
|
public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<MergeRequest, Long> implements MergeRequestsService {
|
||||||
|
|
||||||
protected final NotifyService notifyService;
|
private final NotifyService notifyService;
|
||||||
protected final PullRequestsRepository pullRequestsRepository;
|
private final MergeRequestRepository mergeRequestRepository;
|
||||||
protected final FilterService<MergeRequest, PullRequestFilter> filterService;
|
private final PersonService personService;
|
||||||
|
private final FilterService<MergeRequest, PullRequestFilter> filterService;
|
||||||
|
private final ProjectService projectService;
|
||||||
|
|
||||||
|
private final PersonInformation personInformation;
|
||||||
|
|
||||||
protected MergeRequestsServiceImpl(
|
protected MergeRequestsServiceImpl(
|
||||||
PullRequestsRepository pullRequestsRepository,
|
MergeRequestRepository mergeRequestRepository,
|
||||||
NotifyService notifyService,
|
NotifyService notifyService,
|
||||||
@Qualifier("pullRequestFilterService") FilterService<MergeRequest, PullRequestFilter> pullRequestsFilterService
|
PersonService personService,
|
||||||
|
@Qualifier("mergeRequestFilterService") FilterService<MergeRequest, PullRequestFilter> filterService,
|
||||||
|
ProjectService projectService,
|
||||||
|
PersonInformation personInformation
|
||||||
) {
|
) {
|
||||||
super(pullRequestsRepository);
|
super(mergeRequestRepository);
|
||||||
this.notifyService = notifyService;
|
this.notifyService = notifyService;
|
||||||
this.pullRequestsRepository = pullRequestsRepository;
|
this.mergeRequestRepository = mergeRequestRepository;
|
||||||
this.filterService = pullRequestsFilterService;
|
this.personService = personService;
|
||||||
|
this.filterService = filterService;
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.personInformation = personInformation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MergeRequest create(@NonNull MergeRequest mergeRequest) {
|
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);
|
if (!personInformation.getId().equals(newMergeRequest.getAuthor().getId())) {
|
||||||
|
final String projectName = projectService.getById(newMergeRequest.getProjectId())
|
||||||
notifyService.send(
|
.orElseThrow(() -> new NotFoundException("Проект не найден"))
|
||||||
NewPrNotify.builder()
|
.getName();
|
||||||
.author(newMergeRequest.getAuthor().getName())
|
notifyService.send(
|
||||||
.description(newMergeRequest.getDescription())
|
NewPrNotify.builder()
|
||||||
.title(newMergeRequest.getTitle())
|
.projectName(projectName)
|
||||||
.url(newMergeRequest.getWebUrl())
|
.labels(newMergeRequest.getLabels())
|
||||||
.build()
|
.author(newMergeRequest.getAuthor().getName())
|
||||||
);
|
.description(newMergeRequest.getDescription())
|
||||||
|
.title(newMergeRequest.getTitle())
|
||||||
|
.url(newMergeRequest.getWebUrl())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
return newMergeRequest;
|
return newMergeRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,16 +85,14 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
|||||||
public MergeRequest update(@NonNull MergeRequest mergeRequest) {
|
public MergeRequest update(@NonNull MergeRequest mergeRequest) {
|
||||||
final MergeRequest oldMergeRequest = findAndFillId(mergeRequest);
|
final MergeRequest oldMergeRequest = findAndFillId(mergeRequest);
|
||||||
|
|
||||||
forgottenNotification(oldMergeRequest);
|
// forgottenNotification(oldMergeRequest);
|
||||||
|
|
||||||
oldMergeRequest.setTitle(mergeRequest.getTitle());
|
final Project project = projectService.getById(mergeRequest.getProjectId())
|
||||||
oldMergeRequest.setDescription(mergeRequest.getDescription());
|
.orElseThrow(() -> new NotFoundException("Проект не найден"));
|
||||||
updateReviewers(oldMergeRequest, mergeRequest);
|
notifyStatus(oldMergeRequest, mergeRequest, project);
|
||||||
updateBitbucketVersion(oldMergeRequest, mergeRequest);
|
notifyConflict(oldMergeRequest, mergeRequest, project);
|
||||||
updateStatus(oldMergeRequest, mergeRequest);
|
|
||||||
updateConflict(oldMergeRequest, mergeRequest);
|
|
||||||
|
|
||||||
return pullRequestsRepository.save(oldMergeRequest);
|
return mergeRequestRepository.save(mergeRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void forgottenNotification(MergeRequest mergeRequest) {
|
protected void forgottenNotification(MergeRequest mergeRequest) {
|
||||||
@@ -103,138 +120,39 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateBitbucketVersion(MergeRequest oldMergeRequest, MergeRequest mergeRequest) {
|
protected void notifyConflict(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
||||||
// if (
|
if (
|
||||||
// !oldMergeRequest.getBitbucketVersion().equals(mergeRequest.getBitbucketVersion())
|
!oldMergeRequest.isConflict()
|
||||||
// ) {
|
&& mergeRequest.isConflict()
|
||||||
// oldMergeRequest.setBitbucketVersion(mergeRequest.getBitbucketVersion());
|
&& oldMergeRequest.getAuthor().getId().equals(personInformation.getId())
|
||||||
// if (PullRequestStatus.OPEN.equals(mergeRequest.getStatus())) {
|
) {
|
||||||
// notifyService.send(
|
notifyService.send(
|
||||||
// UpdatePrNotify.builder()
|
ConflictPrNotify.builder()
|
||||||
// .author(oldMergeRequest.getAuthorLogin())
|
.name(mergeRequest.getTitle())
|
||||||
// .name(mergeRequest.getTitle())
|
.url(mergeRequest.getWebUrl())
|
||||||
// .recipients(
|
.projectKey(project.getName())
|
||||||
// mergeRequest.getReviewers().stream()
|
.build()
|
||||||
// .map(Reviewer::getPersonLogin)
|
);
|
||||||
// .collect(Collectors.toSet())
|
}
|
||||||
// )
|
|
||||||
// .url(oldMergeRequest.getUrl())
|
|
||||||
// .projectKey(oldMergeRequest.getProjectKey())
|
|
||||||
// .repositorySlug(oldMergeRequest.getRepositorySlug())
|
|
||||||
// .build()
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateConflict(MergeRequest oldMergeRequest, MergeRequest mergeRequest) {
|
protected void notifyStatus(MergeRequest oldMergeRequest, MergeRequest newMergeRequest, Project project) {
|
||||||
// if (!oldMergeRequest.isConflict() && mergeRequest.isConflict()) {
|
final MergeRequestState oldStatus = oldMergeRequest.getState();
|
||||||
// notifyService.send(
|
final MergeRequestState newStatus = newMergeRequest.getState();
|
||||||
// ConflictPrNotify.builder()
|
if (
|
||||||
// .name(mergeRequest.getTitle())
|
!oldStatus.equals(newStatus)
|
||||||
// .url(mergeRequest.getUrl())
|
&& oldMergeRequest.getAuthor().getId().equals(personInformation.getId())
|
||||||
// .projectKey(mergeRequest.getProjectKey())
|
) {
|
||||||
// .repositorySlug(mergeRequest.getRepositorySlug())
|
notifyService.send(
|
||||||
// .recipients(Collections.singleton(mergeRequest.getAuthorLogin()))
|
StatusPrNotify.builder()
|
||||||
// .build()
|
.name(newMergeRequest.getTitle())
|
||||||
// );
|
.url(oldMergeRequest.getWebUrl())
|
||||||
// }
|
.projectName(project.getName())
|
||||||
// oldMergeRequest.setConflict(mergeRequest.isConflict());
|
.newStatus(newStatus)
|
||||||
}
|
.oldStatus(oldStatus)
|
||||||
|
.build()
|
||||||
protected void updateStatus(MergeRequest oldMergeRequest, MergeRequest newMergeRequest) {
|
);
|
||||||
// final PullRequestStatus oldStatus = oldMergeRequest.getStatus();
|
}
|
||||||
// final PullRequestStatus newStatus = newMergeRequest.getStatus();
|
|
||||||
// if (!oldStatus.equals(newStatus)) {
|
|
||||||
// notifyService.send(
|
|
||||||
// StatusPrNotify.builder()
|
|
||||||
// .name(newMergeRequest.getTitle())
|
|
||||||
// .url(oldMergeRequest.getUrl())
|
|
||||||
// .projectKey(oldMergeRequest.getProjectKey())
|
|
||||||
// .repositorySlug(oldMergeRequest.getRepositorySlug())
|
|
||||||
// .newStatus(newStatus)
|
|
||||||
// .oldStatus(oldStatus)
|
|
||||||
// .recipients(Collections.singleton(oldMergeRequest.getAuthorLogin()))
|
|
||||||
// .build()
|
|
||||||
// );
|
|
||||||
// oldMergeRequest.setStatus(newStatus);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void updateReviewers(MergeRequest oldMergeRequest, MergeRequest newMergeRequest) {
|
|
||||||
// final Map<String, Reviewer> oldReviewers = oldMergeRequest.getReviewers().stream()
|
|
||||||
// .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer));
|
|
||||||
// final Map<String, Reviewer> newReviewers = newMergeRequest.getReviewers().stream()
|
|
||||||
// .collect(Collectors.toMap(Reviewer::getPersonLogin, reviewer -> reviewer));
|
|
||||||
// final List<ReviewerChange> 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<String> 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<Reviewer> 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 boolean enoughTimHasPassedSinceUpdatePr(LocalDateTime updateDate) {
|
protected boolean enoughTimHasPassedSinceUpdatePr(LocalDateTime updateDate) {
|
||||||
@@ -247,8 +165,8 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<PullRequestMini> getMiniInfo(@NonNull Long pullRequestId) {
|
public Optional<MergeRequestMini> getMiniInfo(@NonNull Long pullRequestId) {
|
||||||
return pullRequestsRepository.findMiniInfoById(pullRequestId);
|
return mergeRequestRepository.findMiniInfoById(pullRequestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -282,9 +200,4 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ExistsContainer<MergeRequest, Long> existsById(@NonNull Collection<Long> collection) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,20 @@
|
|||||||
package org.sadtech.bot.gitlab.core.service.impl;
|
package org.sadtech.bot.gitlab.core.service.impl;
|
||||||
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
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.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.MessageSendService;
|
||||||
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
import org.sadtech.bot.gitlab.context.service.NotifyService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Optional;
|
@Service
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
//@Service
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class NotifyServiceImpl implements NotifyService {
|
public class NotifyServiceImpl implements NotifyService {
|
||||||
|
|
||||||
private final NotifySettingRepository settingRepository;
|
|
||||||
|
|
||||||
private final MessageSendService messageSendService;
|
private final MessageSendService messageSendService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Notify> void send(T notify) {
|
public <T extends Notify> void send(T notify) {
|
||||||
if (EntityType.PERSON.equals(notify.getEntityType())) {
|
|
||||||
final Set<String> recipientLogins = settingRepository.isNotification(notify.getRecipients());
|
|
||||||
notify.setRecipients(recipientLogins);
|
|
||||||
}
|
|
||||||
messageSendService.send(notify);
|
messageSendService.send(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveSettings(@NonNull NotifySetting setting) {
|
|
||||||
settingRepository.save(setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<NotifySetting> getSetting(@NonNull String login) {
|
|
||||||
return settingRepository.findById(login);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Person, Long> 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,7 +23,6 @@ import org.springframework.core.convert.ConversionService;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -95,7 +94,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
.messageTask(task.getDescription())
|
.messageTask(task.getDescription())
|
||||||
.authorName(oldTask.getAuthor())
|
.authorName(oldTask.getAuthor())
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.recipients(Collections.singleton(oldTask.getResponsible()))
|
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@@ -105,7 +103,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
.messageTask(oldTask.getDescription())
|
.messageTask(oldTask.getDescription())
|
||||||
.authorName(oldTask.getAuthor())
|
.authorName(oldTask.getAuthor())
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.recipients(Collections.singleton(oldTask.getAuthor()))
|
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@@ -129,7 +126,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
if (!newAnswers.isEmpty()) {
|
if (!newAnswers.isEmpty()) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
AnswerCommentNotify.builder()
|
AnswerCommentNotify.builder()
|
||||||
.recipients(Collections.singleton(oldTask.getAuthor()))
|
|
||||||
.url(oldTask.getUrl())
|
.url(oldTask.getUrl())
|
||||||
.youMessage(oldTask.getDescription())
|
.youMessage(oldTask.getDescription())
|
||||||
.answers(
|
.answers(
|
||||||
@@ -192,7 +188,6 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
|||||||
CommentNotify.builder()
|
CommentNotify.builder()
|
||||||
.authorName(task.getAuthor())
|
.authorName(task.getAuthor())
|
||||||
.url(task.getUrl())
|
.url(task.getUrl())
|
||||||
.recipients(recipientsLogins)
|
|
||||||
.message(task.getDescription())
|
.message(task.getDescription())
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ package org.sadtech.bot.gitlab.core.service.impl.filter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
|
||||||
import org.sadtech.bot.gitlab.context.domain.filter.PullRequestFilter;
|
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.core.service.AbstractFilterService;
|
||||||
import org.sadtech.haiti.filter.Filter;
|
import org.sadtech.haiti.filter.Filter;
|
||||||
import org.sadtech.haiti.filter.FilterQuery;
|
import org.sadtech.haiti.filter.FilterQuery;
|
||||||
import org.sadtech.haiti.filter.criteria.CriteriaFilter;
|
import org.sadtech.haiti.filter.criteria.CriteriaFilter;
|
||||||
import org.sadtech.haiti.filter.criteria.CriteriaQuery;
|
import org.sadtech.haiti.filter.criteria.CriteriaQuery;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
//@Service
|
@Service
|
||||||
public class PullRequestFilterService extends AbstractFilterService<MergeRequest, PullRequestFilter> {
|
public class MergeRequestFilterService extends AbstractFilterService<MergeRequest, PullRequestFilter> {
|
||||||
|
|
||||||
public PullRequestFilterService(PullRequestsRepository filterOperation) {
|
public MergeRequestFilterService(MergeRequestRepository filterOperation) {
|
||||||
super(filterOperation);
|
super(filterOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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<MergeRequest, Long> 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<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses) {
|
||||||
|
return repositoryJpa.findAllIdByStateIn(statuses);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<MergeRequestMini> findMiniInfoById(@NonNull Long id) {
|
||||||
|
return mergeRequestMiniJpaRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
package org.sadtech.bot.gitlab.data.impl;
|
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.domain.entity.NotifySetting;
|
||||||
import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository;
|
import org.sadtech.bot.gitlab.context.repository.NotifySettingRepository;
|
||||||
import org.sadtech.bot.gitlab.data.jpa.NotifySettingJpaRepository;
|
import org.sadtech.bot.gitlab.data.jpa.NotifySettingJpaRepository;
|
||||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 20.09.2020 Добавить описание.
|
* // TODO: 20.09.2020 Добавить описание.
|
||||||
*
|
*
|
||||||
@@ -24,14 +20,4 @@ public class NotifySettingRepositoryImpl extends AbstractSimpleManagerRepository
|
|||||||
this.jpaRepository = jpaRepository;
|
this.jpaRepository = jpaRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNotification(@NonNull String login) {
|
|
||||||
return jpaRepository.findByLoginAndStartReceivingAfter(login, LocalDateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> isNotification(@NonNull Set<String> logins) {
|
|
||||||
return jpaRepository.findAllByLoginInAndStartReceivingAfter(logins, LocalDateTime.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Person, Long> implements PersonRepository {
|
||||||
|
|
||||||
|
public PersonRepositoryImpl(JpaRepository<Person, Long> jpaRepository) {
|
||||||
|
super(jpaRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<MergeRequest, Long> 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<IdAndStatusPr> findAllIdByStatusIn(Set<MergeRequestState> statuses) {
|
|
||||||
return repositoryJpa.findAllIdByStatusIn(statuses);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<PullRequestMini> findMiniInfoById(@NonNull Long id) {
|
|
||||||
return pullRequestMiniRepositoryJpa.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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<MergeRequest, Long> {
|
||||||
|
|
||||||
|
Set<MergeRequest> findAllByIdIn(Set<Long> ids);
|
||||||
|
|
||||||
|
void deleteAllByIdIn(Collection<Long> id);
|
||||||
|
|
||||||
|
@Query("SELECT new org.sadtech.bot.gitlab.context.domain.IdAndStatusPr(p.id, p.state) FROM MergeRequest p WHERE p.state IN :statuses")
|
||||||
|
Set<IdAndStatusPr> findAllIdByStateIn(@Param("statuses") Set<MergeRequestState> statuses);
|
||||||
|
|
||||||
|
@Query("SELECT p.id from MergeRequest p")
|
||||||
|
Set<Long> findAllIds();
|
||||||
|
|
||||||
|
@Query("SELECT p.author.id from MergeRequest p WHERE p.id = :id")
|
||||||
|
Optional<String> findAuthorById(@Param("id") Long id);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<MergeRequestMini, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<Person, Long> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<PullRequestMini, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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<MergeRequest, Long> {
|
|
||||||
|
|
||||||
Set<MergeRequest> findAllByIdIn(Set<Long> ids);
|
|
||||||
|
|
||||||
Boolean existsByBitbucketIdAndRepositoryId(Long bitbucketId, Long repositoryId);
|
|
||||||
|
|
||||||
// @Query("SELECT p.id FROM PullRequest p WHERE p.bitbucketId=:bitbucketId AND p.repositoryId=:repositoryId")
|
|
||||||
Optional<Long> findIdByBitbucketIdAndRepositoryId(@Param("bitbucketId") Long bitbucketId, @Param("repositoryId") Long repositoryId);
|
|
||||||
|
|
||||||
void deleteAllByIdIn(Collection<Long> id);
|
|
||||||
|
|
||||||
// @Query("SELECT new org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses")
|
|
||||||
Set<IdAndStatusPr> findAllIdByStatusIn(@Param("statuses") Set<MergeRequestState> statuses);
|
|
||||||
|
|
||||||
// @Query("SELECT p.id from PullRequest p")
|
|
||||||
Set<Long> findAllIds();
|
|
||||||
|
|
||||||
// @Query("SELECT p.authorLogin from PullRequest p WHERE p.id = :id")
|
|
||||||
Optional<String> findAuthorById(@Param("id") Long id);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,10 +2,13 @@ package org.sadtech.bot.gitlab.sdk.domain;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
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 lombok.Data;
|
||||||
import org.sadtech.bot.gitlab.sdk.utils.LocalDateTimeFromEpochDeserializer;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* TODO: Добавить описание класса.
|
||||||
@@ -24,22 +27,27 @@ public class MergeRequestJson {
|
|||||||
private Long projectId;
|
private Long projectId;
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private PullRequestState state;
|
private MergeRequestStateJson state;
|
||||||
|
|
||||||
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
|
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||||
@JsonProperty("created_at")
|
@JsonProperty("created_at")
|
||||||
@JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
|
|
||||||
private LocalDateTime createdDate;
|
private LocalDateTime createdDate;
|
||||||
|
|
||||||
@JsonProperty("updated_at")
|
@JsonProperty("updated_at")
|
||||||
@JsonDeserialize(using = LocalDateTimeFromEpochDeserializer.class)
|
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||||
|
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||||
private LocalDateTime updatedDate;
|
private LocalDateTime updatedDate;
|
||||||
|
|
||||||
private AuthorJson author;
|
private PersonJson author;
|
||||||
|
private PersonJson assignee;
|
||||||
|
|
||||||
@JsonProperty("web_url")
|
@JsonProperty("web_url")
|
||||||
private String webUrl;
|
private String webUrl;
|
||||||
|
|
||||||
@JsonProperty("has_conflicts")
|
@JsonProperty("has_conflicts")
|
||||||
private String conflicts;
|
private boolean conflicts;
|
||||||
|
|
||||||
|
private Set<String> labels;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,11 +9,11 @@ import lombok.Data;
|
|||||||
* @author upagge [31.01.2020]
|
* @author upagge [31.01.2020]
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class AuthorJson {
|
public class PersonJson {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String userName;
|
private String username;
|
||||||
|
|
||||||
@JsonProperty("web_url")
|
@JsonProperty("web_url")
|
||||||
private String webUrl;
|
private String webUrl;
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package org.sadtech.bot.gitlab.sdk.domain;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Добавить комментарий енума.
|
|
||||||
*
|
|
||||||
* @author upagge [01.02.2020]
|
|
||||||
*/
|
|
||||||
public enum PullRequestState {
|
|
||||||
|
|
||||||
OPENED, MERGED, DECLINED
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,12 @@ package org.sadtech.bot.gitlab.teamcity.core.domain;
|
|||||||
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
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.domain.notify.Notify;
|
||||||
import org.sadtech.bot.gitlab.context.utils.Smile;
|
import org.sadtech.bot.gitlab.context.utils.Smile;
|
||||||
import org.sadtech.bot.gitlab.teamcity.core.domain.entity.BuildShort;
|
import org.sadtech.bot.gitlab.teamcity.core.domain.entity.BuildShort;
|
||||||
import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus;
|
import org.sadtech.bot.gitlab.teamcity.sdk.BuildStatus;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 21.09.2020 Добавить описание.
|
* // TODO: 21.09.2020 Добавить описание.
|
||||||
@@ -22,8 +20,7 @@ public class TeamcityBuildNotify extends Notify {
|
|||||||
private final BuildShort buildShort;
|
private final BuildShort buildShort;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
private TeamcityBuildNotify(EntityType entityType, Set<String> recipients, BuildShort buildShort) {
|
private TeamcityBuildNotify(BuildShort buildShort) {
|
||||||
super(entityType, recipients);
|
|
||||||
this.buildShort = buildShort;
|
this.buildShort = buildShort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,12 @@ package org.sadtech.bot.gitlab.teamcity.core.domain.entity;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.sadtech.bot.gitlab.context.domain.EntityType;
|
|
||||||
import org.sadtech.haiti.context.domain.BasicEntity;
|
import org.sadtech.haiti.context.domain.BasicEntity;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 21.09.2020 Добавить описание.
|
* // TODO: 21.09.2020 Добавить описание.
|
||||||
@@ -22,8 +17,8 @@ import javax.persistence.Table;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity
|
//@Entity
|
||||||
@Table(name = "teamcity_setting")
|
//@Table(name = "teamcity_setting")
|
||||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||||
public class TeamcitySetting implements BasicEntity<Long> {
|
public class TeamcitySetting implements BasicEntity<Long> {
|
||||||
|
|
||||||
@@ -36,10 +31,6 @@ public class TeamcitySetting implements BasicEntity<Long> {
|
|||||||
@Column(name = "recipient_id")
|
@Column(name = "recipient_id")
|
||||||
private String recipientId;
|
private String recipientId;
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@Column(name = "recipient_type")
|
|
||||||
private EntityType recipientType;
|
|
||||||
|
|
||||||
@Column(name = "project_id")
|
@Column(name = "project_id")
|
||||||
private String projectId;
|
private String projectId;
|
||||||
|
|
||||||
|
|||||||
@@ -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.TeamcitySettingRepository;
|
||||||
import org.sadtech.bot.gitlab.teamcity.core.repository.jpa.TeamcitySettingJpaRepository;
|
import org.sadtech.bot.gitlab.teamcity.core.repository.jpa.TeamcitySettingJpaRepository;
|
||||||
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author upagge 21.09.2020
|
* @author upagge 21.09.2020
|
||||||
*/
|
*/
|
||||||
@Repository
|
//@Repository
|
||||||
public class TeamcitySettingRepositoryImpl extends AbstractSimpleManagerRepository<TeamcitySetting, Long> implements TeamcitySettingRepository {
|
public class TeamcitySettingRepositoryImpl extends AbstractSimpleManagerRepository<TeamcitySetting, Long> implements TeamcitySettingRepository {
|
||||||
|
|
||||||
private final TeamcitySettingJpaRepository jpaRepository;
|
private final TeamcitySettingJpaRepository jpaRepository;
|
||||||
|
|||||||
@@ -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.sadtech.bot.gitlab.teamcity.core.domain.entity.TeamcitySetting;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.repository.NoRepositoryBean;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author upagge 21.09.2020
|
* @author upagge 21.09.2020
|
||||||
*/
|
*/
|
||||||
|
@NoRepositoryBean
|
||||||
public interface TeamcitySettingJpaRepository extends JpaRepository<TeamcitySetting, Long> {
|
public interface TeamcitySettingJpaRepository extends JpaRepository<TeamcitySetting, Long> {
|
||||||
|
|
||||||
List<TeamcitySetting> findAllByProjectId(String projectId);
|
List<TeamcitySetting> findAllByProjectId(String projectId);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.sadtech.haiti.context.domain.ExistsContainer;
|
|||||||
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,8 +53,6 @@ public class BuildShortServiceImpl extends AbstractSimpleManagerService<BuildSho
|
|||||||
if (isStatusBuild(teamcitySetting, buildShort.getStatus()) && isTypeBuild(teamcitySetting, buildShort.getBuildTypeId())) {
|
if (isStatusBuild(teamcitySetting, buildShort.getStatus()) && isTypeBuild(teamcitySetting, buildShort.getBuildTypeId())) {
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
TeamcityBuildNotify.builder()
|
TeamcityBuildNotify.builder()
|
||||||
.entityType(teamcitySetting.getRecipientType())
|
|
||||||
.recipients(Collections.singleton(teamcitySetting.getRecipientId()))
|
|
||||||
.buildShort(buildShort)
|
.buildShort(buildShort)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.sadtech.bot.gitlab.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.bot.gitlab.telegram.service.ReplaceUrlLocalhost;
|
|
||||||
import org.sadtech.bot.godfather.telegram.autoresponder.MessageAutoresponderTelegram;
|
import org.sadtech.bot.godfather.telegram.autoresponder.MessageAutoresponderTelegram;
|
||||||
import org.sadtech.bot.godfather.telegram.config.TelegramPollingConfig;
|
import org.sadtech.bot.godfather.telegram.config.TelegramPollingConfig;
|
||||||
import org.sadtech.bot.godfather.telegram.listen.EventDistributor;
|
import org.sadtech.bot.godfather.telegram.listen.EventDistributor;
|
||||||
@@ -18,6 +17,7 @@ import org.sadtech.social.core.service.impl.MailServiceImpl;
|
|||||||
import org.sadtech.social.core.service.sender.Sending;
|
import org.sadtech.social.core.service.sender.Sending;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -27,7 +27,7 @@ import java.util.Collections;
|
|||||||
*
|
*
|
||||||
* @author upagge [30.01.2020]
|
* @author upagge [30.01.2020]
|
||||||
*/
|
*/
|
||||||
//@Configuration
|
@Configuration
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class TelegramBotConfig {
|
public class TelegramBotConfig {
|
||||||
|
|
||||||
@@ -57,12 +57,9 @@ public class TelegramBotConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Sending sending(
|
public Sending sending(
|
||||||
TelegramConnect telegramConnect,
|
TelegramConnect telegramConnect
|
||||||
ReplaceUrlLocalhost replaceUrlLocalhost
|
|
||||||
) {
|
) {
|
||||||
final TelegramSender telegramSender = new TelegramSender(telegramConnect);
|
return new TelegramSender(telegramConnect);
|
||||||
telegramSender.setSendPreProcessing(replaceUrlLocalhost);
|
|
||||||
return telegramSender;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -2,46 +2,29 @@ package org.sadtech.bot.gitlab.telegram.service;
|
|||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
|
||||||
import org.sadtech.bot.gitlab.context.domain.notify.Notify;
|
import org.sadtech.bot.gitlab.context.domain.notify.Notify;
|
||||||
import org.sadtech.bot.gitlab.context.service.ChatService;
|
|
||||||
import org.sadtech.bot.gitlab.context.service.MessageSendService;
|
import org.sadtech.bot.gitlab.context.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.stereotype.Service;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // TODO: 17.09.2020 Добавить описание.
|
* // TODO: 17.09.2020 Добавить описание.
|
||||||
*
|
*
|
||||||
* @author upagge 17.09.2020
|
* @author upagge 17.09.2020
|
||||||
*/
|
*/
|
||||||
//@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MessageSendTelegramService implements MessageSendService {
|
public class MessageSendTelegramService implements MessageSendService {
|
||||||
|
|
||||||
private final Sending sending;
|
private final Sending sending;
|
||||||
|
|
||||||
private final ChatService chatService;
|
private final PersonInformation personInformation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(@NonNull Notify notify) {
|
public void send(@NonNull Notify notify) {
|
||||||
final Set<Long> telegramIds = getTelegramIds(notify);
|
sending.send(personInformation.getTelegramId(), BoxAnswer.of(notify.generateMessage()));
|
||||||
telegramIds.forEach(
|
|
||||||
telegramId -> sending.send(telegramId, BoxAnswer.of(notify.generateMessage()))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<Long> 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user