Новый функционал, собщение об обнволении пр

This commit is contained in:
upagge 2020-03-02 14:46:35 +03:00
parent 31ce2c6cd3
commit c7b9a88a0f
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
4 changed files with 84 additions and 22 deletions

View File

@ -132,22 +132,72 @@ public class SchedulerPullRequest {
private List<PullRequest> processingUpdate(Map<Long, PullRequest> newPullRequests, Set<PullRequest> pullRequests) {
List<PullRequest> updatePullRequest = new ArrayList<>();
for (PullRequest pullRequest : pullRequests) {
final PullRequest newPullRequest = newPullRequests.get(pullRequest.getId());
final User author = pullRequest.getAuthor();
StringBuilder stringBuilder = new StringBuilder();
if (author.getTelegramId() != null) {
changeStatusPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
changeReviewersPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
final String message = stringBuilder.toString();
if (!Message.EMPTY.equalsIgnoreCase(message)) {
updatePullRequest.add(newPullRequest);
messageSendService.add(MessageSend.builder().message(message).telegramId(author.getTelegramId()).build());
}
PullRequest newPullRequest = newPullRequests.get(pullRequest.getId());
@NonNull boolean author = processingAuthor(pullRequest, newPullRequest);
@NonNull boolean reviewer = processingReviewer(pullRequest, newPullRequest);
if (author || reviewer) {
updatePullRequest.add(newPullRequest);
}
}
return updatePullRequest;
}
private boolean processingReviewer(PullRequest pullRequest, PullRequest newPullRequest) {
StringBuilder stringBuilder = new StringBuilder();
changeVersionPr(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
String message = stringBuilder.toString();
if (!Message.EMPTY.equalsIgnoreCase(message)) {
newPullRequest.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.updatePullRequest(
newPullRequest.getName(),
newPullRequest.getUrl(),
newPullRequest.getAuthor().getLogin()))
.build())
);
return true;
}
return false;
}
@NonNull
private boolean processingAuthor(PullRequest pullRequest, PullRequest newPullRequest) {
final User author = pullRequest.getAuthor();
StringBuilder stringBuilder = new StringBuilder();
if (author.getTelegramId() != null) {
changeStatusPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
changeReviewersPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
final String message = stringBuilder.toString();
if (!Message.EMPTY.equalsIgnoreCase(message)) {
messageSendService.add(MessageSend.builder().message(message).telegramId(author.getTelegramId()).build());
return true;
}
}
return false;
}
@NonNull
private Optional<String> changeVersionPr(PullRequest pullRequest, PullRequest newPullRequest) {
Integer oldVersion = pullRequest.getVersion();
Integer newVersion = newPullRequest.getVersion();
if (!oldVersion.equals(newVersion)) {
return Optional.of(
Message.updatePullRequest(
newPullRequest.getName(),
newPullRequest.getUrl(),
newPullRequest.getAuthor().getLogin()
)
);
}
return Optional.empty();
}
@NonNull
private Optional<String> changeReviewersPR(PullRequest pullRequest, PullRequest newPullRequest) {
final Map<String, Reviewer> oldReviewers = pullRequest.getReviewers().stream()

View File

@ -24,6 +24,8 @@ public class Message {
private static final String TWO_BREAK = "\n\n";
private static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB";
private static final String SMILE_PEN = "✏️";
private static final String SMILE_UPDATE = "\uD83D\uDD04";
private static final String HR = "\n -- -- -- -- --\n";
private Message() {
throw new IllegalStateException("Утилитарный класс");
@ -33,19 +35,16 @@ public class Message {
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";
HR +
SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
TWO_BREAK;
}
@NonNull
public static String statusPullRequest(String name, String url, PullRequestStatus oldStatus, PullRequestStatus newStatus) {
return "✏️ *Изменился статус вашего ПР*" + BREAK +
return SMILE_PEN + " *Изменился статус вашего ПР*" + HR +
"[" + name + "](" + url + ")" + BREAK +
oldStatus.name() + " -> " + newStatus.name() +
BREAK + "-- -- -- --" + BREAK +
"\uD83D\uDCCC: #pullRequest #change" +
TWO_BREAK;
}
@ -84,13 +83,20 @@ public class Message {
if (!EMPTY.equalsIgnoreCase(createMessage)) {
return Optional.of(
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK +
HR +
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + BREAK +
createMessage
+ "\n-- -- -- -- --"
);
}
return Optional.empty();
}
@NonNull
public static String updatePullRequest(String pullRequestName, String prUrl, String author) {
return SMILE_UPDATE + " *Обновление Pull Request*" + BREAK +
"[" + pullRequestName + "](" + prUrl + ")" +
HR +
SMILE_AUTHOR + ": " + author +
TWO_BREAK;
}
}

View File

@ -4,6 +4,6 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<include file="liquibase/change-set/create-table.xml"/>
<include file="liquibase/change-set/v1.2.0"/>
<include file="liquibase/change-set/v1.2.0.xml"/>
</databaseChangeLog>

View File

@ -4,9 +4,15 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="v1.2.0-add-atribute-pr" author="upagge">
<addColumn tableName="pull_request">
<addColumn tableName="pull_request" schemaName="public" catalogName="pg_catalog">
<column name="version" type="integer"/>
</addColumn>
</changeSet>
<changeSet id="default-version" author="upagge">
<update tableName="pull_request" schemaName="public" catalogName="pg_catalog">
<column name="version" value="0" type="integer"/>
</update>
</changeSet>
</databaseChangeLog>