Вроде работает

This commit is contained in:
upagge 2020-10-31 03:48:19 +03:00
parent d1deff5e6f
commit 3af712ffc0
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
130 changed files with 775 additions and 594 deletions

6
bitbucket-app/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM openjdk:8-jdk-alpine
MAINTAINER uPagge
RUN addgroup -S bitbucketbot && adduser -S bitbucketbot -G bitbucketbot
USER bitbucketbot:bitbucketbot
COPY target/bitbucketbot.jar app.jar
ENTRYPOINT ["java", "-jar", "", "app.jar"]

View File

@ -14,6 +14,18 @@
<dependencies>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucketbot-core</artifactId>
<version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucketbot-data</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bot-core</artifactId>

View File

@ -5,9 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories(basePackages = {"org.sadtech.bot.vcs.core.repository.jpa", "org.sadtech.bot.vcs.teamcity.core.repository.jpa"})
@EnableJpaRepositories(basePackages = {"org.sadtech.bot.vcs.bitbucketbot.data.jpa", "org.sadtech.bot.vcs.teamcity.core.repository.jpa"})
@SpringBootApplication(scanBasePackages = "org.sadtech.bot.vcs")
@EntityScan(basePackages = {"org.sadtech.bot.vcs.core.domain.entity", "org.sadtech.bot.vcs.teamcity.core.domain.entity"})
@EntityScan(basePackages = {"org.sadtech.bot.vsc.bitbucketbot.context.domain.entity", "org.sadtech.bot.vcs.teamcity.core.domain.entity"})
public class BitbucketbotApplication {
public static void main(String[] args) {

View File

@ -1,14 +0,0 @@
package org.sadtech.bot.vcs.bitbucket.app.exception;
/**
* // TODO: 16.09.2020 Добавить описание.
*
* @author upagge 16.09.2020
*/
public class BitbucketAppException extends RuntimeException {
public BitbucketAppException(String message) {
super(message);
}
}

View File

@ -1,14 +0,0 @@
package org.sadtech.bot.vcs.bitbucket.app.exception;
/**
* // TODO: 16.09.2020 Добавить описание.
*
* @author upagge 16.09.2020
*/
public class ConvertException extends BitbucketAppException {
public ConvertException(String message) {
super(message);
}
}

View File

@ -2,7 +2,7 @@ package org.sadtech.bot.vcs.bitbucket.app.scheduler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vcs.core.service.parser.PullRequestParser;
import org.sadtech.bot.vsc.context.service.PullRequestParser;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

View File

@ -1,24 +1,23 @@
package org.sadtech.bot.vcs.bitbucket.app.scheduler;
/**
* // TODO: 01.10.2020 Добавить описание.
*
* @author upagge 01.10.2020
*/
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.domain.notify.SimpleTextNotify;
import org.sadtech.bot.vcs.core.service.NotifyService;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.core.service.RatingService;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.SimpleTextNotify;
import org.sadtech.bot.vsc.bitbucketbot.context.service.NotifyService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PersonService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.RatingService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
/**
* // TODO: 01.10.2020 Добавить описание.
*
* @author upagge 01.10.2020
*/
@Component
@RequiredArgsConstructor
public class RatingScheduler {

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.bitbucket.app.service;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.sadtech.basic.context.exception.NotFoundException;
import org.sadtech.basic.context.page.Sheet;
import org.sadtech.basic.core.page.PaginationImpl;
import org.sadtech.bot.vcs.bitbucket.app.config.property.CommentSchedulerProperty;
@ -10,15 +10,14 @@ import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.sadtech.bot.vcs.core.config.properties.InitProperty;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.exception.NotFoundException;
import org.sadtech.bot.vcs.core.service.CommentService;
import org.sadtech.bot.vcs.core.service.PullRequestsService;
import org.sadtech.bot.vcs.core.service.TaskService;
import org.sadtech.bot.vcs.core.service.Utils;
import org.sadtech.bot.vcs.core.utils.Utils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.service.CommentService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PullRequestsService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.TaskService;
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Component;
@ -34,7 +33,6 @@ import java.util.stream.Collectors;
* <p>К несчастью, у битбакета не очень удобный API, и у них таска это то же самое что и комментарий, только с флагом</p>
*/
@Component
@RequiredArgsConstructor
public class CommentAndTaskParser {
private final CommentService commentService;
@ -49,6 +47,26 @@ public class CommentAndTaskParser {
private boolean initStart = false;
public CommentAndTaskParser(
CommentService commentService,
PullRequestsService pullRequestsService,
ExecutorScanner executorScanner,
TaskService taskService,
ConversionService conversionService,
BitbucketProperty bitbucketProperty,
CommentSchedulerProperty commentSchedulerProperty,
InitProperty initProperty
) {
this.commentService = commentService;
this.pullRequestsService = pullRequestsService;
this.executorScanner = executorScanner;
this.taskService = taskService;
this.conversionService = conversionService;
this.bitbucketProperty = bitbucketProperty;
this.commentSchedulerProperty = commentSchedulerProperty;
this.initProperty = initProperty;
}
public void scanNewCommentAndTask() {
long commentId = getLastIdCommentOrTask() + 1;
int count = 0;

View File

@ -2,7 +2,7 @@ package org.sadtech.bot.vcs.bitbucket.app.service.executor;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.core.service.Utils;
import org.sadtech.bot.vcs.core.utils.Utils;
import java.util.Optional;
import java.util.concurrent.Callable;

View File

@ -4,10 +4,10 @@ import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.sheet.UserSheetJson;
import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.core.service.Utils;
import org.sadtech.bot.vcs.core.service.parser.PersonParser;
import org.sadtech.bot.vcs.core.utils.Utils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PersonService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.parser.PersonParser;
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;

View File

@ -1,125 +1,58 @@
package org.sadtech.bot.vcs.bitbucket.app.service.parser;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.sheet.PullRequestSheetJson;
import org.sadtech.bot.vcs.bitbucket.core.AbstractPullRequestBitbucketParser;
import org.sadtech.bot.vcs.core.config.properties.BitbucketProperty;
import org.sadtech.bot.vcs.core.domain.IdAndStatusPr;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.filter.PullRequestFilter;
import org.sadtech.bot.vcs.core.service.PersonService;
import org.sadtech.bot.vcs.core.service.PullRequestsService;
import org.sadtech.bot.vcs.core.service.Utils;
import org.sadtech.bot.vcs.core.service.parser.PullRequestParser;
import org.sadtech.bot.vcs.core.utils.Pair;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PersonService;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PullRequestsService;
import org.sadtech.bot.vsc.context.service.PullRequestParser;
import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@Service
@RequiredArgsConstructor
public class PullRequestBitbucketParser implements PullRequestParser {
public class PullRequestBitbucketParser extends AbstractPullRequestBitbucketParser implements PullRequestParser {
private static final Set<PullRequestStatus> OLD_STATUSES = Stream.of(PullRequestStatus.MERGED, PullRequestStatus.OPEN, PullRequestStatus.DECLINED).collect(Collectors.toSet());
private final PullRequestsService pullRequestsService;
private final PersonService personService;
private final ConversionService conversionService;
private final BitbucketProperty bitbucketProperty;
protected PullRequestBitbucketParser(
PullRequestsService pullRequestsService,
PersonService personService,
ConversionService conversionService,
BitbucketProperty bitbucketProperty
) {
super(pullRequestsService, conversionService);
this.personService = personService;
this.bitbucketProperty = bitbucketProperty;
}
@Override
public void parsingOldPullRequest() {
final Set<Long> existsId = pullRequestsService.getAllId(OLD_STATUSES).stream()
.map(IdAndStatusPr::getId)
.collect(Collectors.toSet());
final Set<Long> openId = parsingPullRequest(bitbucketProperty.getUrlPullRequestOpen());
final Set<Long> closeId = parsingPullRequest(bitbucketProperty.getUrlPullRequestClose());
final Set<Long> newNotExistsId = existsId.stream()
.filter(id -> !openId.contains(id) && !closeId.contains(id))
.collect(Collectors.toSet());
log.info("Открыты: " + Arrays.toString(openId.toArray()));
log.info("Закрыты: " + Arrays.toString(closeId.toArray()));
log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray()));
if (!newNotExistsId.isEmpty()) {
pullRequestsService.deleteAllById(newNotExistsId);
}
processingOldPullRequests(bitbucketProperty.getUrlPullRequestOpen(), bitbucketProperty.getUrlPullRequestClose());
}
@Override
public void parsingNewPullRequest() {
final List<Person> users = personService.getAllRegister();
for (Person user : users) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(bitbucketProperty.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().hasContent()) {
final PullRequestSheetJson pullRequestBitbucketSheet = sheetJson.get();
final List<PullRequest> newPullRequest = pullRequestBitbucketSheet.getValues().stream()
.collect(Collectors.toMap(pullRequestJson -> new Pair<>(pullRequestJson.getId(), pullRequestJson.getFromRef().getRepository().getId()), pullRequestJson -> pullRequestJson))
.values()
.stream()
.filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson)))
.map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class))
.collect(Collectors.toList());
pullRequestsService.createAll(newPullRequest);
if (pullRequestBitbucketSheet.getNextPageStart() != null) {
sheetJson = Utils.urlToJson(bitbucketProperty.getUrlPullRequestOpen() + pullRequestBitbucketSheet.getNextPageStart(), user.getToken(), PullRequestSheetJson.class);
} else {
break;
}
}
createNewPullRequest(bitbucketProperty.getUrlPullRequestOpen(), user.getToken());
}
}
private Set<Long> parsingPullRequest(@NonNull String url) {
final List<Person> users = personService.getAllRegister();
@Override
protected Set<Long> getExistsPullRequestIds(String bitbucketUrl) {
final List<Person> persons = personService.getAllRegister();
final Set<Long> ids = new HashSet<>();
for (Person user : users) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(url, user.getToken(), PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().hasContent()) {
final PullRequestSheetJson jsonSheet = sheetJson.get();
final List<PullRequest> existsPr = getExistsPr(jsonSheet.getValues());
ids.addAll(
pullRequestsService.updateAll(existsPr).stream()
.map(PullRequest::getId)
.collect(Collectors.toSet())
);
if (jsonSheet.getNextPageStart() != null) {
sheetJson = Utils.urlToJson(url + jsonSheet.getNextPageStart(), bitbucketProperty.getToken(), PullRequestSheetJson.class);
} else {
break;
}
}
for (Person person : persons) {
ids.addAll(updateOldPullRequests(bitbucketUrl, person.getToken()));
}
return ids;
}
private List<PullRequest> getExistsPr(@NonNull List<PullRequestJson> pullRequestJsons) {
return pullRequestJsons.stream()
.filter(json -> pullRequestsService.exists(bitbucketIdAndPullRequestId(json)))
.map(json -> conversionService.convert(json, PullRequest.class))
.collect(Collectors.toList());
}
private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) {
return PullRequestFilter.builder()
.bitbucketId(json.getId())
.bitbucketRepositoryId(json.getFromRef().getRepository().getId())
.build();
}
}

