diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java index f98654cc1..82f6fdc15 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java @@ -86,7 +86,15 @@ private void mineRandomRepo() { mineRandomRepo(); return; } + if (checkoutResult instanceof ProjectResult.Success success) { + String commitHash = success.project().commitHash(); + if (isAlreadyMined(success, commitHash)) { + logger.atInfo().log( + "Project %s already analyzed with commit hash %s", success.project(), commitHash); + tryDeleteProject(success); + mineRandomRepo(); + } logger.atInfo().log("Successfully checked out project %s", success.project()); var qodanaResult = analyzeProject(success); if (qodanaResult instanceof QodanaResult.Failure failure) { @@ -111,6 +119,11 @@ private void mineRandomRepo() { } } + private boolean isAlreadyMined(ProjectResult.Success success, String commitHash) { + return projectRepository.findByProjectUrl(success.project().url()).stream() + .anyMatch(it -> !it.getCommitHashes().contains(commitHash)); + } + private ProjectResult checkoutProject(Project project) throws IOException { return projectService.handleProjectRequest(new ProjectRequest.WithUrl(project.getProjectUrl())); }