разработка

This commit is contained in:
uPagge 2021-04-19 19:50:29 +03:00
parent 760a17e30c
commit 4ca568caf4
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
8 changed files with 47 additions and 17 deletions

View File

@ -19,11 +19,11 @@ ui.answer.no_task=Задачи не найдены
ui.answer.no_mr=Вы не назначены ответственным за MR
notify.pr.new={0} *Новый MergeRequest | {1}*{2}[{3}]({4}){5}{2}{9}: {10} {12} {11}\n{7}: {8}
notify.pr.forgotten={0} *Напоминание о просмотре PullRequest | {4}*{3}[{1}]({2})
notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3})
notify.pr.conflict={0} *Внимание! Конфликт в MergeRequest | {4}*{1}[{2}]({3}){1}Ветка: {5}
notify.pr.smart={0} *Напоминание о MergeRequest | {6}*{3}[{1}]({2}){3}{4} изменил свое решение на {5}
notify.pr.state={0} *Изменился статус MergeRequest | {7}*{1}[{2}]({3}){1}{4} {5} {6}
notify.pr.update={0} *Обновление MergeRequest | {6}*{3}[{1}]({2}){3}Все задачи: {8}/{7}\nВаши задачи: {10}/{9}{3}{4}: {5}
notify.task.close={0} *Закрыта* [задача]({1}){2}*{3}*: {4}
notify.task.close={0} *Закрыта* [задача]({1}){2}*{3}*: {4}{2}Ваши задачи: {5}/{6}
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}

View File

