Новая прослойка Change

This commit is contained in:
upagge 2020-04-07 16:51:25 +03:00
parent 7fe3388207
commit 0f2179832d
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
21 changed files with 447 additions and 117 deletions

View File

@ -1,6 +1,5 @@
package com.tsc.bitbucketbot.dto;
package com.tsc.bitbucketbot.domain;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

View File

@ -1,8 +1,6 @@
package com.tsc.bitbucketbot.domain;
/**
* TODO: Добавить комментарий енума.
*
* @author upagge [31.01.2020]
*/
public enum PullRequestStatus {

View File

@ -0,0 +1,25 @@
package com.tsc.bitbucketbot.domain.change;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Set;
@Getter
@EqualsAndHashCode(of = "id")
public abstract class Change {
protected final ChangeType type;
protected final LocalDateTime localDateTime = LocalDateTime.now();
protected final Set<Long> telegramId;
@Setter
protected Long id;
protected Change(ChangeType type, Set<Long> telegramId) {
this.type = type;
this.telegramId = telegramId;
}
}

View File

@ -0,0 +1,7 @@
package com.tsc.bitbucketbot.domain.change;
public enum ChangeType {
STATUS_PR, UPDATE_PR, REVIEWERS, NEW_PR
}

View File

@ -0,0 +1,29 @@
package com.tsc.bitbucketbot.domain.change;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import java.util.Set;
@Getter
@EqualsAndHashCode(callSuper = true)
public class NewPrChange extends PrChange {
private final String description;
private final String author;
@Builder
private NewPrChange(
@Singular("telegramId") Set<Long> telegramId,
String name,
String url,
String description,
String author) {
super(ChangeType.NEW_PR, telegramId, name, url);
this.description = description;
this.author = author;
}
}

View File

@ -0,0 +1,21 @@
package com.tsc.bitbucketbot.domain.change;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import java.util.Set;
@Getter
@EqualsAndHashCode(callSuper = true)
public abstract class PrChange extends Change {
private final String name;
private final String url;
protected PrChange(ChangeType type, Set<Long> telegramId, String name, String url) {
super(type, telegramId);
this.name = name;
this.url = url;
}
}

View File

@ -0,0 +1,28 @@
package com.tsc.bitbucketbot.domain.change;
import com.tsc.bitbucketbot.domain.util.ReviewerChange;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import java.util.List;
import java.util.Set;
@Getter
@EqualsAndHashCode(callSuper = true)
public class ReviewersPrChange extends PrChange {
private final List<ReviewerChange> reviewerChanges;
@Builder
private ReviewersPrChange(
@Singular("telegramId") Set<Long> telegramId,
String name,
String url,
List<ReviewerChange> reviewerChanges) {
super(ChangeType.REVIEWERS, telegramId, name, url);
this.reviewerChanges = reviewerChanges;
}
}

View File

@ -0,0 +1,30 @@
package com.tsc.bitbucketbot.domain.change;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import java.util.Set;
@Getter
@EqualsAndHashCode(callSuper = true)
public class StatusPrChange extends PrChange {
private final PullRequestStatus oldStatus;
private final PullRequestStatus newStatus;
@Builder
private StatusPrChange(
@Singular("telegramId") Set<Long> telegramId,
String name,
String url,
PullRequestStatus oldStatus,
PullRequestStatus newStatus) {
super(ChangeType.STATUS_PR, telegramId, name, url);
this.oldStatus = oldStatus;
this.newStatus = newStatus;
}
}

View File

@ -0,0 +1,25 @@
package com.tsc.bitbucketbot.domain.change;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import java.util.Set;
@Getter
@EqualsAndHashCode(callSuper = true)
public class UpdatePrChange extends PrChange {
private final String author;
@Builder
private UpdatePrChange(
@Singular("telegramId") Set<Long> telegramId,
String name,
String url, String author) {
super(ChangeType.UPDATE_PR, telegramId, name, url);
this.author = author;
}
}

View File

@ -2,7 +2,7 @@ package com.tsc.bitbucketbot.exception;
class BitbucketBotException extends RuntimeException {
BitbucketBotException(String message) {
public BitbucketBotException(String message) {
super(message);
}

View File

@ -0,0 +1,9 @@
package com.tsc.bitbucketbot.exception;
public class NotFoundException extends BitbucketBotException {
public NotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,16 @@
package com.tsc.bitbucketbot.repository;
import com.tsc.bitbucketbot.domain.change.Change;
import lombok.NonNull;
import java.util.List;
public interface ChangeRepository {
void add(@NonNull Change change);
List<Change> getAll();
void deleteAll(@NonNull List<Change> changes);
}

View File

@ -0,0 +1,35 @@
package com.tsc.bitbucketbot.repository.impl;
import com.tsc.bitbucketbot.domain.change.Change;
import com.tsc.bitbucketbot.repository.ChangeRepository;
import lombok.NonNull;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
public class ChangeRepositoryImpl implements ChangeRepository {
private List<Change> list = new ArrayList<>();
private long count = 0;
@Override
public void add(@NonNull Change change) {
change.setId(count++);
list.add(change);
}
@Override
public List<Change> getAll() {
final ArrayList<Change> changes = new ArrayList<>(list);
return changes;
}
@Override
public void deleteAll(@NonNull List<Change> changes) {
list.removeAll(changes);
}
}

View File

@ -1,9 +1,9 @@
package com.tsc.bitbucketbot.repository.jpa;
import com.tsc.bitbucketbot.domain.IdAndStatusPr;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@ -34,8 +34,8 @@ public interface PullRequestsRepository extends JpaRepository<PullRequest, Long>
@Query("SELECT p FROM PullRequest p LEFT JOIN p.reviewers r WHERE p.author.login=:author AND r.status=:reviewerStatus")
List<PullRequest> findAllByAuthorAndReviewerStatus(@Param("author") String author, @Param("reviewerStatus") ReviewerStatus reviewerStatus);
@Query("SELECT new com.tsc.bitbucketbot.dto.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses")
Set<IdAndStatusPr> findAllIdByStatusIn(@Param("statuses") Collection<PullRequestStatus> statuses);
@Query("SELECT new com.tsc.bitbucketbot.domain.IdAndStatusPr(p.id, p.status) FROM PullRequest p WHERE p.status IN :statuses")
Set<IdAndStatusPr> findAllIdByStatusIn(@Param("statuses") Set<PullRequestStatus> statuses);
@Query("SELECT p.id from PullRequest p")
Set<Long> findAllIds();

View File

@ -0,0 +1,68 @@
package com.tsc.bitbucketbot.scheduler;
import com.tsc.bitbucketbot.domain.change.Change;
import com.tsc.bitbucketbot.domain.change.NewPrChange;
import com.tsc.bitbucketbot.domain.change.ReviewersPrChange;
import com.tsc.bitbucketbot.domain.change.StatusPrChange;
import com.tsc.bitbucketbot.domain.change.UpdatePrChange;
import com.tsc.bitbucketbot.exception.NotFoundException;
import com.tsc.bitbucketbot.service.ChangeService;
import com.tsc.bitbucketbot.service.MessageSendService;
import com.tsc.bitbucketbot.utils.Message;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class SchedulerChangeParsing {
private final MessageSendService messageSendService;
private final ChangeService changeService;
// @Scheduled(cron = "0 * * * * *")
@Scheduled(fixedRate = 5000)
public void parsing() {
final List<Change> newChange = changeService.getNew().stream()
.filter(change -> change.getTelegramId() != null && !change.getTelegramId().isEmpty())
.collect(Collectors.toList());
for (Change change : newChange) {
final String message = generateMessage(change);
System.out.println(message);
// change.getTelegramId().forEach(
// telegramId -> messageSendService.add(
// MessageSend.builder()
// .telegramId(telegramId)
// .message(message)
// .build()
// )
// );
}
}
private String generateMessage(@NonNull Change change) {
String message;
switch (change.getType()) {
case NEW_PR:
message = Message.generate(((NewPrChange) change));
break;
case REVIEWERS:
message = Message.generate(((ReviewersPrChange) change));
break;
case STATUS_PR:
message = Message.generate(((StatusPrChange) change));
break;
case UPDATE_PR:
message = Message.generate(((UpdatePrChange) change));
break;
default:
throw new NotFoundException("Нет обработчика для типа " + change.getType().name());
}
return message;
}
}

View File

@ -1,22 +1,23 @@
package com.tsc.bitbucketbot.scheduler;
import com.tsc.bitbucketbot.config.BitbucketConfig;
import com.tsc.bitbucketbot.domain.MessageSend;
import com.tsc.bitbucketbot.domain.IdAndStatusPr;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.change.NewPrChange;
import com.tsc.bitbucketbot.domain.change.ReviewersPrChange;
import com.tsc.bitbucketbot.domain.change.StatusPrChange;
import com.tsc.bitbucketbot.domain.change.UpdatePrChange;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.domain.entity.Reviewer;
import com.tsc.bitbucketbot.domain.entity.User;
import com.tsc.bitbucketbot.domain.util.ReviewerChange;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import com.tsc.bitbucketbot.dto.bitbucket.sheet.PullRequestSheetJson;
import com.tsc.bitbucketbot.service.MessageSendService;
import com.tsc.bitbucketbot.service.ChangeService;
import com.tsc.bitbucketbot.service.PullRequestsService;
import com.tsc.bitbucketbot.service.UserService;
import com.tsc.bitbucketbot.service.Utils;
import com.tsc.bitbucketbot.utils.Message;
import com.tsc.bitbucketbot.utils.Pair;
import com.tsc.bitbucketbot.utils.Smile;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.ConversionService;
@ -35,6 +36,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.DECLINED;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.DELETE;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.MERGED;
import static com.tsc.bitbucketbot.domain.PullRequestStatus.OPEN;
@ -49,7 +51,7 @@ public class SchedulerPullRequest {
private final PullRequestsService pullRequestsService;
private final UserService userService;
private final MessageSendService messageSendService;
private final ChangeService changeService;
private final ConversionService conversionService;
private final BitbucketConfig bitbucketConfig;
@ -72,10 +74,13 @@ public class SchedulerPullRequest {
final Set<PullRequest> deletePr = pullRequestsService.getAllById(ids);
deletePr.stream()
.filter(pullRequest -> pullRequest.getAuthor().getTelegramId() != null)
.forEach(pullRequest -> messageSendService.add(
MessageSend.builder()
.forEach(pullRequest -> changeService.add(
StatusPrChange.builder()
.name(pullRequest.getName())
.url(pullRequest.getUrl())
.oldStatus(pullRequest.getStatus())
.newStatus(DELETE)
.telegramId(pullRequest.getAuthor().getTelegramId())
.message(Message.statusPullRequest(pullRequest.getName(), pullRequest.getUrl(), pullRequest.getStatus(), PullRequestStatus.DELETE))
.build()
));
pullRequestsService.updateAll(
@ -98,12 +103,15 @@ public class SchedulerPullRequest {
.filter(pullRequest -> pullRequest.getId() != null)
.collect(Collectors.toList());
for (PullRequest pullRequest : newPrs) {
final User author = pullRequest.getAuthor();
final Long telegramId = author.getTelegramId();
if (telegramId != null) {
final String message = Message.statusPullRequest(pullRequest.getName(), pullRequest.getUrl(), PullRequestStatus.OPEN, pullRequest.getStatus());
messageSendService.add(MessageSend.builder().telegramId(telegramId).message(message).build());
}
changeService.add(
StatusPrChange.builder()
.name(pullRequest.getName())
.url(pullRequest.getUrl())
.oldStatus(pullRequest.getStatus())
.newStatus(OPEN)
.telegramId(pullRequest.getAuthor().getTelegramId())
.build()
);
}
ids.addAll(
@ -165,62 +173,37 @@ public class SchedulerPullRequest {
}
private void processingReviewer(PullRequest pullRequest, PullRequest newPullRequest) {
if (isUpdatePr(pullRequest, newPullRequest)) {
final Set<String> logins = newPullRequest.getReviewers().stream()
.map(Reviewer::getUser)
.collect(Collectors.toSet());
if (!logins.isEmpty()) {
Optional<String> optMessage = changeVersionPr(pullRequest, newPullRequest);
if (optMessage.isPresent()) {
final String message = optMessage.get();
userService.getAllTelegramIdByLogin(logins).forEach(
telegramId -> messageSendService.add(
MessageSend.builder()
.telegramId(telegramId)
.message(message)
final List<Long> telegramIds = userService.getAllTelegramIdByLogin(logins);
changeService.add(
UpdatePrChange.builder()
.name(newPullRequest.getName())
.url(newPullRequest.getUrl())
.author(newPullRequest.getAuthor().getLogin())
.telegramId(telegramIds)
.build()
)
);
}
}
}
@NonNull
private void processingAuthor(PullRequest pullRequest, PullRequest newPullRequest) {
final User author = pullRequest.getAuthor();
StringBuilder builderMessage = new StringBuilder();
if (author.getTelegramId() != null) {
changeStatusPR(pullRequest, newPullRequest).ifPresent(builderMessage::append);
changeReviewersPR(pullRequest, newPullRequest).ifPresent(builderMessage::append);
final String message = builderMessage.toString();
if (!Smile.Constants.EMPTY.equalsIgnoreCase(message)) {
messageSendService.add(
MessageSend.builder()
.message(message)
.telegramId(author.getTelegramId())
.build()
);
}
}
changeStatusPR(pullRequest, newPullRequest);
changeReviewersPR(pullRequest, newPullRequest);
}
@NonNull
private Optional<String> changeVersionPr(PullRequest pullRequest, PullRequest newPullRequest) {
private boolean isUpdatePr(PullRequest pullRequest, PullRequest newPullRequest) {
LocalDateTime oldDate = pullRequest.getUpdateDate();
LocalDateTime newDate = newPullRequest.getUpdateDate();
if (!oldDate.isEqual(newDate)) {
return Optional.of(
Message.updatePullRequest(
newPullRequest.getName(),
newPullRequest.getUrl(),
newPullRequest.getAuthor().getLogin()
)
);
}
return Optional.empty();
return !oldDate.isEqual(newDate);
}
@NonNull
private Optional<String> changeReviewersPR(PullRequest pullRequest, PullRequest newPullRequest) {
private void changeReviewersPR(PullRequest pullRequest, PullRequest newPullRequest) {
final Map<String, Reviewer> oldReviewers = pullRequest.getReviewers().stream()
.collect(Collectors.toMap(Reviewer::getUser, reviewer -> reviewer));
final Map<String, Reviewer> newReviewers = newPullRequest.getReviewers().stream()
@ -241,21 +224,36 @@ public class SchedulerPullRequest {
final Set<String> oldLogins = oldReviewers.keySet();
oldLogins.removeAll(newReviewers.keySet());
oldLogins.forEach(login -> reviewerChanges.add(ReviewerChange.ofDeleted(login)));
return Message.statusReviewers(pullRequest, reviewerChanges);
if (!reviewerChanges.isEmpty()) {
changeService.add(
ReviewersPrChange.builder()
.name(pullRequest.getName())
.url(pullRequest.getUrl())
.reviewerChanges(reviewerChanges)
.telegramId(newPullRequest.getAuthor().getTelegramId())
.build()
);
}
}
@NonNull
private Optional<String> changeStatusPR(PullRequest pullRequest, PullRequest newPullRequest) {
private void changeStatusPR(PullRequest pullRequest, PullRequest newPullRequest) {
final PullRequestStatus oldStatus = pullRequest.getStatus();
final PullRequestStatus newStatus = newPullRequest.getStatus();
if (!oldStatus.equals(newStatus)) {
return Optional.of(Message.statusPullRequest(pullRequest.getName(), pullRequest.getUrl(), oldStatus, newStatus));
changeService.add(
StatusPrChange.builder()
.name(newPullRequest.getName())
.url(newPullRequest.getUrl())
.oldStatus(oldStatus)
.newStatus(newStatus)
.telegramId(newPullRequest.getAuthor().getTelegramId())
.build()
);
}
return Optional.empty();
}
@Scheduled(fixedRate = 30000)
public void checkNewPullRequest() {
final List<User> users = userService.getAllRegister();
@ -283,20 +281,21 @@ public class SchedulerPullRequest {
private void sendNotificationNewPullRequest(@NonNull List<PullRequest> newPullRequests) {
if (!newPullRequests.isEmpty()) {
newPullRequests.forEach(
pullRequest -> pullRequest.getReviewers().stream()
.map(reviewer -> userService.getByLogin(reviewer.getUser()))
.filter(Optional::isPresent)
.map(Optional::get)
.filter(user -> user.getTelegramId() != null)
.forEach(user -> messageSendService.add(
MessageSend.builder()
.telegramId(user.getTelegramId())
.message(Message.newPullRequest(pullRequest))
for (PullRequest newPullRequest : newPullRequests) {
final List<Long> reviewerTelegramIds = userService.getAllTelegramIdByLogin(newPullRequest.getReviewers().stream()
.map(Reviewer::getUser)
.collect(Collectors.toSet()));
changeService.add(
NewPrChange.builder()
.name(newPullRequest.getName())
.url(newPullRequest.getUrl())
.description(newPullRequest.getDescription())
.author(newPullRequest.getAuthor().getLogin())
.telegramId(reviewerTelegramIds)
.build()
))
);
}
}
}
}

View File

@ -0,0 +1,14 @@
package com.tsc.bitbucketbot.service;
import com.tsc.bitbucketbot.domain.change.Change;
import lombok.NonNull;
import java.util.List;
public interface ChangeService {
void add(@NonNull Change change);
List<Change> getNew();
}

View File

@ -1,10 +1,10 @@
package com.tsc.bitbucketbot.service;
import com.tsc.bitbucketbot.domain.IdAndStatusPr;
import com.tsc.bitbucketbot.domain.Pagination;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import lombok.NonNull;
import org.springframework.data.domain.Page;
@ -37,7 +37,7 @@ public interface PullRequestsService {
Set<Long> getAllId();
Set<IdAndStatusPr> getAllId(Collection<PullRequestStatus> statuses);
Set<IdAndStatusPr> getAllId(Set<PullRequestStatus> statuses);
Page<PullRequest> getAll(@NonNull Pagination pagination);

View File

@ -0,0 +1,31 @@
package com.tsc.bitbucketbot.service.impl;
import com.tsc.bitbucketbot.domain.change.Change;
import com.tsc.bitbucketbot.repository.ChangeRepository;
import com.tsc.bitbucketbot.service.ChangeService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ChangeServiceImpl implements ChangeService {
private final ChangeRepository changeRepository;
@Override
public void add(@NonNull Change change) {
changeRepository.add(change);
}
@Override
public List<Change> getNew() {
final List<Change> changes = changeRepository.getAll();
changeRepository.deleteAll(changes);
return changes;
}
}

View File

@ -1,10 +1,10 @@
package com.tsc.bitbucketbot.service.impl;
import com.tsc.bitbucketbot.domain.IdAndStatusPr;
import com.tsc.bitbucketbot.domain.Pagination;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.ReviewerStatus;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.dto.IdAndStatusPr;
import com.tsc.bitbucketbot.repository.jpa.PullRequestsRepository;
import com.tsc.bitbucketbot.service.PullRequestsService;
import lombok.NonNull;
@ -79,7 +79,7 @@ public class PullRequestsServiceImpl implements PullRequestsService {
}
@Override
public Set<IdAndStatusPr> getAllId(Collection<PullRequestStatus> statuses) {
public Set<IdAndStatusPr> getAllId(Set<PullRequestStatus> statuses) {
return pullRequestsRepository.findAllIdByStatusIn(statuses);
}

View File

@ -1,6 +1,9 @@
package com.tsc.bitbucketbot.utils;
import com.tsc.bitbucketbot.domain.PullRequestStatus;
import com.tsc.bitbucketbot.domain.change.NewPrChange;
import com.tsc.bitbucketbot.domain.change.ReviewersPrChange;
import com.tsc.bitbucketbot.domain.change.StatusPrChange;
import com.tsc.bitbucketbot.domain.change.UpdatePrChange;
import com.tsc.bitbucketbot.domain.entity.PullRequest;
import com.tsc.bitbucketbot.domain.util.ReviewerChange;
import com.tsc.bitbucketbot.dto.bitbucket.CommentJson;
@ -9,10 +12,11 @@ import lombok.NonNull;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.*;
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.DELETED;
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.NEW;
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.OLD;
/**
* Генерирует сообщения для отправки.
@ -24,36 +28,35 @@ public class Message {
private static final UpdateDataComparator COMPARATOR = new UpdateDataComparator();
private static final Integer PR_COUNT = 4;
private static final String DONATION_LINK = "https://www.tinkoff.ru/sl/1T9s4esiMf";
public static final String HELP_LINK = "https://nuzhnapomosh.ru/about/";
private static final String HELP_LINK = "https://nuzhnapomosh.ru/about/";
private Message() {
throw new IllegalStateException("Утилитарный класс");
}
@NonNull
public static String newPullRequest(PullRequest pullRequest) {
public static String generate(NewPrChange newPrChange) {
String message = Smile.FUN + " *Новый Pull Request*" + Smile.BR +
link(pullRequest.getName(), pullRequest.getUrl()) +
link(newPrChange.getName(), newPrChange.getUrl()) +
Smile.HR;
if (pullRequest.getDescription() != null && !"".equals(pullRequest.getDescription())) {
message += pullRequest.getDescription() + Smile.HR;
if (newPrChange.getDescription() != null && !"".equals(newPrChange.getDescription())) {
message += newPrChange.getDescription() + Smile.HR;
}
message += Smile.AUTHOR + ": " + pullRequest.getAuthor().getLogin() + Smile.TWO_BR;
message += Smile.AUTHOR + ": " + newPrChange.getAuthor() + Smile.TWO_BR;
return message;
}
@NonNull
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
public static String generate(@NonNull StatusPrChange change) {
return Smile.PEN + " *Изменился статус вашего ПР*" + Smile.HR +
link(name, url) + Smile.BR +
oldStatus.name() + " -> " + newStatus.name() +
link(change.getName(), change.getUrl()) + Smile.BR +
change.getOldStatus().name() + " -> " + change.getNewStatus().name() +
Smile.TWO_BR;
}
@NonNull
public static Optional<String> statusReviewers(PullRequest pullRequest, List<ReviewerChange> reviewerChanges) {
public static String generate(@NonNull ReviewersPrChange reviewersChange) {
StringBuilder stringBuilder = new StringBuilder();
final Map<ReviewerChange.Type, List<ReviewerChange>> changes = reviewerChanges.stream()
final Map<ReviewerChange.Type, List<ReviewerChange>> changes = reviewersChange.getReviewerChanges().stream()
.collect(Collectors.groupingBy(ReviewerChange::getType));
if (changes.containsKey(OLD)) {
stringBuilder.append(Smile.BR).append("Изменили свое решение:").append(Smile.BR);
@ -80,25 +83,18 @@ public class Message {
.map(ReviewerChange::getName).collect(Collectors.joining(","))
);
}
final String createMessage = stringBuilder.toString();
if (!Smile.Constants.EMPTY.equalsIgnoreCase(createMessage)) {
return Optional.of(
Smile.PEN + " *Изменения ревьюверов вашего ПР*" +
return Smile.PEN + " *Изменения ревьюверов вашего ПР*" +
Smile.HR +
link(pullRequest.getName(), pullRequest.getUrl()) + Smile.BR +
createMessage
);
}
return Optional.empty();
link(reviewersChange.getName(), reviewersChange.getUrl()) + Smile.BR +
createMessage;
}
@NonNull
public static String updatePullRequest(String pullRequestName, String prUrl, String author) {
public static String generate(@NonNull UpdatePrChange change) {
return Smile.UPDATE + " *Обновление Pull Request*" + Smile.BR +
link(pullRequestName, prUrl) +
link(change.getName(), change.getUrl()) +
Smile.HR +
Smile.AUTHOR + ": " + author +
Smile.AUTHOR + ": " + change.getAuthor() +
Smile.TWO_BR;
}