View File

@ -28,6 +28,8 @@ bitbucketbot:
init:
start-comment-id: 8301
use: false
rating:
enable: true
bitbucket:
token: ${BITBUCKET_ADMIN_TOKEN}
url-pull-request-open: http://192.168.236.164:7990/rest/api/1.0/dashboard/pull-requests?limit=150&state=OPEN

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bitbucketbot</artifactId>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<version>3.0.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bitbucketbot-context</artifactId>
<version>3.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.basic</groupId>
<artifactId>project-context</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.bot.vcs</groupId>
<artifactId>vcs-bot-context</artifactId>
<version>0.0.1-DEVELOP</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain;
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
import lombok.AccessLevel;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain;
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
/**
* // TODO: 21.09.2020 Добавить описание.

View File

@ -1,8 +1,9 @@
package org.sadtech.bot.vcs.core.domain;
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
@Setter
@Getter

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain;
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain;
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

View File

@ -0,0 +1,8 @@
package org.sadtech.bot.vsc.bitbucketbot.context.domain;
public enum TaskStatus {
OPEN,
RESOLVED
}

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import javax.persistence.CascadeType;
import javax.persistence.Column;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.vcs.core.domain.PointType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.PointType;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import javax.persistence.CascadeType;
import javax.persistence.Column;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.entity;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.entity;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import javax.persistence.CollectionTable;
import javax.persistence.Column;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.domain.filter;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.filter;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;

View File

@ -1,12 +1,12 @@
package org.sadtech.bot.vcs.core.domain.notify;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.utils.MessageUtils;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vcs.core.utils.UpdateDataComparator;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.MessageUtils;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.UpdateDataComparator;
import java.util.List;
import java.util.Set;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.notify;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import java.util.Set;
import java.util.stream.Collectors;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import java.util.Set;

View File

@ -1,11 +1,11 @@
package org.sadtech.bot.vcs.core.domain.notify.comment;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.comment;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.Answer;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.notify.Notify;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.Answer;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.List;

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.domain.notify.comment;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.comment;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.notify.Notify;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.notify.Notify;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
import java.util.Set;

View File

@ -1,18 +1,18 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.util.ReviewerChange;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.util.ReviewerChange;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.sadtech.bot.vcs.core.domain.util.ReviewerChange.Type.DELETED;
import static org.sadtech.bot.vcs.core.domain.util.ReviewerChange.Type.NEW;
import static org.sadtech.bot.vcs.core.domain.util.ReviewerChange.Type.OLD;
import static org.sadtech.bot.vsc.bitbucketbot.context.domain.util.ReviewerChange.Type.DELETED;
import static org.sadtech.bot.vsc.bitbucketbot.context.domain.util.ReviewerChange.Type.NEW;
import static org.sadtech.bot.vsc.bitbucketbot.context.domain.util.ReviewerChange.Type.OLD;
@Getter
public class ReviewersPrNotify extends PrNotify {

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.entity.Reviewer;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Reviewer;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.pullrequest;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.pullrequest;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.domain.notify.task;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.task;
import lombok.Builder;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.notify.task;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.task;
import lombok.Builder;
import lombok.Getter;
import org.sadtech.bot.vcs.core.utils.Smile;
import org.sadtech.bot.vsc.bitbucketbot.context.utils.Smile;
import java.text.MessageFormat;
import java.util.Set;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.domain.notify.task;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.task;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.sadtech.bot.vcs.core.domain.EntityType;
import org.sadtech.bot.vcs.core.domain.notify.Notify;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.EntityType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.domain.util;
package org.sadtech.bot.vsc.bitbucketbot.context.domain.util;
import lombok.Getter;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
/**
* TODO: Добавить описание класса.

View File

@ -0,0 +1,13 @@
package org.sadtech.bot.vsc.bitbucketbot.context.exception;
abstract class BitbucketBotException extends RuntimeException {
public BitbucketBotException(String message) {
super(message);
}
public BitbucketBotException(String message, Throwable throwable) {
super(message, throwable);
}
}

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.exception;
package org.sadtech.bot.vsc.bitbucketbot.context.exception;
public class NotFoundException extends BitbucketBotException {

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.exception;
package org.sadtech.bot.vsc.bitbucketbot.context.exception;
public class RegException extends BitbucketBotException {

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.exception;
package org.sadtech.bot.vsc.bitbucketbot.context.exception;
public class UpdateException extends BitbucketBotException {

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.Chat;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Chat;
import java.util.Set;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.NotifySetting;
import java.util.Set;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import java.util.List;
import java.util.Optional;

View File

@ -1,13 +1,13 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.basic.context.repository.simple.FilterOperation;
import org.sadtech.bot.vcs.core.domain.IdAndStatusPr;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.IdAndStatusPr;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import java.util.List;
import java.util.Optional;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.RatingHistory;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingHistory;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.RatingList;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingList;
import java.util.List;
import java.util.Optional;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.repository;
package org.sadtech.bot.vsc.bitbucketbot.context.repository;
import lombok.NonNull;
import org.sadtech.basic.context.repository.SimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.basic.context.service.SimpleManagerService;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -0,0 +1,11 @@
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
@FunctionalInterface
public interface MessageSendService {
void send(@NonNull Notify notify);
}

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
import org.sadtech.bot.vcs.core.domain.notify.Notify;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.NotifySetting;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.notify.Notify;
import java.util.Optional;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import java.util.Collection;
import java.util.List;

View File

@ -1,14 +1,14 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.basic.context.service.SimpleManagerService;
import org.sadtech.basic.context.service.simple.FilterService;
import org.sadtech.bot.vcs.core.domain.IdAndStatusPr;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini;
import org.sadtech.bot.vcs.core.domain.filter.PullRequestFilter;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.IdAndStatusPr;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.filter.PullRequestFilter;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import java.util.List;
import java.util.Optional;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.PointType;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.PointType;
/**
* // TODO: 01.10.2020 Добавить описание.

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.service;
package org.sadtech.bot.vsc.bitbucketbot.context.service;
import lombok.NonNull;
import org.sadtech.basic.context.service.SimpleManagerService;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import java.time.LocalDateTime;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.service.parser;
package org.sadtech.bot.vsc.bitbucketbot.context.service.parser;
/**
* // TODO: 06.09.2020 Добавить описание.

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.utils;
package org.sadtech.bot.vsc.bitbucketbot.context.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import java.util.List;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package org.sadtech.bot.vcs.core.utils;
package org.sadtech.bot.vsc.bitbucketbot.context.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.core.utils;
package org.sadtech.bot.vsc.bitbucketbot.context.utils;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import java.util.Comparator;

50
bitbucketbot-core/pom.xml Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bitbucketbot</artifactId>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<version>3.0.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bitbucketbot-core</artifactId>
<version>3.1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucketbot-context</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bot-core</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucket-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.bot.vcs</groupId>
<artifactId>vcs-bot-context</artifactId>
<version>0.0.1-DEVELOP</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,123 @@
package org.sadtech.bot.vcs.bitbucket.core;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.sheet.PullRequestSheetJson;
import org.sadtech.bot.vcs.core.utils.Pair;
import org.sadtech.bot.vcs.core.utils.Utils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.IdAndStatusPr;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.filter.PullRequestFilter;
import org.sadtech.bot.vsc.bitbucketbot.context.service.PullRequestsService;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.service.PullRequestParser;
import org.springframework.core.convert.ConversionService;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Абстрактный парсер ПРов, для использования в мульти и локал версиях приложения.
*
* @author upagge 25.10.2020
*/
@Slf4j
public abstract class AbstractPullRequestBitbucketParser implements PullRequestParser {
private static final Set<PullRequestStatus> OLD_STATUSES = Stream.of(PullRequestStatus.MERGED, PullRequestStatus.OPEN, PullRequestStatus.DECLINED).collect(Collectors.toSet());
protected final PullRequestsService pullRequestsService;
protected final ConversionService conversionService;
protected AbstractPullRequestBitbucketParser(
PullRequestsService pullRequestsService,
ConversionService conversionService
) {
this.pullRequestsService = pullRequestsService;
this.conversionService = conversionService;
}
public void processingOldPullRequests(@NonNull String urlPullRequestOpen, @NonNull String urlPullRequestClose) {
final Set<Long> existsId = pullRequestsService.getAllId(OLD_STATUSES).stream()
.map(IdAndStatusPr::getId)
.collect(Collectors.toSet());
final Set<Long> openId = getExistsPullRequestIds(urlPullRequestOpen);
final Set<Long> closeId = getExistsPullRequestIds(urlPullRequestClose);
final Set<Long> newNotExistsId = existsId.stream()
.filter(id -> !openId.contains(id) && !closeId.contains(id))
.collect(Collectors.toSet());
log.info("Открыты: " + Arrays.toString(openId.toArray()));
log.info("Закрыты: " + Arrays.toString(closeId.toArray()));
log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray()));
if (!newNotExistsId.isEmpty()) {
pullRequestsService.deleteAllById(newNotExistsId);
}
}
protected abstract Set<Long> getExistsPullRequestIds(@NonNull String bitbucketUrl);
protected void createNewPullRequest(@NonNull String urlPullRequestOpen, @NonNull String bitbucketToken) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(urlPullRequestOpen, bitbucketToken, PullRequestSheetJson.class);
while (sheetJson.isPresent() && sheetJson.get().hasContent()) {
final PullRequestSheetJson pullRequestBitbucketSheet = sheetJson.get();
final List<PullRequest> newPullRequest = pullRequestBitbucketSheet.getValues().stream()
.collect(Collectors.toMap(pullRequestJson -> new Pair<>(pullRequestJson.getId(), pullRequestJson.getFromRef().getRepository().getId()), pullRequestJson -> pullRequestJson))
.values()
.stream()
.filter(pullRequestJson -> !pullRequestsService.exists(bitbucketIdAndPullRequestId(pullRequestJson)))
.map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class))
.collect(Collectors.toList());
pullRequestsService.createAll(newPullRequest);
if (pullRequestBitbucketSheet.getNextPageStart() != null) {
sheetJson = Utils.urlToJson(urlPullRequestOpen + pullRequestBitbucketSheet.getNextPageStart(), bitbucketToken, PullRequestSheetJson.class);
} else {
break;
}
}
}
protected Set<Long> updateOldPullRequests(@NonNull String url, @NonNull String token) {
Optional<PullRequestSheetJson> sheetJson = Utils.urlToJson(url, token, PullRequestSheetJson.class);
Set<Long> ids = new HashSet<>();
while (sheetJson.isPresent() && sheetJson.get().hasContent()) {
final PullRequestSheetJson jsonSheet = sheetJson.get();
final List<PullRequest> existsPr = getExistsPr(jsonSheet.getValues());
ids.addAll(
pullRequestsService.updateAll(existsPr).stream()
.map(PullRequest::getId)
.collect(Collectors.toSet())
);
if (jsonSheet.getNextPageStart() != null) {
sheetJson = Utils.urlToJson(url + jsonSheet.getNextPageStart(), token, PullRequestSheetJson.class);
} else {
break;
}
}
return ids;
}
private List<PullRequest> getExistsPr(@NonNull List<PullRequestJson> pullRequestJsons) {
return pullRequestJsons.stream()
.filter(json -> pullRequestsService.exists(bitbucketIdAndPullRequestId(json)))
.map(json -> conversionService.convert(json, PullRequest.class))
.collect(Collectors.toList());
}
private PullRequestFilter bitbucketIdAndPullRequestId(PullRequestJson json) {
return PullRequestFilter.builder()
.bitbucketId(json.getId())
.bitbucketRepositoryId(json.getFromRef().getRepository().getId())
.build();
}
}

