Исправление бага. При удалении MR оставались дискуссии, которые относились к удаленному MR, из-за этого падал парсинг дискуссий.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-01-16 15:08:07 +03:00
parent ed12bfd473
commit 8bb5acf16b
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
8 changed files with 46 additions and 7 deletions

View File

@ -38,7 +38,7 @@ public class Discussion {
@Column(name = "resolved")
private Boolean resolved;
@ManyToOne(optional = false)
@ManyToOne(optional = false, cascade = CascadeType.REMOVE)
@JoinTable(
name = "discussion_merge_request",
joinColumns = @JoinColumn(name = "discussion_id"),

View File

@ -26,4 +26,8 @@ public interface DiscussionRepository {
Set<String> findAllIds();
void deleteById(String id);
void cleanOld();
}

View File

@ -39,4 +39,8 @@ public interface DiscussionService {
Set<String> getAllIds();
void deleteById(@NonNull String discussionId);
void cleanOld();
}

View File

@ -305,6 +305,18 @@ public class DiscussionServiceImpl implements DiscussionService {
return repository.findAllIds();
}
@Override
public void deleteById(@NonNull String discussionId) {
repository.deleteById(discussionId);
}
@Override
public void cleanOld() {
log.debug("Старт очистки старых дискуссий");
repository.cleanOld();
log.debug("Конец очистки старых дискуссий");
}
/**
* Уведомляет пользователя, если его никнейм упоминается в комментарии.
*/

View File

@ -170,12 +170,16 @@ public class DiscussionParser {
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);
} else {
discussionService.deleteById(discussion.getId());
}
}
if (checkNotEmpty(newDiscussions)) {

View File

@ -52,4 +52,14 @@ public class DiscussionRepositoryImpl implements DiscussionRepository {
return jpaRepository.findAllIds();
}
@Override
public void deleteById(String id) {
jpaRepository.deleteById(id);
}
@Override
public void cleanOld() {
jpaRepository.removeAllByMergeRequestIsNull();
}
}

View File

@ -20,4 +20,6 @@ public interface DiscussionJpaRepository extends JpaRepository<Discussion, Strin
@Query("SELECT d.id FROM Discussion d")
Set<String> findAllIds();
void removeAllByMergeRequestIsNull();
}

View File

@ -1,6 +1,7 @@
package dev.struchkov.bot.gitlab.scheduler;
import dev.struchkov.bot.gitlab.context.service.AppSettingService;
import dev.struchkov.bot.gitlab.context.service.DiscussionService;
import dev.struchkov.bot.gitlab.context.service.MergeRequestsService;
import dev.struchkov.bot.gitlab.context.service.PipelineService;
import dev.struchkov.bot.gitlab.core.service.parser.DiscussionParser;
@ -27,6 +28,7 @@ public class SchedulerService {
private final PipelineService pipelineService;
private final MergeRequestsService mergeRequestsService;
private final DiscussionService discussionService;
@Scheduled(cron = "0 */1 * * * *")
public void newMergeRequest() {
@ -39,6 +41,7 @@ public class SchedulerService {
discussionParser.scanOldDiscussions();
discussionParser.scanNewDiscussion();
mergeRequestsService.cleanOld();
discussionService.cleanOld();
pipelineService.cleanOld();
} else {
log.warn("Процесс обновления данных не был выполнен, так как пользователь не выполнил первичную настройку.");