Добавление тасок
This commit is contained in:
parent
d2cd4b62f5
commit
9289957723
@ -12,5 +12,6 @@ import org.springframework.stereotype.Component;
|
||||
public class InitProperty {
|
||||
|
||||
private Long startCommentId;
|
||||
private boolean use = false;
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ public class Comment {
|
||||
@EqualsAndHashCode.Include
|
||||
private Long id;
|
||||
|
||||
@Column(name = "url_api")
|
||||
private String urlApi;
|
||||
|
||||
@Column(name = "url")
|
||||
private String url;
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
package org.sadtech.bot.bitbucketbot.domain.entity;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
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 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "pull_request")
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class PullRequestMini {
|
||||
|
||||
/**
|
||||
* Идентификатор
|
||||
*/
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@EqualsAndHashCode.Include
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* Адрес ПР
|
||||
*/
|
||||
@Column(name = "url")
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Автор ПР
|
||||
*/
|
||||
@Column(name = "author_login")
|
||||
private String authorLogin;
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.sadtech.bot.bitbucketbot.domain.TaskStatus;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
@ -15,6 +14,7 @@ import javax.persistence.JoinTable;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@ -63,8 +63,11 @@ public class Task {
|
||||
@Column(name = "author_login")
|
||||
private String author;
|
||||
|
||||
@Column(name = "responsible_login")
|
||||
private String responsible;
|
||||
|
||||
@JoinTable
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
private List<Comment> comments;
|
||||
@OneToMany
|
||||
private List<Comment> comments = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package org.sadtech.bot.bitbucketbot.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.basic.context.repository.SimpleManagerRepository;
|
||||
import org.sadtech.basic.context.repository.simple.FilterOperation;
|
||||
import org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr;
|
||||
import org.sadtech.bot.bitbucketbot.domain.PullRequestStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.ReviewerStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface PullRequestsRepository extends SimpleManagerRepository<PullRequest, Long>, FilterOperation<PullRequest> {
|
||||
@ -18,4 +21,6 @@ public interface PullRequestsRepository extends SimpleManagerRepository<PullRequ
|
||||
|
||||
Set<IdAndStatusPr> findAllIdByStatusIn(Set<PullRequestStatus> statuses);
|
||||
|
||||
Optional<PullRequestMini> findMiniInfoById(@NonNull Long id);
|
||||
|
||||
}
|
||||
|
@ -1,25 +1,31 @@
|
||||
package org.sadtech.bot.bitbucketbot.repository.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.basic.database.repository.manager.FilterManagerRepository;
|
||||
import org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr;
|
||||
import org.sadtech.bot.bitbucketbot.domain.PullRequestStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.ReviewerStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
import org.sadtech.bot.bitbucketbot.repository.PullRequestsRepository;
|
||||
import org.sadtech.bot.bitbucketbot.repository.jpa.PullRequestMiniRepositoryJpa;
|
||||
import org.sadtech.bot.bitbucketbot.repository.jpa.PullRequestsRepositoryJpa;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@Repository
|
||||
public class PullRequestsRepositoryImpl extends FilterManagerRepository<PullRequest, Long> implements PullRequestsRepository {
|
||||
|
||||
private final PullRequestsRepositoryJpa repositoryJpa;
|
||||
private final PullRequestMiniRepositoryJpa pullRequestMiniRepositoryJpa;
|
||||
|
||||
public PullRequestsRepositoryImpl(PullRequestsRepositoryJpa jpaRepository) {
|
||||
public PullRequestsRepositoryImpl(PullRequestsRepositoryJpa jpaRepository, PullRequestMiniRepositoryJpa pullRequestMiniRepositoryJpa) {
|
||||
super(jpaRepository);
|
||||
repositoryJpa = jpaRepository;
|
||||
this.pullRequestMiniRepositoryJpa = pullRequestMiniRepositoryJpa;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +43,9 @@ public class PullRequestsRepositoryImpl extends FilterManagerRepository<PullRequ
|
||||
return repositoryJpa.findAllIdByStatusIn(statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PullRequestMini> findMiniInfoById(@NonNull Long id) {
|
||||
return pullRequestMiniRepositoryJpa.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package org.sadtech.bot.bitbucketbot.repository.jpa;
|
||||
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
/**
|
||||
* // TODO: 12.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 12.09.2020
|
||||
*/
|
||||
public interface PullRequestMiniRepositoryJpa extends JpaRepository<PullRequestMini, Long> {
|
||||
}
|
@ -39,6 +39,9 @@ public interface PullRequestsRepositoryJpa extends JpaRepositoryImplementation<P
|
||||
@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);
|
||||
|
||||
// @Query("SELECT p FROM PullRequest p WHERE p.authorLogin = :login AND p.createDate BETWEEN :dateFrom AND :dateTo")
|
||||
// List<PullRequest> findAllByAuthorAndDateBetween(@Param("login") String login, @Param("dateFrom") LocalDateTime dateFrom, @Param("dateTo") LocalDateTime dateTo);
|
||||
|
||||
|
@ -7,9 +7,11 @@ import org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr;
|
||||
import org.sadtech.bot.bitbucketbot.domain.PullRequestStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.ReviewerStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
import org.sadtech.bot.bitbucketbot.domain.filter.PullRequestFilter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface PullRequestsService extends SimpleManagerService<PullRequest, Long>, FilterService<PullRequest, PullRequestFilter> {
|
||||
@ -27,4 +29,6 @@ public interface PullRequestsService extends SimpleManagerService<PullRequest, L
|
||||
*/
|
||||
Set<IdAndStatusPr> getAllId(Set<PullRequestStatus> statuses);
|
||||
|
||||
Optional<PullRequestMini> getMiniInfo(@NonNull Long pullRequestId);
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class ResultScanToComment implements Converter<ResultScan, Comment> {
|
||||
comment.setAuthor(commentJson.getAuthor().getName());
|
||||
comment.setPullRequestId(resultScan.getPullRequestId());
|
||||
comment.setMessage(commentJson.getText());
|
||||
comment.setUrl(resultScan.getUrlComment());
|
||||
comment.setUrlApi(resultScan.getCommentApiUrl());
|
||||
comment.setBitbucketVersion(commentJson.getVersion());
|
||||
comment.setAnswers(
|
||||
commentJson.getComments().stream()
|
||||
|
@ -1,7 +1,10 @@
|
||||
package org.sadtech.bot.bitbucketbot.service.converter;
|
||||
|
||||
import org.sadtech.basic.context.exception.ConvertException;
|
||||
import org.sadtech.bot.bitbucketbot.domain.TaskStatus;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.Task;
|
||||
import org.sadtech.bot.bitbucketbot.dto.bitbucket.CommentJson;
|
||||
import org.sadtech.bot.bitbucketbot.dto.bitbucket.CommentState;
|
||||
import org.sadtech.bot.bitbucketbot.service.executor.ResultScan;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -19,7 +22,20 @@ public class ResultScanToTaskConvert implements Converter<ResultScan, Task> {
|
||||
task.setCreateDate(json.getCreatedDate());
|
||||
task.setBitbucketVersion(json.getVersion());
|
||||
task.setPullRequestId(resultScan.getPullRequestId());
|
||||
task.setStatus(convertState(json.getState()));
|
||||
task.setUrlApi(resultScan.getCommentApiUrl());
|
||||
return task;
|
||||
}
|
||||
|
||||
private TaskStatus convertState(CommentState state) {
|
||||
switch (state) {
|
||||
case RESOLVED:
|
||||
return TaskStatus.RESOLVED;
|
||||
case OPEN:
|
||||
return TaskStatus.OPEN;
|
||||
default:
|
||||
throw new ConvertException("Неподдерживаемый тип задачи");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.sadtech.bot.bitbucketbot.dto.bitbucket.CommentJson;
|
||||
@RequiredArgsConstructor
|
||||
public class ResultScan {
|
||||
|
||||
private final String urlComment;
|
||||
private final String commentApiUrl;
|
||||
private final Long pullRequestId;
|
||||
private final CommentJson commentJson;
|
||||
|
||||
|
@ -2,7 +2,6 @@ package org.sadtech.bot.bitbucketbot.service.impl;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.sadtech.basic.core.service.AbstractSimpleManagerService;
|
||||
import org.sadtech.bot.bitbucketbot.config.InitProperty;
|
||||
import org.sadtech.bot.bitbucketbot.domain.change.comment.CommentChange;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.Comment;
|
||||
import org.sadtech.bot.bitbucketbot.exception.NotFoundException;
|
||||
@ -27,23 +26,17 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
||||
private final CommentRepository commentRepository;
|
||||
private final PersonService personService;
|
||||
private final ChangeService changeService;
|
||||
private final InitProperty initProperty;
|
||||
|
||||
public CommentServiceImpl(CommentRepository commentRepository, PersonService personService, ChangeService changeService, InitProperty initProperty) {
|
||||
public CommentServiceImpl(CommentRepository commentRepository, PersonService personService, ChangeService changeService) {
|
||||
super(commentRepository);
|
||||
this.personService = personService;
|
||||
this.commentRepository = commentRepository;
|
||||
this.changeService = changeService;
|
||||
this.initProperty = initProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastCommentId() {
|
||||
return commentRepository.findFirstByOrderByIdDesc().map(Comment::getId).orElse(getInitCommentId());
|
||||
}
|
||||
|
||||
private Long getInitCommentId() {
|
||||
return initProperty.getStartCommentId() != null ? initProperty.getStartCommentId() : 0L;
|
||||
return commentRepository.findFirstByOrderByIdDesc().map(Comment::getId).orElse(0L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +46,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
||||
|
||||
@Override
|
||||
public Comment create(@NonNull Comment comment) {
|
||||
comment.getAnswers().clear();
|
||||
final Comment newComment = commentRepository.save(comment);
|
||||
notificationPersonal(comment);
|
||||
return newComment;
|
||||
|
@ -16,6 +16,7 @@ import org.sadtech.bot.bitbucketbot.domain.change.pullrequest.NewPrChange;
|
||||
import org.sadtech.bot.bitbucketbot.domain.change.pullrequest.ReviewersPrChange;
|
||||
import org.sadtech.bot.bitbucketbot.domain.change.pullrequest.UpdatePrChange;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest_;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.Reviewer;
|
||||
import org.sadtech.bot.bitbucketbot.domain.filter.PullRequestFilter;
|
||||
@ -182,6 +183,11 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
|
||||
return pullRequestsRepository.findAllIdByStatusIn(statuses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PullRequestMini> getMiniInfo(@NonNull Long pullRequestId) {
|
||||
return pullRequestsRepository.findMiniInfoById(pullRequestId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sheet<PullRequest> getAll(@NonNull PullRequestFilter filter, Pagination pagination) {
|
||||
return filterService.getAll(filter, pagination);
|
||||
|
@ -36,6 +36,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
@Override
|
||||
public Task create(@NonNull Task task) {
|
||||
Assert.isNotNull(task.getId(), "При создании объекта должен быть установлен идентификатор");
|
||||
task.getComments().clear();
|
||||
final Task newTask = taskRepository.save(task);
|
||||
|
||||
final PullRequest pullRequest = pullRequestsService.getById(task.getPullRequestId())
|
||||
|
@ -11,9 +11,11 @@ import org.sadtech.bot.bitbucketbot.domain.Answer;
|
||||
import org.sadtech.bot.bitbucketbot.domain.change.comment.AnswerCommentChange;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.Comment;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequestMini;
|
||||
import org.sadtech.bot.bitbucketbot.domain.entity.Task;
|
||||
import org.sadtech.bot.bitbucketbot.dto.bitbucket.CommentJson;
|
||||
import org.sadtech.bot.bitbucketbot.dto.bitbucket.Severity;
|
||||
import org.sadtech.bot.bitbucketbot.exception.NotFoundException;
|
||||
import org.sadtech.bot.bitbucketbot.service.ChangeService;
|
||||
import org.sadtech.bot.bitbucketbot.service.CommentService;
|
||||
import org.sadtech.bot.bitbucketbot.service.PersonService;
|
||||
@ -26,6 +28,7 @@ import org.sadtech.bot.bitbucketbot.service.impl.ExecutorScanner;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -54,6 +57,8 @@ public class CommentAndTaskParser {
|
||||
private final CommentSchedulerProperty commentSchedulerProperty;
|
||||
private final InitProperty initProperty;
|
||||
|
||||
private boolean initStart = false;
|
||||
|
||||
public void scanNewCommentAndTask() {
|
||||
long commentId = getLastIdCommentOrTask() + 1;
|
||||
int count = 0;
|
||||
@ -62,8 +67,13 @@ public class CommentAndTaskParser {
|
||||
executorScanner.registration(dataScans);
|
||||
final List<ResultScan> resultScans = executorScanner.getResult();
|
||||
if (!resultScans.isEmpty()) {
|
||||
commentService.createAll(getCommentsByResultScan(resultScans));
|
||||
taskService.createAll(getTaskByResultScan(resultScans));
|
||||
final long commentMax = commentService.createAll(getCommentsByResultScan(resultScans)).stream()
|
||||
.mapToLong(Comment::getId)
|
||||
.max().orElse(0L);
|
||||
final long taskMax = taskService.createAll(getTaskByResultScan(resultScans)).stream()
|
||||
.mapToLong(Task::getId)
|
||||
.max().orElse(0L);
|
||||
commentId = Long.max(commentMax, taskMax) + 1;
|
||||
count = 0;
|
||||
}
|
||||
} while (count++ < commentSchedulerProperty.getNoCommentCount());
|
||||
@ -71,8 +81,9 @@ public class CommentAndTaskParser {
|
||||
|
||||
private long getLastIdCommentOrTask() {
|
||||
Long commentStartId = Long.max(commentService.getLastCommentId(), taskService.getLastTaskId());
|
||||
if (commentStartId == 0L && initProperty != null) {
|
||||
if (initProperty != null && !initStart && (commentStartId == 0L || initProperty.isUse())) {
|
||||
commentStartId = initProperty.getStartCommentId();
|
||||
initStart = true;
|
||||
}
|
||||
return commentStartId;
|
||||
}
|
||||
@ -107,6 +118,13 @@ public class CommentAndTaskParser {
|
||||
return resultScans.stream()
|
||||
.filter(resultScan -> Severity.NORMAL.equals(resultScan.getCommentJson().getSeverity()))
|
||||
.map(resultScan -> conversionService.convert(resultScan, Comment.class))
|
||||
.peek(
|
||||
comment -> {
|
||||
final PullRequestMini pullRequestMini = pullRequestsService.getMiniInfo(comment.getPullRequestId())
|
||||
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
||||
comment.setUrl(generateUrl(comment.getId(), pullRequestMini.getUrl()));
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@ -114,9 +132,21 @@ public class CommentAndTaskParser {
|
||||
return resultScans.stream()
|
||||
.filter(commentJson -> Severity.BLOCKER.equals(commentJson.getCommentJson().getSeverity()))
|
||||
.map(resultScan -> conversionService.convert(resultScan, Task.class))
|
||||
.peek(
|
||||
task -> {
|
||||
final PullRequestMini pullRequestMini = pullRequestsService.getMiniInfo(task.getPullRequestId())
|
||||
.orElseThrow(() -> new NotFoundException("Автор ПР не найден"));
|
||||
task.setResponsible(pullRequestMini.getAuthorLogin());
|
||||
task.setUrl(generateUrl(task.getId(), pullRequestMini.getUrl()));
|
||||
}
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String generateUrl(@NonNull Long id, @NonNull String pullRequestUrl) {
|
||||
return MessageFormat.format("{0}/overview?commentId={1}", pullRequestUrl, id).replaceAll(" ", "");
|
||||
}
|
||||
|
||||
private String getCommentUrl(long commentId, PullRequest pullRequest) {
|
||||
return bitbucketProperty.getUrlPullRequestComment()
|
||||
.replace("{projectKey}", pullRequest.getProjectKey())
|
||||
|
@ -23,7 +23,8 @@ bitbucketbot:
|
||||
no-comment-count: 20
|
||||
comment-count: 100
|
||||
init:
|
||||
start-comment-id: 7623
|
||||
start-comment-id: 7796
|
||||
use: false
|
||||
server-send:
|
||||
url: http://188.225.35.149:8080/api/send
|
||||
bitbucket:
|
||||
|
@ -91,7 +91,12 @@
|
||||
<column name="id" type="int">
|
||||
<constraints primaryKey="true"/>
|
||||
</column>
|
||||
<column name="url" type="varchar(300)"/>
|
||||
<column name="url" type="varchar(300)">
|
||||
<constraints nullable="false" unique="true"/>
|
||||
</column>
|
||||
<column name="url_api" type="varchar(300)">
|
||||
<constraints nullable="false" unique="true"/>
|
||||
</column>
|
||||
<column name="author_login" type="varchar(64)">
|
||||
<constraints nullable="false" foreignKeyName="task_author_login_person_login"
|
||||
references="person(login)" deleteCascade="true"/>
|
||||
@ -139,15 +144,19 @@
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
<column name="url" type="varchar(300)">
|
||||
<constraints nullable="false"/>
|
||||
<constraints nullable="false" unique="true"/>
|
||||
</column>
|
||||
<column name="url_api" type="varchar(300)">
|
||||
<constraints nullable="false"/>
|
||||
<constraints nullable="false" unique="true"/>
|
||||
</column>
|
||||
<column name="author_login" type="varchar(64)">
|
||||
<constraints nullable="false" foreignKeyName="task_author_login_person_login"
|
||||
references="person(login)" deleteCascade="true"/>
|
||||
</column>
|
||||
<column name="responsible_login" type="varchar(64)">
|
||||
<constraints nullable="false" foreignKeyName="task_responsible_login_person_login"
|
||||
references="person(login)" deleteCascade="true"/>
|
||||
</column>
|
||||
<column name="pull_request_id" type="int">
|
||||
<constraints nullable="true" foreignKeyName="task_pull_request_id_pull_request_id"
|
||||
references="pull_request(id)" deleteCascade="true"/>
|
||||
|
Loading…
Reference in New Issue
Block a user