View File

@ -1,10 +1,9 @@
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

View File

@ -1,12 +1,12 @@
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException;
import org.sadtech.basic.context.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

View File

@ -1,18 +1,18 @@
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import lombok.RequiredArgsConstructor;
import org.sadtech.bot.vcs.bitbucket.app.exception.ConvertException;
import org.sadtech.basic.context.exception.ConvertException;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Outcome;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Properties;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.PullRequestState;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserDecisionJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserPullRequestStatus;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.Reviewer;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Reviewer;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.bitbucket.app.service.converter;
package org.sadtech.bot.vcs.bitbucket.core.service.converter;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.UserJson;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

32
bitbucketbot-data/pom.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bitbucketbot</artifactId>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<version>3.0.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bitbucketbot-data</artifactId>
<version>3.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucketbot-context</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.basic</groupId>
<artifactId>project-database</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.Chat;
import org.sadtech.bot.vcs.core.repository.ChatRepository;
import org.sadtech.bot.vcs.core.repository.jpa.ChatJpaRepository;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.ChatJpaRepository;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Chat;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.ChatRepository;
import org.springframework.stereotype.Repository;
import java.util.Set;

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.repository.CommentRepository;
import org.sadtech.bot.vcs.core.repository.jpa.CommentRepositoryJpa;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.CommentRepositoryJpa;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.CommentRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
import org.sadtech.bot.vcs.core.repository.NotifySettingRepository;
import org.sadtech.bot.vcs.core.repository.jpa.NotifySettingJpaRepository;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.NotifySettingJpaRepository;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.NotifySetting;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.NotifySettingRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;

