Большой рефакторинг 2
This commit is contained in:
parent
a6dce07b3f
commit
f8a6c36eea
@ -2,7 +2,37 @@ stages:
|
||||
- build
|
||||
- deploy
|
||||
|
||||
build:
|
||||
build-develop:
|
||||
image: maven:3.8.6-eclipse-temurin-17
|
||||
stage: build
|
||||
variables:
|
||||
MAVEN_OPTS: "-Dmaven.repo.local=./.m2/repository"
|
||||
only:
|
||||
- develop
|
||||
except:
|
||||
- tags
|
||||
script:
|
||||
- 'mvn -U clean package'
|
||||
artifacts:
|
||||
paths:
|
||||
- gitlab-app/target/gitlab-notification.jar
|
||||
|
||||
docker-build-develop:
|
||||
image: upagge/docker-buildx:latest
|
||||
stage: deploy
|
||||
only:
|
||||
- develop
|
||||
except:
|
||||
- tags
|
||||
services:
|
||||
- docker:dind
|
||||
before_script:
|
||||
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin
|
||||
script:
|
||||
- docker buildx create --use
|
||||
- docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t "$CI_REGISTRY_IMAGE:develop" .
|
||||
|
||||
build-release:
|
||||
image: maven:3.8.6-eclipse-temurin-17
|
||||
stage: build
|
||||
variables:
|
||||
@ -17,7 +47,7 @@ build:
|
||||
paths:
|
||||
- gitlab-app/target/gitlab-notification.jar
|
||||
|
||||
docker-build:
|
||||
docker-build-release:
|
||||
image: upagge/docker-buildx:latest
|
||||
stage: deploy
|
||||
only:
|
||||
|
@ -12,9 +12,10 @@ import lombok.Setter;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(of = "id")
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class MessageSend {
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
private Long id;
|
||||
private Long telegramId;
|
||||
private String message;
|
||||
|
@ -15,6 +15,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author upagge 11.02.2021
|
||||
@ -65,4 +66,13 @@ public class Discussion {
|
||||
return this.notes.get(0);
|
||||
}
|
||||
|
||||
public Optional<Note> getPrevLastNote() {
|
||||
final int size = notes.size();
|
||||
if (size > 2) {
|
||||
return Optional.of(notes.get(size - 2));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.bot.gitlab.context.domain.notify.comment;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.Answer;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import dev.struchkov.haiti.utils.Strings;
|
||||
import lombok.Builder;
|
||||
|
@ -1,31 +0,0 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.comment;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
public record CommentNotify(
|
||||
String url,
|
||||
String authorName,
|
||||
String message
|
||||
) implements Notify {
|
||||
|
||||
@Builder
|
||||
public CommentNotify {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateMessage() {
|
||||
return MessageFormat.format(
|
||||
"{0} *New mention* | [MR]({1}){2}*{3}*: {4}",
|
||||
Smile.COMMENT.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(message)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.comment;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.Notify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import lombok.Builder;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Builder
|
||||
public record NewCommentNotify(
|
||||
String url,
|
||||
String discussionMessage,
|
||||
String discussionAuthor,
|
||||
String previousMessage,
|
||||
String previousAuthor,
|
||||
String authorName,
|
||||
String message
|
||||
) implements Notify {
|
||||
|
||||
@Override
|
||||
public String generateMessage() {
|
||||
|
||||
final StringBuilder builder = new StringBuilder(Smile.COMMENT.getValue()).append(" [New answer in discussion](").append(url).append(")\n--- --- --- ---");
|
||||
|
||||
if (checkNotNull(discussionMessage)) {
|
||||
builder.append("\n-- -- discussion first message -- --\n")
|
||||
.append("*").append(discussionAuthor).append("*: ").append(escapeMarkdown(discussionMessage));
|
||||
}
|
||||
|
||||
if (checkNotNull(previousMessage)) {
|
||||
builder.append("\n-- -- -- previous message -- -- --\n")
|
||||
.append("*").append(previousAuthor).append("*: ").append(escapeMarkdown(previousMessage));
|
||||
}
|
||||
|
||||
builder.append("\n-- -- -- --- new answer --- -- -- --\n")
|
||||
.append("*").append(authorName).append("*: ").append(escapeMarkdown(message));
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,59 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.task;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import dev.struchkov.haiti.utils.Pair;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
/**
|
||||
* @author upagge 10.09.2020
|
||||
*/
|
||||
@Getter
|
||||
public class DiscussionNewNotify extends TaskNotify {
|
||||
|
||||
private final String mrName;
|
||||
private final List<Pair<String, String>> notes;
|
||||
|
||||
@Builder
|
||||
public DiscussionNewNotify(
|
||||
String mrName,
|
||||
String authorName,
|
||||
String url,
|
||||
String discussionMessage,
|
||||
@Singular List<Pair<String, String>> notes
|
||||
) {
|
||||
super(authorName, url, discussionMessage);
|
||||
this.mrName = mrName;
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateMessage() {
|
||||
final StringBuilder builder = new StringBuilder(Smile.TASK.getValue()).append(" [New discussion](").append(url).append(")")
|
||||
.append(Smile.HR.getValue())
|
||||
.append(escapeMarkdown(mrName))
|
||||
.append(Smile.HR.getValue())
|
||||
.append("*").append(authorName).append("*: ").append(escapeMarkdown(messageTask));
|
||||
|
||||
if (checkNotNull(notes)) {
|
||||
builder.append("\n-- -- -- -- comments -- -- -- --\n")
|
||||
.append(convertNotes(notes));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String convertNotes(List<Pair<String, String>> notes) {
|
||||
return notes.stream()
|
||||
.map(note -> "*" + note.getKey() + "*: " + note.getValue())
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.task;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.utils.Smile;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
/**
|
||||
* @author upagge 10.09.2020
|
||||
*/
|
||||
@Getter
|
||||
public class TaskNewNotify extends TaskNotify {
|
||||
|
||||
@Builder
|
||||
protected TaskNewNotify(
|
||||
String authorName,
|
||||
String url,
|
||||
String messageTask
|
||||
) {
|
||||
super(authorName, url, messageTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateMessage() {
|
||||
return MessageFormat.format(
|
||||
"{0} *New [task]({1}) assigned{2}*{3}*: {4}",
|
||||
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -33,7 +33,9 @@ public enum Smile {
|
||||
DANGEROUS("⚠️"),
|
||||
COMMENT("\uD83D\uDCAC"),
|
||||
ARROW("➜"),
|
||||
HR("\n -- -- -- -- --\n"),
|
||||
SHORT_HR("\n-- -- --\n"),
|
||||
HR("\n-- -- -- -- --\n"),
|
||||
HR2("\n-- -- -- -- -- -- -- -- -- --\n"),
|
||||
FAILURE("❌"),
|
||||
SUCCESS("✅"),
|
||||
BUILD("♻️"),
|
||||
|
@ -6,15 +6,16 @@ import dev.struchkov.bot.gitlab.context.domain.entity.Discussion;
|
||||
import dev.struchkov.bot.gitlab.context.domain.entity.MergeRequest;
|
||||
import dev.struchkov.bot.gitlab.context.domain.entity.Note;
|
||||
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.comment.CommentNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.comment.NewCommentNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.DiscussionNewNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.TaskCloseNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.task.TaskNewNotify;
|
||||
import dev.struchkov.bot.gitlab.context.repository.DiscussionRepository;
|
||||
import dev.struchkov.bot.gitlab.context.service.DiscussionService;
|
||||
import dev.struchkov.bot.gitlab.context.service.NotifyService;
|
||||
import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty;
|
||||
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
|
||||
import dev.struchkov.bot.gitlab.core.utils.StringUtils;
|
||||
import dev.struchkov.haiti.utils.Pair;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -33,6 +34,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -67,8 +69,11 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
public Discussion create(@NonNull Discussion discussion) {
|
||||
final List<Note> notes = discussion.getNotes();
|
||||
|
||||
notes.forEach(this::notificationPersonal);
|
||||
notes.forEach(note -> notifyNewNote(note, discussion));
|
||||
if (isNeedNotifyNewNote(discussion)) {
|
||||
notifyNewDiscussion(discussion);
|
||||
} else {
|
||||
notes.forEach(this::notificationPersonal);
|
||||
}
|
||||
|
||||
final boolean resolved = discussion.getNotes().stream()
|
||||
.allMatch(note -> note.isResolvable() && note.getResolved());
|
||||
@ -81,24 +86,37 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
/**
|
||||
* <p>Уведомляет пользователя, если появился новый комментарий</p>
|
||||
*/
|
||||
private void notifyNewNote(Note note, Discussion discussion) {
|
||||
if (isNeedNotifyNewNote(note, discussion)) {
|
||||
notifyService.send(
|
||||
TaskNewNotify.builder()
|
||||
.authorName(note.getAuthor().getName())
|
||||
.messageTask(note.getBody())
|
||||
.url(note.getWebUrl())
|
||||
.build()
|
||||
);
|
||||
private void notifyNewDiscussion(Discussion discussion) {
|
||||
final Note firstNote = discussion.getFirstNote();
|
||||
final List<Note> notes = discussion.getNotes();
|
||||
|
||||
|
||||
final MergeRequest mergeRequest = discussion.getMergeRequest();
|
||||
final DiscussionNewNotify.DiscussionNewNotifyBuilder notifyBuilder = DiscussionNewNotify.builder()
|
||||
.mrName(mergeRequest.getTitle())
|
||||
.authorName(firstNote.getAuthor().getName())
|
||||
.discussionMessage(firstNote.getBody())
|
||||
.url(firstNote.getWebUrl());
|
||||
|
||||
if (notes.size() > 1) {
|
||||
for (int i = 1; i < notes.size(); i++) {
|
||||
final Note note = notes.get(i);
|
||||
notifyBuilder.note(
|
||||
new Pair<>(note.getAuthor().getName(), note.getBody())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
notifyService.send(notifyBuilder.build());
|
||||
}
|
||||
|
||||
private boolean isNeedNotifyNewNote(Note note, Discussion discussion) {
|
||||
private boolean isNeedNotifyNewNote(Discussion discussion) {
|
||||
final Note firstNote = discussion.getFirstNote();
|
||||
final Long gitlabUserId = personInformation.getId();
|
||||
return note.isResolvable() // Тип комментария требует решения (Задачи)
|
||||
&& gitlabUserId.equals(discussion.getResponsible().getId()) // Создатель дискуссии пользователь приложения
|
||||
&& !gitlabUserId.equals(note.getAuthor().getId()) // Создатель комментария не пользователь системы
|
||||
&& FALSE.equals(note.getResolved()); // Комментарий не отмечен как решенный
|
||||
return firstNote.isResolvable() // Тип комментария требует решения (Задачи)
|
||||
&& gitlabUserId.equals(discussion.getResponsible().getId()) // Ответственный за дискуссию пользователь
|
||||
&& !gitlabUserId.equals(firstNote.getAuthor().getId()) // Создатель комментария не пользователь системы
|
||||
&& FALSE.equals(firstNote.getResolved()); // Комментарий не отмечен как решенный
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -160,7 +178,7 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
|
||||
} else {
|
||||
if (userParticipatedInDiscussion) {
|
||||
notifyNewAnswer(newNote);
|
||||
notifyNewAnswer(discussion, newNote);
|
||||
} else {
|
||||
notificationPersonal(newNote);
|
||||
}
|
||||
@ -169,11 +187,25 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
|
||||
}
|
||||
|
||||
private void notifyNewAnswer(Note note) {
|
||||
private void notifyNewAnswer(Discussion discussion, Note note) {
|
||||
if (!personInformation.getId().equals(note.getAuthor().getId())) {
|
||||
final Note firstNote = discussion.getFirstNote();
|
||||
final Optional<Note> prevLastNote = discussion.getPrevLastNote();
|
||||
|
||||
|
||||
final NewCommentNotify.NewCommentNotifyBuilder notifyBuilder = NewCommentNotify.builder();
|
||||
|
||||
if (prevLastNote.isPresent()) {
|
||||
final Note prevNote = prevLastNote.get();
|
||||
notifyBuilder.previousMessage(prevNote.getBody());
|
||||
notifyBuilder.previousAuthor(prevNote.getAuthor().getName());
|
||||
}
|
||||
|
||||
notifyService.send(
|
||||
CommentNotify.builder()
|
||||
notifyBuilder
|
||||
.url(note.getWebUrl())
|
||||
.discussionMessage(firstNote.getBody())
|
||||
.discussionAuthor(firstNote.getAuthor().getName())
|
||||
.message(note.getBody())
|
||||
.authorName(note.getAuthor().getName())
|
||||
.build()
|
||||
@ -287,7 +319,7 @@ public class DiscussionServiceImpl implements DiscussionService {
|
||||
}
|
||||
if (recipientsLogins.contains(personInformation.getUsername())) {
|
||||
notifyService.send(
|
||||
CommentNotify.builder()
|
||||
NewCommentNotify.builder()
|
||||
.authorName(note.getAuthor().getName())
|
||||
.message(note.getBody())
|
||||
.url(note.getWebUrl())
|
||||
|
@ -241,6 +241,7 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteAllById(@NonNull Set<Long> mergeRequestIds) {
|
||||
repository.deleteByIds(mergeRequestIds);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ spring:
|
||||
liquibase:
|
||||
change-log: classpath:liquibase/changelog.xml
|
||||
jpa:
|
||||
show-sql: true
|
||||
show-sql: false
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
database-platform: org.hibernate.dialect.PostgreSQLDialect
|
||||
|
2
pom.xml
2
pom.xml
@ -44,7 +44,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<godfather.telegram.core.version>0.0.38</godfather.telegram.core.version>
|
||||
<godfather.telegram.core.version>0.0.39</godfather.telegram.core.version>
|
||||
|
||||
<javax.persistance.version>2.2</javax.persistance.version>
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class StartNotify {
|
||||
if (!settingService.isFirstStart()) {
|
||||
notifyService.send(
|
||||
SimpleTextNotify.builder()
|
||||
.message("Привет. Желаю продуктивного дня :)" +
|
||||
.message("Hello. I wish you a productive day :)" +
|
||||
"\n-- -- -- -- --\n" +
|
||||
"Version " + appProperty.getVersion() + " | Developer: [uPagge](https://mark.struchkov.dev)")
|
||||
.build()
|
||||
|
Loading…
Reference in New Issue
Block a user