Небольшие доработки в области дискуссий
This commit is contained in:
parent
b8c3fc6b25
commit
b350e18a5c
@ -11,8 +11,8 @@ import dev.struchkov.bot.gitlab.core.config.properties.GitlabProperty;
|
||||
import dev.struchkov.bot.gitlab.core.config.properties.PersonProperty;
|
||||
import dev.struchkov.bot.gitlab.sdk.domain.DiscussionJson;
|
||||
import dev.struchkov.haiti.utils.network.HttpParse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -30,7 +31,6 @@ import java.util.stream.Stream;
|
||||
import static dev.struchkov.bot.gitlab.core.utils.StringUtils.H_PRIVATE_TOKEN;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNull;
|
||||
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
||||
|
||||
/**
|
||||
@ -40,16 +40,34 @@ import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class DiscussionParser {
|
||||
|
||||
private final DiscussionService discussionService;
|
||||
|
||||
private final MergeRequestsService mergeRequestsService;
|
||||
private final ConversionService conversionService;
|
||||
private final ForkJoinPool forkJoinPool;
|
||||
|
||||
private final GitlabProperty gitlabProperty;
|
||||
|
||||
private final PersonProperty personProperty;
|
||||
|
||||
public DiscussionParser(
|
||||
DiscussionService discussionService,
|
||||
MergeRequestsService mergeRequestsService,
|
||||
ConversionService conversionService,
|
||||
@Qualifier("parserPool") ForkJoinPool forkJoinPool,
|
||||
GitlabProperty gitlabProperty,
|
||||
PersonProperty personProperty
|
||||
) {
|
||||
this.discussionService = discussionService;
|
||||
this.mergeRequestsService = mergeRequestsService;
|
||||
this.conversionService = conversionService;
|
||||
this.forkJoinPool = forkJoinPool;
|
||||
this.gitlabProperty = gitlabProperty;
|
||||
this.personProperty = personProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Поиск новых обсуждений
|
||||
*/
|
||||
@ -148,23 +166,14 @@ public class DiscussionParser {
|
||||
log.debug("Старт обработки старых дискуссий");
|
||||
final List<Discussion> discussions = discussionService.getAll();
|
||||
|
||||
// Удаляем обсуждения, которые потеряли свои MR
|
||||
//TODO [05.12.2022|uPagge]: Проверить целесообразность этого действия
|
||||
discussions.stream()
|
||||
.filter(discussion -> checkNull(discussion.getMergeRequest()))
|
||||
.map(Discussion::getId)
|
||||
.forEach(discussionService::deleteById);
|
||||
|
||||
final List<Discussion> newDiscussions = new ArrayList<>();
|
||||
for (Discussion discussion : discussions) {
|
||||
if (checkNotNull(discussion.getMergeRequest())) {
|
||||
getOldDiscussionJson(discussion)
|
||||
.map(json -> {
|
||||
final Discussion newDiscussion = conversionService.convert(json, Discussion.class);
|
||||
newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest()));
|
||||
return newDiscussion;
|
||||
}).ifPresent(newDiscussions::add);
|
||||
}
|
||||
getOldDiscussionJson(discussion)
|
||||
.map(json -> {
|
||||
final Discussion newDiscussion = conversionService.convert(json, Discussion.class);
|
||||
newDiscussion.getNotes().forEach(createNoteLink(discussion.getMergeRequest()));
|
||||
return newDiscussion;
|
||||
}).ifPresent(newDiscussions::add);
|
||||
}
|
||||
|
||||
if (checkNotEmpty(newDiscussions)) {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package dev.struchkov.bot.gitlab.core.service.parser.forktask;
|
||||
|
||||
import dev.struchkov.bot.gitlab.sdk.domain.DiscussionJson;
|
||||
import dev.struchkov.haiti.utils.network.HttpParse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
|
||||
import static dev.struchkov.bot.gitlab.core.utils.StringUtils.H_PRIVATE_TOKEN;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
public class GetAllDiscussionForMergeRequestTask extends RecursiveTask<List<DiscussionJson>> {
|
||||
|
||||
private static final int PAGE_COUNT = 100;
|
||||
|
||||
private final String discussionsUrl;
|
||||
private final long projectId;
|
||||
private final long mergeRequestTwoId;
|
||||
private final String personalGitlabToken;
|
||||
private int page = 0;
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
protected List<DiscussionJson> compute() {
|
||||
Thread.sleep(100);
|
||||
final List<DiscussionJson> jsons = getDiscussionJson();
|
||||
if (checkNotEmpty(jsons) && jsons.size() == PAGE_COUNT) {
|
||||
final var newTask = new GetAllDiscussionForMergeRequestTask(discussionsUrl, projectId, mergeRequestTwoId, personalGitlabToken, page + 1);
|
||||
newTask.fork();
|
||||
jsons.addAll(newTask.join());
|
||||
}
|
||||
return jsons;
|
||||
}
|
||||
|
||||
private List<DiscussionJson> getDiscussionJson() {
|
||||
return HttpParse.request(MessageFormat.format(discussionsUrl, projectId, mergeRequestTwoId, page, PAGE_COUNT))
|
||||
.header(ACCEPT)
|
||||
.header(H_PRIVATE_TOKEN, personalGitlabToken)
|
||||
.executeList(DiscussionJson.class);
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static dev.struchkov.haiti.utils.network.HttpParse.ACCEPT;
|
||||
|
||||
@Slf4j
|
||||
@ -31,7 +32,7 @@ public class GetAllMergeRequestForProjectTask extends RecursiveTask<List<MergeRe
|
||||
protected List<MergeRequestJson> compute() {
|
||||
Thread.sleep(100);
|
||||
final List<MergeRequestJson> mergeRequestJsons = getMergeRequestJsons();
|
||||
if (mergeRequestJsons.size() == PAGE_COUNT) {
|
||||
if (checkNotEmpty(mergeRequestJsons) && mergeRequestJsons.size() == PAGE_COUNT) {
|
||||
final GetAllMergeRequestForProjectTask newTask = new GetAllMergeRequestForProjectTask(projectId, pageNumber + 1, urlMrOpen, gitlabToken);
|
||||
newTask.fork();
|
||||
mergeRequestJsons.addAll(newTask.join());
|
||||
|
@ -35,8 +35,8 @@ gitlab-bot:
|
||||
gitlab:
|
||||
base-url: ${GITLAB_URL}
|
||||
replaceUrl: ${GITLAB_REPLACE_URL}
|
||||
users-url: ${GITLAB_URL}/api/v4/users
|
||||
user-url: ${GITLAB_URL}/api/v4/user
|
||||
users-url: "${GITLAB_URL}/api/v4/users"
|
||||
user-url: "${GITLAB_URL}/api/v4/user"
|
||||
projects-url: "${GITLAB_URL}/api/v4/projects?page={0, number, integer}&per_page=100"
|
||||
open-merge-requests-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=opened&page={1, number, integer}&per_page={2, number, integer}"
|
||||
close-merge-requests-url: "${GITLAB_URL}/api/v4/projects/{0,number,#}/merge_requests?state=closed&page={1, number, integer}&per_page=100"
|
||||
|
Loading…
Reference in New Issue
Block a user