Поправил уведомление об обновлении MR
This commit is contained in:
parent
f8a6c36eea
commit
ee1425b5af
@ -4,8 +4,6 @@ import dev.struchkov.bot.gitlab.context.utils.Smile;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class UpdatePrNotify extends PrNotify {
|
public class UpdatePrNotify extends PrNotify {
|
||||||
|
|
||||||
@ -36,10 +34,24 @@ public class UpdatePrNotify extends PrNotify {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateMessage() {
|
public String generateMessage() {
|
||||||
return MessageFormat.format(
|
final StringBuilder builder = new StringBuilder(Smile.UPDATE.getValue()).append(" *MergeRequest update | ").append(projectName).append("*")
|
||||||
"{0} *MergeRequest update | {6}*{3}[{1}]({2}){3}{4}: {5}",
|
.append(Smile.HR.getValue())
|
||||||
Smile.UPDATE.getValue(), title, url, Smile.HR.getValue(), Smile.AUTHOR.getValue(), author, projectName, allTasks, allResolvedTasks, personTasks, personResolvedTasks
|
.append("[").append(title).append("](").append(url).append(")");
|
||||||
);
|
|
||||||
|
|
||||||
|
if (allTasks > 0) {
|
||||||
|
builder.append(Smile.HR.getValue())
|
||||||
|
.append("All tasks: ").append(allResolvedTasks).append("/").append(allTasks);
|
||||||
|
|
||||||
|
if (personTasks > 0) {
|
||||||
|
builder.append("\nYour tasks: ").append(personResolvedTasks).append("/").append(personTasks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append(Smile.HR.getValue())
|
||||||
|
.append(Smile.AUTHOR.getValue()).append(": ").append(author);
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,12 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
|
import static dev.struchkov.haiti.context.exception.NotFoundException.notFoundException;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNull;
|
|
||||||
import static java.lang.Boolean.TRUE;
|
import static java.lang.Boolean.TRUE;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -146,8 +144,8 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
final MergeRequest oldMergeRequest = repository.findById(mergeRequest.getId())
|
final MergeRequest oldMergeRequest = repository.findById(mergeRequest.getId())
|
||||||
.orElseThrow(notFoundException("MergeRequest не найден"));
|
.orElseThrow(notFoundException("MergeRequest не найден"));
|
||||||
|
|
||||||
final Boolean notification = mergeRequest.getNotification();
|
final Boolean notification = oldMergeRequest.getNotification();
|
||||||
if (checkNull(notification)) {
|
if (checkNotNull(notification)) {
|
||||||
mergeRequest.setNotification(oldMergeRequest.getNotification());
|
mergeRequest.setNotification(oldMergeRequest.getNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,27 +250,34 @@ public class MergeRequestsServiceImpl implements MergeRequestsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
private void notifyAboutUpdate(MergeRequest oldMergeRequest, MergeRequest mergeRequest, Project project) {
|
||||||
final Long gitlabUserId = personInformation.getId();
|
final Long botUserGitlabId = personInformation.getId();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!gitlabUserId.equals(mergeRequest.getAuthor().getId()) // Автор MR не пользователь приложения
|
!botUserGitlabId.equals(mergeRequest.getAuthor().getId()) // Автор MR не пользователь приложения
|
||||||
&& !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit()) // Изменилась дата последнего коммита
|
&& !oldMergeRequest.getDateLastCommit().equals(mergeRequest.getDateLastCommit()) // Изменилась дата последнего коммита
|
||||||
&& !mergeRequest.isConflict() // MR не находится в состоянии конфликта
|
&& !mergeRequest.isConflict() // MR не находится в состоянии конфликта
|
||||||
) {
|
) {
|
||||||
final List<Discussion> discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId())
|
|
||||||
.stream()
|
long allTask = 0;
|
||||||
.filter(discussion -> Objects.nonNull(discussion.getResponsible()))
|
long resolvedTask = 0;
|
||||||
.toList();
|
long allYouTasks = 0;
|
||||||
final long allTask = discussions.size();
|
long resolvedYouTask = 0;
|
||||||
final long resolvedTask = discussions.stream()
|
final List<Discussion> discussions = discussionService.getAllByMergeRequestId(oldMergeRequest.getId());
|
||||||
.filter(Discussion::getResolved)
|
for (Discussion discussion : discussions) {
|
||||||
.count();
|
if (checkNotNull(discussion.getResponsible())) {
|
||||||
final long allYouTasks = discussions.stream()
|
final boolean isBotUserAuthorDiscussion = botUserGitlabId.equals(discussion.getFirstNote().getAuthor().getId());
|
||||||
.filter(discussion -> gitlabUserId.equals(discussion.getFirstNote().getAuthor().getId()))
|
allTask += 1;
|
||||||
.count();
|
if (isBotUserAuthorDiscussion) {
|
||||||
final long resolvedYouTask = discussions.stream()
|
allYouTasks += 1;
|
||||||
.filter(discussion -> gitlabUserId.equals(discussion.getFirstNote().getAuthor().getId()) && discussion.getResolved())
|
}
|
||||||
.count();
|
if (TRUE.equals(discussion.getResolved())) {
|
||||||
|
resolvedTask += 1;
|
||||||
|
if (isBotUserAuthorDiscussion) {
|
||||||
|
resolvedYouTask += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
notifyService.send(
|
notifyService.send(
|
||||||
UpdatePrNotify.builder()
|
UpdatePrNotify.builder()
|
||||||
.author(oldMergeRequest.getAuthor().getName())
|
.author(oldMergeRequest.getAuthor().getName())
|
||||||
|
Loading…
Reference in New Issue
Block a user