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