This commit is contained in:
uPagge 2021-01-18 00:03:15 +03:00
parent c0188f59ea
commit ba5e70f8d5
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
36 changed files with 651 additions and 360 deletions

View File

@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.gitlab.core.service.parser.MergeRequestParser;
import org.sadtech.bot.gitlab.core.service.parser.NoteParser;
import org.sadtech.bot.gitlab.core.service.parser.PipelineParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@ -17,6 +18,7 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
public class SchedulerService {
private final PipelineParser pipelineParser;
private final MergeRequestParser mergeRequestParser;
private final NoteParser noteParser;
@ -40,4 +42,14 @@ public class SchedulerService {
noteParser.scanOldTask();
}
@Scheduled(cron = "*/30 * * * * *")
public void newPipeline() {
pipelineParser.scanNewPipeline();
}
@Scheduled(cron = "*/30 * * * * *")
public void oldPipeline() {
pipelineParser.scanOldPipeline();
}
}

View File

@ -42,6 +42,8 @@ gitlab-bot:
users-url: ${GITLAB_URL}/api/v4/users
url-note: "{0}#note_{1,number,#}"
url-note-api: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests/{1,number,#}/notes/{2,number,#}"
url-pipelines: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines?&page={1,number,integer}&per_page=100"
url-pipeline: "${GITLAB_URL}/api/v4/projects/{0,number,#}/pipelines/{1,number,integer}"
teamcity:
token: ${TEAMCITY_ADMIN_TOKEN}
project-url: ${TEAMCITY_URL}/app/rest/projects

View File

@ -167,4 +167,26 @@
<addPrimaryKey tableName="merge_request_notes" columnNames="merge_request_id, notes_id"/>
</changeSet>
<changeSet id="2020-01-17-create-table-pipelines" author="uPagge">
<createTable tableName="pipeline">
<column name="id" type="int">
<constraints nullable="false" primaryKey="true"/>
</column>
<column name="ref" type="varchar(300)"/>
<column name="project_id" type="int">
<constraints foreignKeyName="pipelines_project_id" references="project(id)"/>
</column>
<column name="status" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="created_date" type="datetime">
<constraints nullable="false"/>
</column>
<column name="updated_date" type="datetime"/>
<column name="web_url" type="varchar(300)">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -24,4 +24,5 @@ notify.pr.update={0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5}
notify.task.close={0} *Closed [task]({1}){2}*{3}*: {4}
notify.task.new={0} *New [task]({1}) assigned{2}*{3}*: {4}
notify.project.new={0} *New project*{1}[{2}]({3}){1}{4}{5}: {6}
notify.comment.bell={0} *New mention* | [MR]({1}){2}*{3}*: {4}
notify.comment.bell={0} *New mention* | [MR]({1}){2}*{3}*: {4}
notify.pipeline={0} *Pipeline {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8}

View File

@ -24,4 +24,5 @@ notify.pr.update={0} *Обновление MergeRequest | {6}*{3}[{1}]({2}){3}{4
notify.task.close={0} *Закрыта* [задача]({1}){2}*{3}*: {4}
notify.task.new={0} *Назначена новая* [задача]({1}){2}*{3}*: {4}
notify.project.new={0} *Новый Проект*{1}[{2}]({3}){1}{4}{5}: {6}
notify.comment.bell={0} *Новое упоминание* | [MR]({1}){2}*{3}*: {4}
notify.comment.bell={0} *Новое упоминание* | [MR]({1}){2}*{3}*: {4}
notify.pipeline={0} *Сборка {1,number,#}* | {2}{3}[{4}]({5}){3}{6} {7} {8}

View File

@ -0,0 +1,22 @@
package org.sadtech.bot.gitlab.context.domain;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public enum PipelineStatus {
CREATED,
WAITING_FOR_RESOURCE,
PREPARING,
PENDING,
RUNNING,
SUCCESS,
FAILED,
CANCELED,
SKIPPED,
MANUAL,
SCHEDULED
}

View File

@ -1,31 +0,0 @@
package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.haiti.context.domain.BasicEntity;
import javax.persistence.Column;
import javax.persistence.Id;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
@Getter
@Setter
//@Entity
//@Table(name = "chat")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Chat implements BasicEntity<String> {
@Id
@Column(name = "key")
@EqualsAndHashCode.Include
private String id;
@Column(name = "telegram_id")
private Long telegramId;
}

View File

@ -0,0 +1,57 @@
package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
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.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.time.LocalDateTime;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Entity
@Getter
@Setter
@Table(name = "pipeline")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Pipeline implements BasicEntity<Long> {
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
private Long id;
@Column(name = "created_date")
private LocalDateTime created;
@Column(name = "updated_date")
private LocalDateTime updated;
@Enumerated(EnumType.STRING)
@Column(name = "status")
private PipelineStatus status;
@Column(name = "ref")
private String ref;
@Column(name = "web_url")
private String webUrl;
@ManyToOne
@JoinColumn(name = "project_id")
private Project project;
}

View File

@ -1,61 +0,0 @@
package org.sadtech.bot.gitlab.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.time.LocalDateTime;
/**
* Ревьювер пулреквеста.
*
* @author upagge [01.02.2020]
*/
//@Entity
@Getter
@Setter
//@Table(name = "reviewer")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class Reviewer {
/**
* Идентификатор
*/
@Id
@Column(name = "id")
@EqualsAndHashCode.Include
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* Пользователь
*/
@Column(name = "person_login")
private String personLogin;
/**
* Статус
*/
// @Enumerated(EnumType.STRING)
// @Column(name = "status")
// private ReviewerStatus status;
@Column(name = "date_change")
private LocalDateTime dateChange;
@Column(name = "date_smart_notify")
private LocalDateTime dateSmartNotify;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH, optional = false)
@JoinColumn(name = "pull_request_id")
private MergeRequest mergeRequest;
}