View File

@ -1,11 +1,11 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vcs.core.repository.PersonRepository;
import org.sadtech.bot.vcs.core.repository.jpa.PersonJpaRepository;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.PersonJpaRepository;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.PersonRepository;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.stereotype.Repository;

View File

@ -1,15 +1,15 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.FilterManagerRepository;
import org.sadtech.bot.vcs.core.domain.IdAndStatusPr;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini;
import org.sadtech.bot.vcs.core.repository.PullRequestsRepository;
import org.sadtech.bot.vcs.core.repository.jpa.PullRequestMiniRepositoryJpa;
import org.sadtech.bot.vcs.core.repository.jpa.PullRequestsRepositoryJpa;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.PullRequestMiniRepositoryJpa;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.PullRequestsRepositoryJpa;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.IdAndStatusPr;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.PullRequestsRepository;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.springframework.stereotype.Repository;
import java.util.List;

View File

@ -1,10 +1,10 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.RatingHistory;
import org.sadtech.bot.vcs.core.repository.RatingHistoryRepository;
import org.sadtech.bot.vcs.core.repository.jpa.RatingHistoryJpaRepository;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.RatingHistoryJpaRepository;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingHistory;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.RatingHistoryRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.entity.RatingList;
import org.sadtech.bot.vcs.core.repository.RatingListRepository;
import org.sadtech.bot.vcs.core.repository.jpa.RatingListJpaRepository;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.RatingListJpaRepository;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingList;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.RatingListRepository;
import org.springframework.stereotype.Repository;
import java.util.List;

