Новый функционал, собщение об обнволении пр
This commit is contained in:
parent
31ce2c6cd3
commit
c7b9a88a0f
@ -132,22 +132,72 @@ public class SchedulerPullRequest {
|
|||||||
private List<PullRequest> processingUpdate(Map<Long, PullRequest> newPullRequests, Set<PullRequest> pullRequests) {
|
private List<PullRequest> processingUpdate(Map<Long, PullRequest> newPullRequests, Set<PullRequest> pullRequests) {
|
||||||
List<PullRequest> updatePullRequest = new ArrayList<>();
|
List<PullRequest> updatePullRequest = new ArrayList<>();
|
||||||
for (PullRequest pullRequest : pullRequests) {
|
for (PullRequest pullRequest : pullRequests) {
|
||||||
final PullRequest newPullRequest = newPullRequests.get(pullRequest.getId());
|
PullRequest newPullRequest = newPullRequests.get(pullRequest.getId());
|
||||||
final User author = pullRequest.getAuthor();
|
@NonNull boolean author = processingAuthor(pullRequest, newPullRequest);
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
@NonNull boolean reviewer = processingReviewer(pullRequest, newPullRequest);
|
||||||
if (author.getTelegramId() != null) {
|
if (author || reviewer) {
|
||||||
changeStatusPR(pullRequest, newPullRequest).ifPresent(stringBuilder::append);
|
updatePullRequest.add(newPullRequest);
|
||||||
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 updatePullRequest;
|
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
|
@NonNull
|
||||||
private Optional<String> changeReviewersPR(PullRequest pullRequest, PullRequest newPullRequest) {
|
private Optional<String> changeReviewersPR(PullRequest pullRequest, PullRequest newPullRequest) {
|
||||||
final Map<String, Reviewer> oldReviewers = pullRequest.getReviewers().stream()
|
final Map<String, Reviewer> oldReviewers = pullRequest.getReviewers().stream()
|
||||||
|
@ -24,6 +24,8 @@ public class Message {
|
|||||||
private static final String TWO_BREAK = "\n\n";
|
private static final String TWO_BREAK = "\n\n";
|
||||||
private static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB️";
|
private static final String SMILE_AUTHOR = "\uD83D\uDC68\u200D\uD83D\uDCBB️";
|
||||||
private static final String SMILE_PEN = "✏️";
|
private static final String SMILE_PEN = "✏️";
|
||||||
|
private static final String SMILE_UPDATE = "\uD83D\uDD04";
|
||||||
|
private static final String HR = "\n -- -- -- -- --\n";
|
||||||
|
|
||||||
private Message() {
|
private Message() {
|
||||||
throw new IllegalStateException("Утилитарный класс");
|
throw new IllegalStateException("Утилитарный класс");
|
||||||
@ -33,19 +35,16 @@ public class Message {
|
|||||||
public static String newPullRequest(PullRequest pullRequest) {
|
public static String newPullRequest(PullRequest pullRequest) {
|
||||||
return "\uD83C\uDF89 *Новый Pull Request*\n" +
|
return "\uD83C\uDF89 *Новый Pull Request*\n" +
|
||||||
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")\n" +
|
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")\n" +
|
||||||
"\uD83D\uDC68\u200D\uD83D\uDCBB️: " + pullRequest.getAuthor().getLogin() +
|
HR +
|
||||||
"\n-- -- -- -- --\n" +
|
SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
|
||||||
"\uD83D\uDCCC: " + "#" + pullRequest.getAuthor().getLogin() + " #pullRequest" +
|
TWO_BREAK;
|
||||||
"\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 SMILE_PEN + " *Изменился статус вашего ПР*" + HR +
|
||||||
"[" + name + "](" + url + ")" + BREAK +
|
"[" + name + "](" + url + ")" + BREAK +
|
||||||
oldStatus.name() + " -> " + newStatus.name() +
|
oldStatus.name() + " -> " + newStatus.name() +
|
||||||
BREAK + "-- -- -- --" + BREAK +
|
|
||||||
"\uD83D\uDCCC: #pullRequest #change" +
|
|
||||||
TWO_BREAK;
|
TWO_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +83,20 @@ public class Message {
|
|||||||
if (!EMPTY.equalsIgnoreCase(createMessage)) {
|
if (!EMPTY.equalsIgnoreCase(createMessage)) {
|
||||||
return Optional.of(
|
return Optional.of(
|
||||||
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK +
|
SMILE_PEN + " *Изменения ревьюверов вашего ПР*" + BREAK +
|
||||||
|
HR +
|
||||||
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + BREAK +
|
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" + BREAK +
|
||||||
createMessage
|
createMessage
|
||||||
+ "\n-- -- -- -- --"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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">
|
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/create-table.xml"/>
|
||||||
<include file="liquibase/change-set/v1.2.0"/>
|
<include file="liquibase/change-set/v1.2.0.xml"/>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</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">
|
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">
|
<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"/>
|
<column name="version" type="integer"/>
|
||||||
</addColumn>
|
</addColumn>
|
||||||
</changeSet>
|
</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>
|
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user