Рабочая версия с датой создания и обновления
This commit is contained in:
parent
4c603effc7
commit
5b96965518
10
pom.xml
10
pom.xml
@ -30,11 +30,11 @@
|
|||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>com.google.code.gson</groupId>
|
<!-- <groupId>com.google.code.gson</groupId>-->
|
||||||
<artifactId>gson</artifactId>
|
<!-- <artifactId>gson</artifactId>-->
|
||||||
<version>2.8.5</version>
|
<!-- <version>2.8.5</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -17,4 +17,10 @@ public class AppConfig {
|
|||||||
return taskScheduler;
|
return taskScheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Bean
|
||||||
|
// public ObjectMapper objectMapper(ObjectMapper objectMapper) {
|
||||||
|
// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
// return objectMapper;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,4 +71,10 @@ public class PullRequest {
|
|||||||
@Column(name = "status")
|
@Column(name = "status")
|
||||||
private PullRequestStatus status;
|
private PullRequestStatus status;
|
||||||
|
|
||||||
|
@Column(name = "create_date")
|
||||||
|
private LocalDate createDate;
|
||||||
|
|
||||||
|
@Column(name = "update_date")
|
||||||
|
private LocalDate updateDate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.tsc.bitbucketbot.dto.bitbucket;
|
package com.tsc.bitbucketbot.dto.bitbucket;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.tsc.bitbucketbot.utils.LocalDateFromEpochDeserializer;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,6 +18,13 @@ public class PullRequestJson {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private Integer version;
|
private Integer version;
|
||||||
private PullRequestState state;
|
private PullRequestState state;
|
||||||
|
|
||||||
|
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class)
|
||||||
|
private LocalDate createdDate;
|
||||||
|
|
||||||
|
@JsonDeserialize(using = LocalDateFromEpochDeserializer.class)
|
||||||
|
private LocalDate updatedDate;
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private LinkJson links;
|
private LinkJson links;
|
||||||
|
@ -9,4 +9,5 @@ import com.tsc.bitbucketbot.dto.bitbucket.Sheet;
|
|||||||
* @author upagge [02.02.2020]
|
* @author upagge [02.02.2020]
|
||||||
*/
|
*/
|
||||||
public class PullRequestSheetJson extends Sheet<PullRequestJson> {
|
public class PullRequestSheetJson extends Sheet<PullRequestJson> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.tsc.bitbucketbot.scheduler;
|
package com.tsc.bitbucketbot.scheduler;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.tsc.bitbucketbot.config.PushMessageConfig;
|
import com.tsc.bitbucketbot.config.PushMessageConfig;
|
||||||
import com.tsc.bitbucketbot.domain.MessageSend;
|
import com.tsc.bitbucketbot.domain.MessageSend;
|
||||||
import com.tsc.bitbucketbot.service.MessageSendService;
|
import com.tsc.bitbucketbot.service.MessageSendService;
|
||||||
@ -30,7 +31,7 @@ public class SchedulerPushMessageSend {
|
|||||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||||
|
|
||||||
private final MessageSendService messageSendService;
|
private final MessageSendService messageSendService;
|
||||||
private final Gson gson = new Gson();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private final PushMessageConfig pushMessageConfig;
|
private final PushMessageConfig pushMessageConfig;
|
||||||
private OkHttpClient client;
|
private OkHttpClient client;
|
||||||
|
|
||||||
@ -61,7 +62,11 @@ public class SchedulerPushMessageSend {
|
|||||||
public void sendNewMessage() {
|
public void sendNewMessage() {
|
||||||
List<MessageSend> pushMessage = messageSendService.getPushMessage();
|
List<MessageSend> pushMessage = messageSendService.getPushMessage();
|
||||||
if (!pushMessage.isEmpty()) {
|
if (!pushMessage.isEmpty()) {
|
||||||
sendMessage(gson.toJson(pushMessage));
|
try {
|
||||||
|
sendMessage(objectMapper.writeValueAsString(pushMessage));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package com.tsc.bitbucketbot.service;
|
package com.tsc.bitbucketbot.service;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -16,9 +19,15 @@ import java.util.zip.GZIPInputStream;
|
|||||||
*
|
*
|
||||||
* @author upagge [30.01.2020]
|
* @author upagge [30.01.2020]
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
private static Gson gson = new Gson();
|
private static ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
static {
|
||||||
|
objectMapper = new ObjectMapper();
|
||||||
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
private Utils() {
|
private Utils() {
|
||||||
throw new IllegalStateException("Утилитарный класс");
|
throw new IllegalStateException("Утилитарный класс");
|
||||||
@ -54,7 +63,11 @@ public class Utils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (sb != null) {
|
if (sb != null) {
|
||||||
return Optional.of(gson.fromJson(sb.toString(), classOfT));
|
try {
|
||||||
|
return Optional.of(objectMapper.readValue(sb.toString(), classOfT));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public class PullRequestJsonConverter implements Converter<PullRequestJson, Pull
|
|||||||
return PullRequest.builder()
|
return PullRequest.builder()
|
||||||
.bitbucketId(json.getId())
|
.bitbucketId(json.getId())
|
||||||
.version(json.getVersion())
|
.version(json.getVersion())
|
||||||
|
.createDate(json.getCreatedDate())
|
||||||
|
.updateDate(json.getUpdatedDate())
|
||||||
.repositoryId(json.getFromRef().getRepository().getId())
|
.repositoryId(json.getFromRef().getRepository().getId())
|
||||||
.author(this.convertUser(json.getAuthor().getUser()))
|
.author(this.convertUser(json.getAuthor().getUser()))
|
||||||
.name(json.getTitle())
|
.name(json.getTitle())
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.tsc.bitbucketbot.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class LocalDateFromEpochDeserializer extends JsonDeserializer<LocalDate> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDate deserialize(JsonParser jp, DeserializationContext ctxt) {
|
||||||
|
try {
|
||||||
|
Long time = jp.readValueAs(Long.class);
|
||||||
|
Instant instant = Instant.ofEpochMilli(time);
|
||||||
|
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
|
||||||
|
return localDate;
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return LocalDate.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,17 +24,19 @@ 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_NEW_PR = "\uD83C\uDF89";
|
||||||
private static final String SMILE_UPDATE = "\uD83D\uDD04";
|
private static final String SMILE_UPDATE = "\uD83D\uDD04";
|
||||||
private static final String HR = "\n -- -- -- -- --\n";
|
private static final String HR = "\n -- -- -- -- --\n";
|
||||||
|
|
||||||
|
|
||||||
private Message() {
|
private Message() {
|
||||||
throw new IllegalStateException("Утилитарный класс");
|
throw new IllegalStateException("Утилитарный класс");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String newPullRequest(PullRequest pullRequest) {
|
public static String newPullRequest(PullRequest pullRequest) {
|
||||||
return "\uD83C\uDF89 *Новый Pull Request*\n" +
|
return SMILE_NEW_PR + " *Новый Pull Request*" + BREAK +
|
||||||
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")\n" +
|
"[" + pullRequest.getName() + "](" + pullRequest.getUrl() + ")" +
|
||||||
HR +
|
HR +
|
||||||
SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
|
SMILE_AUTHOR + ": " + pullRequest.getAuthor().getLogin() +
|
||||||
TWO_BREAK;
|
TWO_BREAK;
|
||||||
|
@ -15,4 +15,14 @@
|
|||||||
</update>
|
</update>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet id="date-update-pr" author="upagge">
|
||||||
|
<addColumn tableName="pull_request" schemaName="public" catalogName="pg_catalog">
|
||||||
|
<column name="create_date" type="date"/>
|
||||||
|
</addColumn>
|
||||||
|
|
||||||
|
<addColumn tableName="pull_request" schemaName="public" catalogName="pg_catalog">
|
||||||
|
<column name="update_date" type="date"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user