Добавил идентификацыию реп в уведомления

This commit is contained in:
upagge 2020-10-16 09:52:27 +03:00
parent 5dd2f32986
commit 0bb74203ea
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
9 changed files with 84 additions and 29 deletions

View File

@ -14,18 +14,20 @@ public class ConflictPrNotify extends PrNotify {
private ConflictPrNotify( private ConflictPrNotify(
Set<String> recipients, Set<String> recipients,
String name, String name,
String url String url,
String projectKey,
String repositorySlug
) { ) {
super(recipients, name, url); super(recipients, projectKey, repositorySlug, name, url);
} }
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Внимание конфликт в ПР*" + "{0} *Внимание конфликт в ПР | {4} | {5}*" +
"{1}" + "{1}" +
"[{2}]({3})\n\n", "[{2}]({3})\n\n",
Smile.DANGEROUS, Smile.HR, title, url Smile.DANGEROUS, Smile.HR, title, url, projectKey, repositorySlug
); );
} }

View File

@ -16,16 +16,22 @@ import java.util.Set;
public class ForgottenSmartPrNotify extends PrNotify { public class ForgottenSmartPrNotify extends PrNotify {
@Builder @Builder
protected ForgottenSmartPrNotify(Set<String> recipients, String title, String url) { protected ForgottenSmartPrNotify(
super(recipients, title, url); Set<String> recipients,
String title,
String url,
String projectKey,
String repositorySlug
) {
super(recipients, projectKey, repositorySlug, title, url);
} }
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Напоминание о просмотре PullRequest*" + "{0} *Напоминание о просмотре PullRequest | {4} | {5}*" +
"{3}[{1}]({2})", "{3}[{1}]({2})",
Smile.SMART, title, url, Smile.HR Smile.SMART, title, url, Smile.HR, projectKey, repositorySlug
); );
} }

View File

@ -19,8 +19,11 @@ public class NewPrNotify extends PrNotify {
String title, String title,
String url, String url,
String description, String description,
String author) { String author,
super(recipients, title, url); String projectKey,
String repositorySlug
) {
super(recipients, projectKey, repositorySlug, title, url);
this.description = description; this.description = description;
this.author = author; this.author = author;
} }
@ -28,12 +31,12 @@ public class NewPrNotify extends PrNotify {
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Новый Pull Request*{1}" + "{0} *Новый PullRequest | {7} | {8}*{1}" +
"[{2}]({3})" + "[{2}]({3})" +
"{1}{4}{5}: {6}\n\n", "{1}{4}{5}: {6}\n\n",
Smile.FUN, Smile.HR, title, url, Smile.FUN, Smile.HR, title, url,
(description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "", (description != null && !"".equals(description)) ? escapeMarkdown(description) + Smile.HR : "",
Smile.AUTHOR, author Smile.AUTHOR, author, projectKey, repositorySlug
); );
} }

View File

@ -9,11 +9,21 @@ import java.util.Set;
@Getter @Getter
public abstract class PrNotify extends Notify { public abstract class PrNotify extends Notify {
protected final String projectKey;
protected final String repositorySlug;
protected final String title; protected final String title;
protected final String url; protected final String url;
protected PrNotify(Set<String> recipients, String title, String url) { protected PrNotify(
Set<String> recipients,
String projectKey,
String repositorySlug,
String title,
String url
) {
super(EntityType.PERSON, recipients); super(EntityType.PERSON, recipients);
this.projectKey = projectKey;
this.repositorySlug = repositorySlug;
this.title = title; this.title = title;
this.url = url; this.url = url;
} }

View File

@ -24,8 +24,11 @@ public class ReviewersPrNotify extends PrNotify {
Set<String> recipients, Set<String> recipients,
String title, String title,
String url, String url,
List<ReviewerChange> reviewerChanges) { String projectKey,
super(recipients, title, url); String repositorySlug,
List<ReviewerChange> reviewerChanges
) {
super(recipients, projectKey, repositorySlug, title, url);
this.reviewerChanges = reviewerChanges; this.reviewerChanges = reviewerChanges;
} }
@ -60,7 +63,7 @@ public class ReviewersPrNotify extends PrNotify {
); );
} }
final String createMessage = stringBuilder.toString(); final String createMessage = stringBuilder.toString();
return Smile.PEN + " *Изменения ревьюверов | PullRequest*" + return Smile.PEN + " *Изменения ревьюверов PullRequest | " + projectKey + " | " + repositorySlug + "*" +
Smile.HR + Smile.HR +
"[" + title + "](" + url + ")" + Smile.HR + "[" + title + "](" + url + ")" + Smile.HR +
createMessage; createMessage;