View File

@ -0,0 +1,49 @@
package org.sadtech.bot.gitlab.context.domain.notify.pipeline;
import lombok.Builder;
import org.sadtech.bot.gitlab.context.domain.notify.Notify;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
import org.sadtech.bot.gitlab.context.utils.Smile;
import java.text.MessageFormat;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public class PipelineNotify extends Notify {
private final Long pipelineId;
private final String projectName;
private final String refName;
private final String newStatus;
private final String webUrl;
private String oldStatus = "n/a";
@Builder
public PipelineNotify(Long pipelineId, String projectName, String refName, String oldStatus, String newStatus, String webUrl) {
this.pipelineId = pipelineId;
this.projectName = projectName;
this.refName = refName;
this.oldStatus = oldStatus;
this.newStatus = newStatus;
this.webUrl = webUrl;
}
@Override
public String generateMessage(AppSettingService appSettingService) {
return MessageFormat.format(
appSettingService.getMessage("notify.pipeline"),
Smile.BUILD,
pipelineId,
escapeMarkdown(projectName),
Smile.HR,
refName,
webUrl,
oldStatus,
Smile.ARROW,
newStatus
);
}
}

View File

@ -1,40 +0,0 @@
package org.sadtech.bot.gitlab.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.gitlab.context.domain.entity.Reviewer;
import org.sadtech.bot.gitlab.context.service.AppSettingService;
import org.sadtech.bot.gitlab.context.utils.Smile;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
@Getter
public class SmartPrNotify extends PrNotify {
private final Reviewer reviewerTriggered;
@Builder
protected SmartPrNotify(
String title,
String url,
String projectName,
String repositorySlug,
Reviewer reviewerTriggered
) {
super(projectName, title, url);
this.reviewerTriggered = reviewerTriggered;
}
@Override
public String generateMessage(AppSettingService settingService) {
return settingService.getMessage(
"notify.pr.smart",
Smile.SMART.getValue(), title, url, Smile.HR.getValue(), reviewerTriggered.getPersonLogin(),
projectName
);
}
}

View File

@ -1,18 +0,0 @@
package org.sadtech.bot.gitlab.context.repository;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.Chat;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
import java.util.Set;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
public interface ChatRepository extends SimpleManagerRepository<Chat, String> {
Set<Long> findAllTelegramIdByKey(@NonNull Set<String> keys);
}

View File

@ -0,0 +1,20 @@
package org.sadtech.bot.gitlab.context.repository;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.context.repository.SimpleManagerRepository;
import java.util.Set;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public interface PipelineRepository extends SimpleManagerRepository<Pipeline, Long> {
Sheet<Pipeline> findAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination);
}

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.gitlab.context.service;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.context.service.SimpleManagerService;
import java.util.Set;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public interface PipelineService extends SimpleManagerService<Pipeline, Long> {
Sheet<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination);
}

View File

@ -48,4 +48,8 @@ public class GitlabProperty {
private String urlNoteApi;
private String urlPipelines;
private String urlPipeline;
}

