Новый функционал, собщение об обнволении пр
This commit is contained in:
parent
31ce2c6cd3
commit
c7b9a88a0f
@ -132,7 +132,42 @@ 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());
|
||||
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) {
|
||||
@ -140,12 +175,27 @@ public class SchedulerPullRequest {
|
||||
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());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return updatePullRequest;
|
||||
|
||||
@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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
@ -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>
|
Loading…
Reference in New Issue
Block a user