View File

@ -1,11 +1,11 @@
package org.sadtech.bot.vcs.core.repository.impl;
package org.sadtech.bot.vcs.bitbucketbot.data.impl;
import lombok.NonNull;
import org.sadtech.basic.database.repository.manager.AbstractSimpleManagerRepository;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.repository.TaskRepository;
import org.sadtech.bot.vcs.core.repository.jpa.TaskRepositoryJpa;
import org.sadtech.bot.vcs.bitbucketbot.data.jpa.TaskRepositoryJpa;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.repository.TaskRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.Chat;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Chat;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,7 +1,7 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.NotifySetting;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.NotifySetting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.Person;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

View File

@ -1,6 +1,6 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.PullRequestMini;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequestMini;
import org.springframework.data.jpa.repository.JpaRepository;
/**
@ -9,4 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @author upagge 12.09.2020
*/
public interface PullRequestMiniRepositoryJpa extends JpaRepository<PullRequestMini, Long> {
}

View File

@ -1,9 +1,9 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.IdAndStatusPr;
import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.IdAndStatusPr;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.PullRequest;
import org.sadtech.bot.vsc.context.domain.PullRequestStatus;
import org.sadtech.bot.vsc.context.domain.ReviewerStatus;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import org.springframework.data.repository.query.Param;
@ -42,7 +42,4 @@ public interface PullRequestsRepositoryJpa extends JpaRepositoryImplementation<P
@Query("SELECT p.authorLogin from PullRequest p WHERE p.id = :id")
Optional<String> findAuthorById(@Param("id") Long id);
// @Query("SELECT p FROM PullRequest p WHERE p.authorLogin = :login AND p.createDate BETWEEN :dateFrom AND :dateTo")
// List<PullRequest> findAllByAuthorAndDateBetween(@Param("login") String login, @Param("dateFrom") LocalDateTime dateFrom, @Param("dateTo") LocalDateTime dateTo);
}