View File

@ -0,0 +1,69 @@
package org.sadtech.bot.gitlab.core.service.convert;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.bot.gitlab.sdk.domain.PipelineJson;
import org.sadtech.bot.gitlab.sdk.domain.PipelineStatusJson;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.CANCELED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.CREATED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.FAILED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.MANUAL;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.PENDING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.PREPARING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.RUNNING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.SCHEDULED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.SKIPPED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.SUCCESS;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Component
public class PipelineJsonConverter implements Converter<PipelineJson, Pipeline> {
@Override
public Pipeline convert(PipelineJson source) {
final Pipeline pipeline = new Pipeline();
pipeline.setId(source.getId());
pipeline.setCreated(source.getCreated());
pipeline.setUpdated(source.getUpdated());
pipeline.setRef(source.getRef());
pipeline.setWebUrl(source.getWebUrl());
pipeline.setStatus(convertStatus(source.getStatus()));
return pipeline;
}
private PipelineStatus convertStatus(PipelineStatusJson status) {
switch (status) {
case SKIPPED:
return SKIPPED;
case CANCELED:
return CANCELED;
case SUCCESS:
return SUCCESS;
case MANUAL:
return MANUAL;
case CREATED:
return CREATED;
case PENDING:
return PENDING;
case RUNNING:
return RUNNING;
case PREPARING:
return PREPARING;
case SCHEDULED:
return SCHEDULED;
case WAITING_FOR_RESOURCE:
return WAITING_FOR_RESOURCE;
default:
return FAILED;
}
}
}

View File

@ -0,0 +1,97 @@
package org.sadtech.bot.gitlab.core.service.impl;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.bot.gitlab.context.domain.notify.pipeline.PipelineNotify;
import org.sadtech.bot.gitlab.context.repository.PipelineRepository;
import org.sadtech.bot.gitlab.context.service.NotifyService;
import org.sadtech.bot.gitlab.context.service.PipelineService;
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.springframework.stereotype.Service;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.CANCELED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.FAILED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.SKIPPED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.SUCCESS;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Service
public class PipelineServiceImpl extends AbstractSimpleManagerService<Pipeline, Long> implements PipelineService {
private static final Set<PipelineStatus> notificationStatus = Stream.of(
FAILED, SUCCESS, CANCELED, SKIPPED
).collect(Collectors.toSet());
private final NotifyService notifyService;
private final PipelineRepository repository;
public PipelineServiceImpl(NotifyService notifyService, PipelineRepository repository) {
super(repository);
this.notifyService = notifyService;
this.repository = repository;
}
@Override
public Pipeline create(@NonNull Pipeline pipeline) {
final Pipeline newPipeline = repository.save(pipeline);
if (notificationStatus.contains(pipeline.getStatus())) {
notifyService.send(
PipelineNotify.builder()
.newStatus(pipeline.getStatus().name())
.pipelineId(pipeline.getId())
.projectName(pipeline.getProject().getName())
.refName(pipeline.getRef())
.webUrl(pipeline.getWebUrl())
.build()
);
}
return newPipeline;
}
@Override
public Pipeline update(@NonNull Pipeline pipeline) {
final Pipeline oldPipeline = repository.findById(pipeline.getId())
.orElseThrow(() -> new NotFoundException("Pipeline не найден"));
if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) {
pipeline.setProject(oldPipeline.getProject());
if (notificationStatus.contains(pipeline.getStatus())) {
notifyService.send(
PipelineNotify.builder()
.pipelineId(pipeline.getId())
.webUrl(pipeline.getWebUrl())
.projectName(pipeline.getProject().getName())
.refName(pipeline.getRef())
.newStatus(pipeline.getStatus().name())
.oldStatus(oldPipeline.getStatus().name())
.build()
);
return repository.save(pipeline);
}
}
return oldPipeline;
}
@Override
public Sheet<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) {
return repository.findAllByStatuses(statuses, pagination);
}
}

View File

