Общий рефакторинг
This commit is contained in:
parent
c06554a42b
commit
d7fcbf549a
@ -24,7 +24,6 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -201,7 +200,7 @@ public class SchedulerPullRequest {
|
|||||||
.map(test -> conversionService.convert(test.getValue(), PullRequest.class))
|
.map(test -> conversionService.convert(test.getValue(), PullRequest.class))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
final List<PullRequest> newPullRequests = pullRequestsService.addAll(newPullRequest);
|
final List<PullRequest> newPullRequests = pullRequestsService.addAll(newPullRequest);
|
||||||
sendNotification(newPullRequests);
|
sendNotificationNewPullRequest(newPullRequests);
|
||||||
if (pullRequestBitbucketSheet.getNextPageStart() != null) {
|
if (pullRequestBitbucketSheet.getNextPageStart() != null) {
|
||||||
sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen() + pullRequestBitbucketSheet.getNextPageStart(), bitbucketConfig.getToken(), PullRequestSheetJson.class);
|
sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen() + pullRequestBitbucketSheet.getNextPageStart(), bitbucketConfig.getToken(), PullRequestSheetJson.class);
|
||||||
} else {
|
} else {
|
||||||
@ -211,35 +210,22 @@ public class SchedulerPullRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotification(@NonNull List<PullRequest> newPullRequests) {
|
private void sendNotificationNewPullRequest(@NonNull List<PullRequest> newPullRequests) {
|
||||||
if (!newPullRequests.isEmpty()) {
|
if (!newPullRequests.isEmpty()) {
|
||||||
Map<Long, StringBuilder> map = new HashMap<>();
|
|
||||||
newPullRequests.forEach(
|
newPullRequests.forEach(
|
||||||
pullRequest -> pullRequest.getReviewers().forEach(
|
pullRequest -> pullRequest.getReviewers().stream()
|
||||||
reviewer -> test(pullRequest, reviewer, map)
|
.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))
|
||||||
|
.build()
|
||||||
|
))
|
||||||
);
|
);
|
||||||
map.forEach((key, value) -> messageSendService.add(MessageSend.builder().telegramId(key).message(value.toString()).build()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void test(PullRequest pullRequest, Reviewer reviewer, Map<Long, StringBuilder> map) {
|
|
||||||
userService.getByLogin(reviewer.getUser()).ifPresent(
|
|
||||||
user -> {
|
|
||||||
final Long telegramId = user.getTelegramId();
|
|
||||||
if (telegramId != null) {
|
|
||||||
if (!map.containsKey(telegramId)) {
|
|
||||||
map.put(telegramId, new StringBuilder());
|
|
||||||
}
|
|
||||||
map.get(telegramId).append("\uD83C\uDF89 *Новый Pull Request*\n")
|
|
||||||
.append("[").append(pullRequest.getName()).append("](").append(pullRequest.getUrl()).append(")\n")
|
|
||||||
.append("\uD83D\uDC68\u200D\uD83D\uDCBB️: ").append(pullRequest.getAuthor().getLogin())
|
|
||||||
.append("\n-- -- -- -- --\n")
|
|
||||||
.append("\uD83D\uDCCC: ").append("#").append(pullRequest.getAuthor().getLogin()).append(" #pullRequest")
|
|
||||||
.append("\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,4 @@ public interface PullRequestsService {
|
|||||||
|
|
||||||
void deleteAll(@NonNull Set<Long> id);
|
void deleteAll(@NonNull Set<Long> id);
|
||||||
|
|
||||||
Optional<PullRequest> update(PullRequest pullRequest);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,9 @@ public class MessageSendServiceImpl implements MessageSendService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@NonNull MessageSend messageSend) {
|
public void add(@NonNull MessageSend messageSend) {
|
||||||
|
messageSend.setMessage(
|
||||||
|
messageSend.getMessage().replace("localhost", "192.168.236.164:7990")
|
||||||
|
);
|
||||||
messageSendRepository.add(messageSend);
|
messageSendRepository.add(messageSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,14 +49,6 @@ public class PullRequestsServiceImpl implements PullRequestsService {
|
|||||||
return pullRequestsRepository.saveAll(updatePullRequests);
|
return pullRequestsRepository.saveAll(updatePullRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<PullRequest> update(PullRequest pullRequest) {
|
|
||||||
if (pullRequestsRepository.existsById(pullRequest.getId())) {
|
|
||||||
pullRequestsRepository.save(pullRequest);
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Long> getIdByBitbucketIdAndReposId(@NonNull Long bitbucketId, @NonNull Long repositoryId) {
|
public Optional<Long> getIdByBitbucketIdAndReposId(@NonNull Long bitbucketId, @NonNull Long repositoryId) {
|
||||||
return pullRequestsRepository.findIdByBitbucketIdAndRepositoryId(bitbucketId, repositoryId);
|
return pullRequestsRepository.findIdByBitbucketIdAndRepositoryId(bitbucketId, repositoryId);
|
||||||
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors;
|
|||||||
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.*;
|
import static com.tsc.bitbucketbot.domain.util.ReviewerChange.Type.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Добавить описание класса.
|
* Генерирует сообщения для отправки.
|
||||||
*
|
*
|
||||||
* @author upagge [07.02.2020]
|
* @author upagge [07.02.2020]
|
||||||
*/
|
*/
|
||||||
@ -29,10 +29,20 @@ public class Message {
|
|||||||
throw new IllegalStateException("Утилитарный класс");
|
throw new IllegalStateException("Утилитарный класс");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static String newPullRequest(PullRequest pullRequest) {
|
||||||
|
return "\uD83C\uDF89 *Новый Pull Request*\n" +
|
||||||
|
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")\n" +
|
||||||
|
"\uD83D\uDC68\u200D\uD83D\uDCBB️: " + pullRequest.getAuthor().getLogin() +
|
||||||
|
"\n-- -- -- -- --\n" +
|
||||||
|
"\uD83D\uDCCC: " + "#" + pullRequest.getAuthor().getLogin() + " #pullRequest" +
|
||||||
|
"\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
|
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
|
||||||
return "✏️ *Изменился статус вашего ПР*" + BREAK +
|
return "✏️ *Изменился статус вашего ПР*" + BREAK +
|
||||||
"[" + name + "](" + url.replace("localhost", "192.168.236.164") + ")" + BREAK +
|
"[" + name + "](" + url + ")" + BREAK +
|
||||||
oldStatus.name() + " -> " + newStatus.name() +
|
oldStatus.name() + " -> " + newStatus.name() +
|
||||||
BREAK + "-- -- -- --" + BREAK +
|
BREAK + "-- -- -- --" + BREAK +
|
||||||
"\uD83D\uDCCC: #pullRequest #change" +
|
"\uD83D\uDCCC: #pullRequest #change" +
|
||||||
@ -74,7 +84,7 @@ public class Message {
|
|||||||
if (!EMPTY.equalsIgnoreCase(createMessage)) {
|
if (!EMPTY.equalsIgnoreCase(createMessage)) {
|
||||||
return Optional.of(
|
return Optional.of(
|
||||||
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK +
|
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK +
|
||||||
"[" + pullRequest.getName() + "](" + pullRequest.getUrl().replace("localhost", "192.168.236.164") + ")" + BREAK +
|
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + BREAK +
|
||||||
createMessage
|
createMessage
|
||||||
+ "\n-- -- -- -- --"
|
+ "\n-- -- -- -- --"
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user