View File

@ -19,19 +19,27 @@ public class SmartPrNotify extends PrNotify {
private final Reviewer reviewerTriggered; private final Reviewer reviewerTriggered;
@Builder @Builder
protected SmartPrNotify(Set<String> recipients, String title, String url, Reviewer reviewerTriggered) { protected SmartPrNotify(
super(recipients, title, url); Set<String> recipients,
String title,
String url,
String projectKey,
String repositorySlug,
Reviewer reviewerTriggered
) {
super(recipients, projectKey, repositorySlug, title, url);
this.reviewerTriggered = reviewerTriggered; this.reviewerTriggered = reviewerTriggered;
} }
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Напоминание о просмотре PullRequest*" + "{0} *Напоминание о PullRequest | {6} | {7}*" +
"{3}[{1}]({2})" + "{3}[{1}]({2})" +
"{3}" + "{3}" +
"{4} изменил свое решение на {5}\n\n", "{4} изменил свое решение на {5}\n\n",
Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(), reviewerTriggered.getStatus().getValue() Smile.SMART, title, url, Smile.HR, reviewerTriggered.getPersonLogin(), reviewerTriggered.getStatus().getValue(),
projectKey, repositorySlug
); );
} }

View File

@ -19,9 +19,12 @@ public class StatusPrNotify extends PrNotify {
Set<String> recipients, Set<String> recipients,
String name, String name,
String url, String url,
String projectKey,
String repositorySlug,
PullRequestStatus oldStatus, PullRequestStatus oldStatus,
PullRequestStatus newStatus) { PullRequestStatus newStatus
super(recipients, name, url); ) {
super(recipients, projectKey, repositorySlug, name, url);
this.oldStatus = oldStatus; this.oldStatus = oldStatus;
this.newStatus = newStatus; this.newStatus = newStatus;
} }
@ -29,10 +32,10 @@ public class StatusPrNotify extends PrNotify {
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Изменился статус вашего ПР*{1}" + "{0} *Изменился статус PullRequest | {7} | {8}*{1}" +
"[{2}]({3}){1}" + "[{2}]({3}){1}" +
"{4} {5} {6}\n\n", "{4} {5} {6}\n\n",
Smile.PEN, Smile.HR, title, url, oldStatus.name(), Smile.ARROW, newStatus.name() Smile.PEN, Smile.HR, title, url, oldStatus.name(), Smile.ARROW, newStatus.name(), projectKey, repositorySlug
); );
} }

View File

