Исправил дублирующийся ответ на комментарии
This commit is contained in:
parent
9f687469ee
commit
b8f4a5fb2a
@ -4,6 +4,7 @@ package org.sadtech.bot.vcs.bitbucket.app.service.converter;
|
||||
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
|
||||
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
|
||||
import org.sadtech.bot.vcs.core.domain.entity.Comment;
|
||||
import org.sadtech.bot.vcs.core.utils.StringUtils;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -19,7 +20,7 @@ public class CommentJsonToComment implements Converter<CommentJson, Comment> {
|
||||
comment.setCreateDate(source.getCreatedDate());
|
||||
comment.setAuthor(source.getAuthor().getName());
|
||||
comment.setPullRequestId(source.getCustomPullRequestId());
|
||||
comment.setMessage(source.getText());
|
||||
comment.setMessage(StringUtils.cutOff(source.getText(), 490));
|
||||
comment.setUrlApi(source.getCustomCommentApiUrl());
|
||||
comment.setBitbucketVersion(source.getVersion());
|
||||
comment.setAnswers(
|
||||
|
@ -6,6 +6,7 @@ import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState;
|
||||
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
|
||||
import org.sadtech.bot.vcs.core.domain.TaskStatus;
|
||||
import org.sadtech.bot.vcs.core.domain.entity.Task;
|
||||
import org.sadtech.bot.vcs.core.utils.StringUtils;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -19,7 +20,7 @@ public class CommentJsonToTaskConvert implements Converter<CommentJson, Task> {
|
||||
final Task task = new Task();
|
||||
task.setId(source.getId());
|
||||
task.setAuthor(source.getAuthor().getName());
|
||||
task.setDescription(source.getText());
|
||||
task.setDescription(StringUtils.cutOff(source.getText(), 490));
|
||||
task.setCreateDate(source.getCreatedDate());
|
||||
task.setBitbucketVersion(source.getVersion());
|
||||
task.setPullRequestId(source.getCustomPullRequestId());
|
||||
|
@ -12,6 +12,7 @@ import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
|
||||
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
|
||||
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
|
||||
import org.sadtech.bot.vcs.core.domain.entity.Reviewer;
|
||||
import org.sadtech.bot.vcs.core.utils.StringUtils;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -30,9 +31,9 @@ public class PullRequestJsonConverter implements Converter<PullRequestJson, Pull
|
||||
pullRequest.setCreateDate(json.getCreatedDate());
|
||||
pullRequest.setUpdateDate(json.getUpdatedDate());
|
||||
pullRequest.setConflict(convertConflict(json.getProperties()));
|
||||
pullRequest.setDescription(convertString(json.getDescription(), 180));
|
||||
pullRequest.setDescription(StringUtils.cutOff(json.getDescription(), 180));
|
||||
pullRequest.setAuthorLogin(json.getAuthor().getUser().getName());
|
||||
pullRequest.setTitle(convertString(json.getTitle(), 90));
|
||||
pullRequest.setTitle(StringUtils.cutOff(json.getTitle(), 90));
|
||||
pullRequest.setUrl(json.getLinks().getSelf().get(0).getHref());
|
||||
pullRequest.setStatus(convertPullRequestStatus(json.getState()));
|
||||
pullRequest.setProjectKey(json.getFromRef().getRepository().getProject().getKey());
|
||||
@ -50,13 +51,6 @@ public class PullRequestJsonConverter implements Converter<PullRequestJson, Pull
|
||||
&& Outcome.CONFLICTED.equals(properties.getMergeResult().getOutcome());
|
||||
}
|
||||
|
||||
private String convertString(String string, int length) {
|
||||
if (string != null) {
|
||||
return string.length() > length ? string.substring(0, length) + "..." : string;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PullRequestStatus convertPullRequestStatus(PullRequestState state) {
|
||||
switch (state) {
|
||||
case OPEN:
|
||||
|
@ -122,6 +122,7 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
||||
final Set<Long> newAnswerIds = newComment.getAnswers();
|
||||
if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds);
|
||||
if (!existsNewAnswersIds.isEmpty()) {
|
||||
final List<Comment> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream()
|
||||
.filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
.collect(Collectors.toList());
|
||||
@ -141,5 +142,6 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -120,6 +120,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
final Set<Long> newAnswerIds = task.getAnswers();
|
||||
if (!oldAnswerIds.equals(newAnswerIds)) {
|
||||
final Set<Long> existsNewAnswersIds = commentService.existsById(newAnswerIds);
|
||||
if (!existsNewAnswersIds.isEmpty()) {
|
||||
final List<Comment> newAnswers = commentService.getAllById(existsNewAnswersIds).stream()
|
||||
.filter(comment -> !oldAnswerIds.contains(comment.getId()))
|
||||
.collect(Collectors.toList());
|
||||
@ -139,6 +140,7 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLastTaskId() {
|
||||
|
@ -52,8 +52,4 @@ public enum Smile {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static class Constants {
|
||||
public static final String EMPTY = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package org.sadtech.bot.vcs.core.utils;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* // TODO: 29.09.2020 Добавить описание.
|
||||
*
|
||||
* @author upagge 29.09.2020
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class StringUtils {
|
||||
|
||||
public static String cutOff(String string, int length) {
|
||||
if (string != null) {
|
||||
return string.length() > length ? string.substring(0, length) + "..." : string;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user