@ -0,0 +1,131 @@
package org.sadtech.bot.gitlab.core.service.parser;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.bot.gitlab.context.domain.entity.Project;
import org.sadtech.bot.gitlab.context.service.PipelineService;
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.PipelineJson;
import org.sadtech.haiti.context.domain.ExistsContainer;
import org.sadtech.haiti.context.exception.ConvertException;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.core.page.PaginationImpl;
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;
import java.util.stream.Stream;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.CREATED;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.MANUAL;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.PENDING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.PREPARING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.RUNNING;
import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
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;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Service
@RequiredArgsConstructor
public class PipelineParser {
public static final Integer COUNT = 100;
private static final Set<PipelineStatus> oldStatus = Stream.of(
CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, MANUAL
).collect(Collectors.toSet());
private final PipelineService pipelineService;
private final ProjectService projectService;
private final GitlabProperty gitlabProperty;
private final PersonProperty personProperty;
private final ConversionService conversionService;
public void scanNewPipeline() {
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) {
processingProject(project);
}
projectSheet = projectService.getAll(PaginationImpl.of(++page, COUNT));
}
}
private void processingProject(Project project) {
int page = 1;
List<PipelineJson> pipelineJsons = getPipelineJsons(project.getId(), page);
while (!pipelineJsons.isEmpty()) {
final Set<Long> jsonIds = pipelineJsons.stream()
.map(PipelineJson::getId)
.collect(Collectors.toSet());
final ExistsContainer<Pipeline, Long> existsContainer = pipelineService.existsById(jsonIds);
if (!existsContainer.isAllFound()) {
final List<Pipeline> newPipelines = pipelineJsons.stream()
.filter(json -> existsContainer.getIdNoFound().contains(json.getId()))
.map(json -> conversionService.convert(json, Pipeline.class))
.peek(
pipeline -> pipeline.setProject(project)
).collect(Collectors.toList());
pipelineService.createAll(newPipelines);
}
pipelineJsons = getPipelineJsons(project.getId(), ++page);
}
}
private List<PipelineJson> getPipelineJsons(Long projectId, int page) {
return HttpParse.request(MessageFormat.format(gitlabProperty.getUrlPipelines(), projectId, page))
.header(ACCEPT)
.header(HttpParse.AUTHORIZATION, HttpParse.BEARER + personProperty.getToken())
.executeList(PipelineJson.class);
}
public void scanOldPipeline() {
int page = 0;
Sheet<Pipeline> pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(page, COUNT));
while (pipelineSheet.hasContent()) {
final List<Pipeline> pipelines = pipelineSheet.getContent();
for (Pipeline pipeline : pipelines) {
final Pipeline newPipeline = HttpParse.request(
MessageFormat.format(gitlabProperty.getUrlPipeline(), pipeline.getProject().getId(), pipeline.getId())
)
.header(ACCEPT)
.header(AUTHORIZATION, BEARER + personProperty.getToken())
.execute(PipelineJson.class)
.map(json -> conversionService.convert(json, Pipeline.class))
.orElseThrow(() -> new ConvertException("Ошибка обновления Pipelines"));
pipelineService.update(newPipeline);
}
pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PaginationImpl.of(++page, COUNT));
}
}
}

View File

@ -1,31 +0,0 @@
package org.sadtech.bot.gitlab.data.impl;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.entity.Chat;
import org.sadtech.bot.gitlab.context.repository.ChatRepository;
import org.sadtech.bot.gitlab.data.jpa.ChatJpaRepository;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import java.util.Set;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
//@Repository
public class ChatRepositoryImpl extends AbstractSimpleManagerRepository<Chat, String> implements ChatRepository {
private final ChatJpaRepository jpaRepository;
public ChatRepositoryImpl(ChatJpaRepository jpaRepository) {
super(jpaRepository);
this.jpaRepository = jpaRepository;
}
@Override
public Set<Long> findAllTelegramIdByKey(@NonNull Set<String> keys) {
return jpaRepository.findAllTelegramIdByKey(keys);
}
}

View File

@ -0,0 +1,37 @@
package org.sadtech.bot.gitlab.data.impl;
import lombok.NonNull;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.sadtech.bot.gitlab.context.repository.PipelineRepository;
import org.sadtech.bot.gitlab.data.jpa.PipelineJpaRepository;
import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.haiti.database.util.Converter;
import org.springframework.stereotype.Repository;
import java.util.Set;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Repository
public class PipelineRepositoryImpl extends AbstractSimpleManagerRepository<Pipeline, Long> implements PipelineRepository {
private final PipelineJpaRepository jpaRepository;
public PipelineRepositoryImpl(PipelineJpaRepository jpaRepository) {
super(jpaRepository);
this.jpaRepository = jpaRepository;
}
@Override
public Sheet<Pipeline> findAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pagination pagination) {
return Converter.page(
jpaRepository.findAllByStatusIn(statuses, Converter.pagination(pagination))
);
}
}