@ -16,19 +16,23 @@ public class UpdatePrNotify extends PrNotify {
private UpdatePrNotify( private UpdatePrNotify(
Set<String> recipients, Set<String> recipients,
String name, String name,
String url, String author) { String url,
super(recipients, name, url); String author,
String projectKey,
String repositorySlug
) {
super(recipients, projectKey, repositorySlug, name, url);
this.author = author; this.author = author;
} }
@Override @Override
public String generateMessage() { public String generateMessage() {
return MessageFormat.format( return MessageFormat.format(
"{0} *Обновление PullRequest*\n" + "{0} *Обновление PullRequest | {6} | {7}*{3}" +
"[{1}]({2})" + "[{1}]({2})" +
"{3}" + "{3}" +
"{4}: {5}\n\n", "{4}: {5}\n\n",
Smile.UPDATE, title, url, Smile.HR, Smile.AUTHOR, author Smile.UPDATE, title, url, Smile.HR, Smile.AUTHOR, author, projectKey, repositorySlug
); );
} }

View File

@ -80,6 +80,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
.description(newPullRequest.getDescription()) .description(newPullRequest.getDescription())
.title(newPullRequest.getTitle()) .title(newPullRequest.getTitle())
.url(newPullRequest.getUrl()) .url(newPullRequest.getUrl())
.projectKey(newPullRequest.getProjectKey())
.repositorySlug(newPullRequest.getRepositorySlug())
.recipients( .recipients(
newPullRequest.getReviewers().stream() newPullRequest.getReviewers().stream()
.map(Reviewer::getPersonLogin) .map(Reviewer::getPersonLogin)
@ -122,6 +124,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
if (!smartReviewers.isEmpty()) { if (!smartReviewers.isEmpty()) {
notifyService.send( notifyService.send(
ForgottenSmartPrNotify.builder() ForgottenSmartPrNotify.builder()
.projectKey(pullRequest.getProjectKey())
.repositorySlug(pullRequest.getRepositorySlug())
.recipients(smartReviewers) .recipients(smartReviewers)
.title(pullRequest.getTitle()) .title(pullRequest.getTitle())
.url(pullRequest.getUrl()) .url(pullRequest.getUrl())
@ -132,7 +136,9 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
} }
private void updateBitbucketVersion(PullRequest oldPullRequest, PullRequest pullRequest) { private void updateBitbucketVersion(PullRequest oldPullRequest, PullRequest pullRequest) {
if (!oldPullRequest.getBitbucketVersion().equals(pullRequest.getBitbucketVersion())) { if (
!oldPullRequest.getBitbucketVersion().equals(pullRequest.getBitbucketVersion())
) {
oldPullRequest.setBitbucketVersion(pullRequest.getBitbucketVersion()); oldPullRequest.setBitbucketVersion(pullRequest.getBitbucketVersion());
notifyService.send( notifyService.send(
UpdatePrNotify.builder() UpdatePrNotify.builder()
@ -144,6 +150,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
.collect(Collectors.toSet()) .collect(Collectors.toSet())
) )
.url(oldPullRequest.getUrl()) .url(oldPullRequest.getUrl())
.projectKey(oldPullRequest.getProjectKey())
.repositorySlug(oldPullRequest.getRepositorySlug())
.build() .build()
); );
} }
@ -155,6 +163,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
ConflictPrNotify.builder() ConflictPrNotify.builder()
.name(pullRequest.getTitle()) .name(pullRequest.getTitle())
.url(pullRequest.getUrl()) .url(pullRequest.getUrl())
.projectKey(pullRequest.getProjectKey())
.repositorySlug(pullRequest.getRepositorySlug())
.recipients(Collections.singleton(pullRequest.getAuthorLogin())) .recipients(Collections.singleton(pullRequest.getAuthorLogin()))
.build() .build()
); );
@ -171,6 +181,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
StatusPrNotify.builder() StatusPrNotify.builder()
.name(newPullRequest.getTitle()) .name(newPullRequest.getTitle())
.url(oldPullRequest.getUrl()) .url(oldPullRequest.getUrl())
.projectKey(oldPullRequest.getProjectKey())
.repositorySlug(oldPullRequest.getRepositorySlug())
.newStatus(newStatus) .newStatus(newStatus)
.oldStatus(oldStatus) .oldStatus(oldStatus)
.recipients(Collections.singleton(oldPullRequest.getAuthorLogin())) .recipients(Collections.singleton(oldPullRequest.getAuthorLogin()))
@ -234,6 +246,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
ReviewersPrNotify.builder() ReviewersPrNotify.builder()
.title(newPullRequest.getTitle()) .title(newPullRequest.getTitle())
.url(newPullRequest.getUrl()) .url(newPullRequest.getUrl())
.projectKey(newPullRequest.getProjectKey())
.repositorySlug(newPullRequest.getRepositorySlug())
.recipients(Collections.singleton(newPullRequest.getAuthorLogin())) .recipients(Collections.singleton(newPullRequest.getAuthorLogin()))
.reviewerChanges(reviewerChanges) .reviewerChanges(reviewerChanges)
.build() .build()
@ -256,6 +270,8 @@ public class PullRequestsServiceImpl extends AbstractSimpleManagerService<PullRe
.reviewerTriggered(newReviewer) .reviewerTriggered(newReviewer)
.title(oldPullRequest.getTitle()) .title(oldPullRequest.getTitle())
.url(oldPullRequest.getUrl()) .url(oldPullRequest.getUrl())
.projectKey(oldPullRequest.getProjectKey())
.repositorySlug(oldPullRequest.getRepositorySlug())
.recipients( .recipients(
smartReviewers.stream() smartReviewers.stream()
.map(Reviewer::getPersonLogin) .map(Reviewer::getPersonLogin)