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