View File

@ -1,21 +0,0 @@
package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.entity.Chat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param;
import java.util.Set;
/**
* // TODO: 11.10.2020 Добавить описание.
*
* @author upagge 11.10.2020
*/
@NoRepositoryBean
public interface ChatJpaRepository extends JpaRepository<Chat, String> {
// @Query("SELECT c.telegramId FROM Chat c WHERE c.key IN :keys AND c.telegramId IS NOT NULL")
Set<Long> findAllTelegramIdByKey(@Param("keys") Set<String> keys);
}

View File

@ -0,0 +1,20 @@
package org.sadtech.bot.gitlab.data.jpa;
import org.sadtech.bot.gitlab.context.domain.PipelineStatus;
import org.sadtech.bot.gitlab.context.domain.entity.Pipeline;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Set;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public interface PipelineJpaRepository extends JpaRepository<Pipeline, Long> {
Page<Pipeline> findAllByStatusIn(Set<PipelineStatus> statuses, Pageable pageable);
}

View File

@ -1,12 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
/**
* TODO: Добавить комментарий енума.
*
* @author upagge [31.01.2020]
*/
public enum BitbucketUserRole {
AUTHOR, REVIEWER
}

View File

@ -1,8 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
public enum CommentState {
RESOLVED,
OPEN
}

View File

@ -1,15 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
/**
* TODO: Добавить описание класса.
*
* @author upagge [04.02.2020]
*/
@Data
public class FromRefJson {
private RepositoryJson repository;
}

View File

@ -1,21 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* // TODO: 14.01.2021 Добавить описание.
*
* @author upagge 14.01.2021
*/
@Data
public class GroupJson {
private Long id;
@JsonProperty("web_url")
private String webUrl;
private String name;
}

View File

@ -1,17 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
import java.util.List;
/**
* TODO: Добавить описание класса.
*
* @author upagge [31.01.2020]
*/
@Data
public class LinkJson {
private List<SelfJson> self;
}

View File

@ -1,10 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
@Data
public class MergeResult {
private Outcome outcome;
}

View File

@ -1,8 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
public enum Outcome {
CONFLICTED,
CLEAN
}

View File

@ -0,0 +1,39 @@
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 java.time.LocalDateTime;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
@Data
public class PipelineJson {
private Long id;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonProperty("created_at")
private LocalDateTime created;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonProperty("updated_at")
private LocalDateTime updated;
private PipelineStatusJson status;
private String ref;
@JsonProperty("web_url")
private String webUrl;
}

View File

@ -0,0 +1,45 @@
package org.sadtech.bot.gitlab.sdk.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* // TODO: 17.01.2021 Добавить описание.
*
* @author upagge 17.01.2021
*/
public enum PipelineStatusJson {
@JsonProperty("created")
CREATED,
@JsonProperty("waiting_for_resource")
WAITING_FOR_RESOURCE,
@JsonProperty("preparing")
PREPARING,
@JsonProperty("pending")
PENDING,
@JsonProperty("running")
RUNNING,
@JsonProperty("success")
SUCCESS,
@JsonProperty("failed")
FAILED,
@JsonProperty("canceled")
CANCELED,
@JsonProperty("skipped")
SKIPPED,
@JsonProperty("manual")
MANUAL,
@JsonProperty("scheduled")
SCHEDULED
}

View File

@ -1,13 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
@Data
public class Properties {
private MergeResult mergeResult;
private Integer resolvedTaskCount = 0;
private Integer commentCount = 0;
private Integer openTaskCount = 0;
}

View File

@ -1,17 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
/**
* TODO: Добавить описание класса.
*
* @author upagge [04.02.2020]
*/
@Data
public class RepositoryJson {
private Long id;
private String slug;
private ProjectJson project;
}

View File

@ -1,15 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
import lombok.Data;
/**
* TODO: Добавить описание класса.
*
* @author upagge [31.01.2020]
*/
@Data
public class SelfJson {
private String href;
}

View File

@ -1,8 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
public enum Severity {
NORMAL,
BLOCKER
}

View File

@ -1,12 +0,0 @@
package org.sadtech.bot.gitlab.sdk.domain;
/**
* TODO: Добавить комментарий енума.
*
* @author upagge [31.01.2020]
*/
public enum UserPullRequestStatus {
UNAPPROVED, APPROVED, NEEDS_WORK
}