@ -8,20 +8,24 @@ import org.sadtech.bot.gitlab.context.utils.Smile;
@Getter
public class ConflictPrNotify extends PrNotify {
private final String sourceBranch;
@Builder
private ConflictPrNotify(
String name,
String url,
String projectKey
String projectKey,
String sourceBranch
) {
super(projectKey, name, url);
this.sourceBranch = sourceBranch;
}
@Override
public String generateMessage(AppSettingService settingService) {
return settingService.getMessage(
"notify.pr.conflict",
Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName
Smile.DANGEROUS.getValue(), Smile.HR.getValue(), title, url, projectName, sourceBranch
);
}

View File

@ -11,20 +11,27 @@ import org.sadtech.bot.gitlab.context.utils.Smile;
*/
public class TaskCloseNotify extends TaskNotify {
private final Long personTasks;
private final Long personResolvedTasks;
@Builder
protected TaskCloseNotify(
String authorName,
String url,
String messageTask
String messageTask,
Long personTasks,
Long personResolvedTasks
) {
super(authorName, url, messageTask);
this.personTasks = personTasks;
this.personResolvedTasks = personResolvedTasks;
}
@Override
public String generateMessage(AppSettingService settingService) {
return settingService.getMessage(
"notify.task.close",
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask)
Smile.TASK.getValue(), url, Smile.HR.getValue(), authorName, escapeMarkdown(messageTask), personTasks, personResolvedTasks
);
}

View File

@ -5,7 +5,7 @@ import org.sadtech.bot.gitlab.context.domain.MergeRequestState;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
import org.sadtech.bot.gitlab.context.domain.filter.MergeRequestFilter;
import org.sadtech.haiti.context.service.SimpleManagerService;
import org.sadtech.haiti.filter.FilterService;
import org.sadtech.haiti.context.service.simple.FilterService;
import java.util.Set;

View File

@ -7,7 +7,7 @@ import org.sadtech.bot.gitlab.context.domain.filter.PipelineFilter;
import org.sadtech.haiti.context.page.Pagination;
import org.sadtech.haiti.context.page.Sheet;
import org.sadtech.haiti.context.service.SimpleManagerService;
import org.sadtech.haiti.filter.FilterService;
import org.sadtech.haiti.context.service.simple.FilterService;
import java.util.Set;

View File

@ -34,7 +34,9 @@ public class MergeRequestJsonConverter implements Converter<MergeRequestJson, Me
mergeRequest.setProjectId(source.getProjectId());
mergeRequest.setWebUrl(source.getWebUrl());
mergeRequest.setLabels(source.getLabels());
mergeRequest.setAssignee(convertPerson.convert(source.getAssignee()));
if (source.getAssignee() != null) {
mergeRequest.setAssignee(convertPerson.convert(source.getAssignee()));
}
mergeRequest.setAuthor(convertPerson.convert(source.getAuthor()));
mergeRequest.setSourceBranch(source.getSourceBranch());
mergeRequest.setTargetBranch(source.getTargetBranch());

View File

@ -6,7 +6,6 @@ import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.sadtech.bot.gitlab.context.domain.PersonInformation;
import org.sadtech.bot.gitlab.context.domain.entity.Discussion;
import org.sadtech.bot.gitlab.context.domain.entity.MergeRequest;
@ -29,6 +28,7 @@ import java.text.MessageFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -146,11 +146,24 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
private void updateTask(Note note, Note oldNote) {
if (isResolved(note, oldNote)) {
final MergeRequest mergeRequest = oldNote.getDiscussion().getMergeRequest();
final List<Discussion> discussions = getAllByMergeRequestId(mergeRequest.getId())
.stream()
.filter(discussion -> Objects.nonNull(discussion.getResponsible()))
.collect(Collectors.toList());
final long allYouTasks = discussions.stream()
.filter(discussion -> personInformation.getId().equals(discussion.getFirstNote().getAuthor().getId()))
.count();
final long resolvedYouTask = discussions.stream()
.filter(discussion -> personInformation.getId().equals(discussion.getFirstNote().getAuthor().getId()) && discussion.getResolved())
.count();
notifyService.send(
TaskCloseNotify.builder()
.authorName(oldNote.getAuthor().getName())
.messageTask(oldNote.getBody())
.url(oldNote.getWebUrl())
.personTasks(allYouTasks)
.personResolvedTasks(resolvedYouTask)
.build()
);
}
@ -182,9 +195,7 @@ public class DiscussionServiceImpl extends AbstractSimpleManagerService<Discussi
.build();
try {
final Response execute = client.newCall(request).execute();
System.out.println(execute.isSuccessful());
System.out.println(execute.body().toString());
client.newCall(request).execute();
} catch (IOException e) {
log.error(e.getMessage(), e);
}

View File

@ -21,8 +21,8 @@ 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.context.service.simple.FilterService;
import org.sadtech.haiti.core.service.AbstractSimpleManagerService;
import org.sadtech.haiti.filter.FilterService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@ -64,8 +64,10 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override
public MergeRequest create(@NonNull MergeRequest mergeRequest) {
if (mergeRequest.getAssignee() != null) {
personService.create(mergeRequest.getAssignee());
}
personService.create(mergeRequest.getAuthor());
personService.create(mergeRequest.getAssignee());
mergeRequest.setNotification(true);
@ -102,8 +104,10 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
@Override
public MergeRequest update(@NonNull MergeRequest mergeRequest) {
if (mergeRequest.getAssignee() != null) {
personService.create(mergeRequest.getAssignee());
}
personService.create(mergeRequest.getAuthor());
personService.create(mergeRequest.getAssignee());
final MergeRequest oldMergeRequest = mergeRequestRepository.findById(mergeRequest.getId())
.orElseThrow(() -> new NotFoundException("МержРеквест не найден"));
@ -112,7 +116,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
mergeRequest.setNotification(oldMergeRequest.getNotification());
}
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate())) {
if (!oldMergeRequest.getUpdatedDate().equals(mergeRequest.getUpdatedDate()) || oldMergeRequest.isConflict() != mergeRequest.isConflict()) {
final Project project = projectService.getById(mergeRequest.getProjectId())
.orElseThrow(() -> new NotFoundException("Проект не найден"));
@ -131,6 +135,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
if (
!personInformation.getId().equals(mergeRequest.getAuthor().getId())
&& !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit())
&& !mergeRequest.isConflict()
) {
final List<Discussion> discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId())
.stream()
@ -169,6 +174,7 @@ public class MergeRequestsServiceImpl extends AbstractSimpleManagerService<Merge
) {
notifyService.send(
ConflictPrNotify.builder()
.sourceBranch(oldMergeRequest.getSourceBranch())
.name(mergeRequest.getTitle())
.url(mergeRequest.getWebUrl())
.projectKey(project.getName())