Добавлено уведомление об отсутствии ревьюверов
This commit is contained in:
parent
e5727f2b30
commit
07b5687cf2
@ -0,0 +1,36 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.group.mr;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Getter;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.group.mr.ConflictMrGroupNotifyFields.CLASS_NAME;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class ConflictMrGroupNotify implements GroupNotify {
|
||||
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
protected final String sourceBranch;
|
||||
protected final String projectName;
|
||||
protected final String title;
|
||||
protected final String url;
|
||||
protected final String milestone;
|
||||
protected final String authorTelegramUsername;
|
||||
|
||||
public ConflictMrGroupNotify(String sourceBranch, String projectName, String title, String url, String milestone, String authorTelegramUsername) {
|
||||
this.sourceBranch = sourceBranch;
|
||||
this.projectName = projectName;
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
this.milestone = milestone;
|
||||
this.authorTelegramUsername = authorTelegramUsername;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import static dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRe
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class NewMergeRequestGroupPersonalNotify implements GroupNotify {
|
||||
public class NewMergeRequestGroupNotify implements GroupNotify {
|
||||
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
@ -29,7 +29,7 @@ public class NewMergeRequestGroupPersonalNotify implements GroupNotify {
|
||||
protected final Person assignee;
|
||||
|
||||
@Builder
|
||||
public NewMergeRequestGroupPersonalNotify(Long mrId, String projectName, String title, String url, String milestone, String description, String author, String targetBranch, String sourceBranch, Map<Long, String> reviewerTelegramUsernames, Person assignee) {
|
||||
public NewMergeRequestGroupNotify(Long mrId, String projectName, String title, String url, String milestone, String description, String author, String targetBranch, String sourceBranch, Map<Long, String> reviewerTelegramUsernames, Person assignee) {
|
||||
this.mrId = mrId;
|
||||
this.projectName = projectName;
|
||||
this.title = title;
|
@ -0,0 +1,41 @@
|
||||
package dev.struchkov.bot.gitlab.context.domain.notify.group.mr;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.entity.Person;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.GroupNotify;
|
||||
import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class NoReviewerGroupNotify implements GroupNotify {
|
||||
|
||||
public static final String TYPE = "NoReviewersGroupNotify";
|
||||
|
||||
protected final String projectName;
|
||||
protected final String title;
|
||||
protected final String url;
|
||||
protected final String milestone;
|
||||
protected final String targetBranch;
|
||||
protected final String sourceBranch;
|
||||
protected final Person assignee;
|
||||
protected final String ownerTelegramUsername;
|
||||
|
||||
@Builder
|
||||
public NoReviewerGroupNotify(String projectName, String title, String url, String milestone, String targetBranch, String sourceBranch, Person assignee, String ownerTelegramUsername) {
|
||||
this.projectName = projectName;
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
this.milestone = milestone;
|
||||
this.targetBranch = targetBranch;
|
||||
this.sourceBranch = sourceBranch;
|
||||
this.assignee = assignee;
|
||||
this.ownerTelegramUsername = ownerTelegramUsername;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -6,11 +6,13 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.context.domain.notify.group.pipeline.PipelineGroupNotifyFields.CLASS_NAME;
|
||||
|
||||
@Getter
|
||||
@FieldNames
|
||||
public class PipelineGroupNotify implements GroupNotify {
|
||||
|
||||
public static final String TYPE = "PipelineGroupNotify";
|
||||
public static final String TYPE = CLASS_NAME;
|
||||
|
||||
private final String projectName;
|
||||
private final String refName;
|
||||
|
@ -11,7 +11,8 @@ import dev.struchkov.bot.gitlab.context.domain.entity.Person;
|
||||
import dev.struchkov.bot.gitlab.context.domain.entity.Project;
|
||||
import dev.struchkov.bot.gitlab.context.domain.event.NewMergeRequestEvent;
|
||||
import dev.struchkov.bot.gitlab.context.domain.event.UpdateMergeRequestEvent;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NoReviewerGroupNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ApprovalChangedMrPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictMrPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.mergerequest.ConflictResolveMrPersonalNotify;
|
||||
@ -56,32 +57,53 @@ public class MergeRequestHandler {
|
||||
|
||||
final boolean userReviewer = mergeRequest.isUserReviewer();
|
||||
final boolean userAssignee = mergeRequest.isUserAssignee();
|
||||
if (!mergeRequest.isConflict()) {
|
||||
if (mergeRequest.isConflict()) {
|
||||
|
||||
} else {
|
||||
if (mergeRequest.isNotification()) {
|
||||
if (userReviewer || userAssignee) {
|
||||
if (userReviewer) sendNotifyNewMrReview(mergeRequest, projectName);
|
||||
if (userAssignee) sendNotifyNewAssignee(mergeRequest, projectName, null);
|
||||
}
|
||||
}
|
||||
final Map<Long, String> reviewerTelegramUsernames = personService.getTelegramUsernamesByPersonIds(mergeRequest.getReviewers().stream().map(Person::getId).collect(Collectors.toSet()));
|
||||
if (!reviewerTelegramUsernames.isEmpty()) {
|
||||
notifyService.send(
|
||||
NewMergeRequestGroupPersonalNotify.builder()
|
||||
.mrId(mergeRequest.getId())
|
||||
.title(mergeRequest.getTitle())
|
||||
.url(mergeRequest.getWebUrl())
|
||||
.author(mergeRequest.getAuthor().getName())
|
||||
.reviewerTelegramUsernames(reviewerTelegramUsernames)
|
||||
.milestone(mergeRequest.getMilestone())
|
||||
.projectName(projectName)
|
||||
.targetBranch(mergeRequest.getTargetBranch())
|
||||
.sourceBranch(mergeRequest.getSourceBranch())
|
||||
.description(mergeRequest.getDescription())
|
||||
.build()
|
||||
);
|
||||
|
||||
if (checkNotEmpty(mergeRequest.getReviewers())) {
|
||||
final Map<Long, String> reviewerTelegramUsernames = personService.getTelegramUsernamesByPersonIds(mergeRequest.getReviewers().stream().map(Person::getId).collect(Collectors.toSet()));
|
||||
if (!reviewerTelegramUsernames.isEmpty()) {
|
||||
notifyService.send(
|
||||
NewMergeRequestGroupNotify.builder()
|
||||
.mrId(mergeRequest.getId())
|
||||
.title(mergeRequest.getTitle())
|
||||
.url(mergeRequest.getWebUrl())
|
||||
.author(mergeRequest.getAuthor().getName())
|
||||
.reviewerTelegramUsernames(reviewerTelegramUsernames)
|
||||
.milestone(mergeRequest.getMilestone())
|
||||
.projectName(projectName)
|
||||
.targetBranch(mergeRequest.getTargetBranch())
|
||||
.sourceBranch(mergeRequest.getSourceBranch())
|
||||
.description(mergeRequest.getDescription())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
final Optional<String> optAuthorUserName = personService.getTelegramUsernamesByPersonIds(mergeRequest.getAuthor().getId());
|
||||
if (optAuthorUserName.isPresent()) {
|
||||
final String authorUsername = optAuthorUserName.get();
|
||||
notifyService.send(
|
||||
NoReviewerGroupNotify.builder()
|
||||
.ownerTelegramUsername(authorUsername)
|
||||
.title(mergeRequest.getTitle())
|
||||
.url(mergeRequest.getWebUrl())
|
||||
.milestone(mergeRequest.getMilestone())
|
||||
.projectName(projectName)
|
||||
.targetBranch(mergeRequest.getTargetBranch())
|
||||
.sourceBranch(mergeRequest.getSourceBranch())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//TODO [03.09.2024|uPagge]: Уведомление о конфликте
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ gitlab-bot:
|
||||
person:
|
||||
telegram-id: ${TELEGRAM_PERSON_ID}
|
||||
group-notify:
|
||||
chat-id: "-1002233809566"
|
||||
thread-id: "2"
|
||||
chat-id: ${TELEGRAM_CHAT_ID:}
|
||||
thread-id: ${TELEGRAM_THREAD_ID:}
|
||||
gitlab-sdk:
|
||||
access-token: ${GITLAB_PERSONAL_TOKEN}
|
||||
base-url: ${GITLAB_URL}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify.group;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupPersonalNotify;
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NewMergeRequestGroupNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
@ -16,10 +16,10 @@ import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NewMergeRequestGroupNotifyGenerator implements NotifyBoxAnswerGenerator<NewMergeRequestGroupPersonalNotify> {
|
||||
public class NewMergeRequestGroupNotifyGenerator implements NotifyBoxAnswerGenerator<NewMergeRequestGroupNotify> {
|
||||
|
||||
@Override
|
||||
public BoxAnswer generate(NewMergeRequestGroupPersonalNotify notify) {
|
||||
public BoxAnswer generate(NewMergeRequestGroupNotify notify) {
|
||||
final String reviewerUsernames = String.join(", ", notify.getReviewerTelegramUsernames().values());
|
||||
final StringBuilder builder = new StringBuilder(Icons.FUN)
|
||||
.append("*You are reviewers:* ").append(reviewerUsernames)
|
||||
@ -59,7 +59,7 @@ public class NewMergeRequestGroupNotifyGenerator implements NotifyBoxAnswerGener
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return NewMergeRequestGroupPersonalNotify.TYPE;
|
||||
return NewMergeRequestGroupNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package dev.struchkov.bot.gitlab.telegram.service.notify.group;
|
||||
|
||||
import dev.struchkov.bot.gitlab.context.domain.notify.group.mr.NoReviewerGroupNotify;
|
||||
import dev.struchkov.bot.gitlab.context.utils.Icons;
|
||||
import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.SimpleKeyBoardLine.keyBoardLine;
|
||||
import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton;
|
||||
import static dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload.ENABLE_MARKDOWN;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class NoReviewerGroupNotifyGenerator implements NotifyBoxAnswerGenerator<NoReviewerGroupNotify> {
|
||||
|
||||
@Override
|
||||
public BoxAnswer generate(NoReviewerGroupNotify notify) {
|
||||
final StringBuilder builder = new StringBuilder(Icons.DANGEROUS)
|
||||
.append(notify.getOwnerTelegramUsername())
|
||||
.append(", *your merge request does not have reviewers*")
|
||||
.append(Icons.HR)
|
||||
.append(escapeMarkdown(notify.getTitle()));
|
||||
|
||||
builder.append(Icons.HR);
|
||||
|
||||
if (checkNotNull(notify.getProjectName())) {
|
||||
builder.append(Icons.PROJECT).append(": ").append(escapeMarkdown(notify.getProjectName())).append("\n");
|
||||
}
|
||||
|
||||
if (checkNotNull(notify.getMilestone())) {
|
||||
builder.append(Icons.MILESTONE).append(": ").append(notify.getMilestone()).append("\n");
|
||||
}
|
||||
|
||||
builder
|
||||
.append(Icons.TREE).append(": ").append(escapeMarkdown(notify.getSourceBranch())).append(Icons.ARROW).append(escapeMarkdown(notify.getTargetBranch())).append("\n");
|
||||
|
||||
if (checkNotNull(notify.getAssignee())) {
|
||||
builder.append(Icons.ASSIGNEE).append(": ").append(notify.getAssignee());
|
||||
}
|
||||
|
||||
final String notifyMessage = builder.toString();
|
||||
|
||||
return BoxAnswer.builder()
|
||||
.message(notifyMessage)
|
||||
.keyBoard(inlineKeyBoard(
|
||||
keyBoardLine(
|
||||
urlButton(Icons.LINK, notify.getUrl())
|
||||
)
|
||||
))
|
||||
.payload(ENABLE_MARKDOWN)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNotifyType() {
|
||||
return NoReviewerGroupNotify.TYPE;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user