View File

@ -1,6 +1,7 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.RatingHistory;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDateTime;

View File

@ -1,6 +1,7 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import org.sadtech.bot.vcs.core.domain.entity.RatingList;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.RatingList;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.sadtech.bot.vcs.core.repository.jpa;
package org.sadtech.bot.vcs.bitbucketbot.data.jpa;
import lombok.NonNull;
import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.TaskStatus;
import org.sadtech.bot.vsc.bitbucketbot.context.domain.entity.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDateTime;

View File

@ -18,6 +18,12 @@
<artifactId>criteria-filter</artifactId>
</dependency>
<dependency>
<groupId>org.sadtech.bot.bitbucketbot</groupId>
<artifactId>bitbucketbot-context</artifactId>
<version>3.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sadtech.basic</groupId>
<artifactId>project-database</artifactId>

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.vcs.core.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* // TODO: 25.10.2020 Добавить описание.
*
* @author upagge 25.10.2020
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "bitbucketbot.rating")
public class RatingProperty {
boolean enabled = false;
}

View File

@ -1,12 +0,0 @@
package org.sadtech.bot.vcs.core.domain;
/**
* @author upagge [31.01.2020]
*/
public enum PullRequestStatus {
OPEN,
MERGED,
DECLINED
}

View File

@ -1,23 +0,0 @@
package org.sadtech.bot.vcs.core.domain;
import lombok.Getter;
/**
* TODO: Добавить комментарий енума.
*
* @author upagge [01.02.2020]
*/
@Getter
public enum ReviewerStatus {
NEEDS_WORK("NEEDS WORK"),
APPROVED("APPROVED"),
UNAPPROVED("UNAPPROVED");
private final String value;
ReviewerStatus(String value) {
this.value = value;
}
}

View File

@ -1,8 +0,0 @@
package org.sadtech.bot.vcs.core.domain;
public enum TaskStatus {
OPEN,
RESOLVED
}

Some files were not shown because too many files have changed in this diff Show More