diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/GitProject.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitProject.java similarity index 95% rename from github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/GitProject.java rename to github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitProject.java index 2772a082e..e72171bfc 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/GitProject.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitProject.java @@ -1,4 +1,4 @@ -package io.github.martinwitt.laughing_train.gitprojects; +package io.github.martinwitt.laughing_train.commons; import java.io.File; import java.io.Serializable; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitRepoHandler.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitRepoHandler.java new file mode 100644 index 000000000..a80d4a5ff --- /dev/null +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/commons/GitRepoHandler.java @@ -0,0 +1,220 @@ +package io.github.martinwitt.laughing_train.commons; + +import com.google.common.flogger.FluentLogger; +import io.github.martinwitt.laughing_train.commons.result.Result; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.util.Random; +import java.util.Timer; +import java.util.TimerTask; +import java.util.random.RandomGenerator; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.ObjectId; +import org.jetbrains.annotations.NotNull; + +/** + * The GitRepoHandler class provides methods for cloning Git repositories and performing operations + * on them. + */ +public class GitRepoHandler { + + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + private static final RandomGenerator RANDOM_GENERATOR = new Random(); + + private static final long CLEANUP_DELAY_MILLIS = Duration.ofMinutes(60).toMillis(); + + /** + * Clones a Git repository from the specified URL. + * + * @param repoUrl The URL of the Git repository to clone. + * @return A Result object containing a GitProject if the cloning is successful, or an error if an + * exception occurs. + */ + public static Result cloneGitProject(String repoUrl) { + try { + String repoName = extractRepoName(repoUrl); + Path projectDirectory = createProjectDir(repoName); + + Result checkedOutRepoResult = checkoutRepo(repoUrl, projectDirectory); + if (checkedOutRepoResult.isError()) { + return cleanupAndReturnError(projectDirectory); + } + Git gitRepository = checkedOutRepoResult.get(); + logger.atInfo().log("Cloned %s to %s", repoUrl, projectDirectory); + + Result commitHash = getLatestCommitHash(gitRepository); + if (commitHash.isError()) { + return cleanupAndReturnError(projectDirectory); + } + return Result.ok(createProject(repoName, repoUrl, projectDirectory, gitRepository)); + } catch (Exception e) { + logger.atSevere().withCause(e).log("Error while handling project request %s", repoUrl); + return Result.error(e); + } + } + + /** + * Extracts the repository name from a given repository URL. + * + * @param repoURL The URL of the repository. + * @return The repository name. + */ + private static String extractRepoName(String repoURL) { + return StringUtils.substringAfterLast(repoURL, "/").replace(".git", ""); + } + + /** + * Creates a GitProject object based on the given parameters. + * + * @param repoName The name of the Git repository. + * @param repoURL The URL of the Git repository. + * @param projectDirectory The directory where the project will be created. + * @param gitRepository The Git object representing the repository. + * @return A GitProject object representing the newly created project. + */ + private static GitProject createProject( + String repoName, String repoURL, Path projectDirectory, Git gitRepository) { + String commitHash = getLatestCommitHash(gitRepository).get(); + return new GitProject(repoName, repoURL, projectDirectory.toFile(), ".", commitHash); + } + + /** + * Creates a temporary project directory for the given repository name. + * + * @param repoName The name of the repository. + * @return The path of the created project directory. + * @throws IOException if an I/O error occurs. + */ + private static Path createProjectDir(String repoName) throws IOException { + Path projectDir = Files.createTempDirectory(generateUniqueRepoName(repoName)); + cleanAfter60min(projectDir); + return projectDir; + } + + /** + * Generates a unique repository name by appending a random number to the given repository name. + * + * @param repoName The original repository name. + * @return The unique repository name. + */ + @NotNull + private static String generateUniqueRepoName(String repoName) { + return "laughing-train-" + repoName + Math.abs(RANDOM_GENERATOR.nextLong()); + } + + /** + * Cleans up the given project directory by deleting its contents and returns a Result object with + * an error message. + * + * @param projectDir The path of the project directory to be cleaned. + * @return A Result object with an error message indicating that the repository could not be + * checked out. + */ + private static Result cleanupAndReturnError(Path projectDir) { + FileUtils.deleteQuietly(projectDir.toFile()); + return Result.error(new IllegalArgumentException("Could not checkout repo")); + } + + /** + * Cleans a directory after 60 minutes by deleting its contents. + * + * @param dir The path of the directory to be cleaned. + */ + private static void cleanAfter60min(Path dir) { + TimerTask task = + new TimerTask() { + @Override + public void run() { + deleteFolder(dir); + } + }; + Timer timer = new Timer(); + timer.schedule(task, CLEANUP_DELAY_MILLIS); + } + + /** + * Deletes a folder if it exists. + * + * @param dir The path of the folder to be deleted. + */ + private static void deleteFolder(Path dir) { + if (Files.exists(dir)) { + FileUtils.deleteQuietly(dir.toFile()); + logger.atInfo().log("Deleted %s", dir); + } + } + + /** + * Retrieves the latest commit hash from a Git repository. + * + * @param git the Git object representing the repository + * @return a Result object containing the commit hash if successful, or an error if an exception + * occurs + */ + private static Result getLatestCommitHash(Git git) { + try { + return Result.ok(getLatestCommitId(git)); + } catch (GitAPIException e) { + return Result.error(e); + } + } + + /** + * Retrieves the latest commit ID from a Git repository. + * + * @param git The Git object representing the repository. + * @return The latest commit ID as a string. + * @throws GitAPIException If an error occurs while accessing the Git repository. + */ + private static String getLatestCommitId(Git git) throws GitAPIException { + return ObjectId.toString(git.log().call().iterator().next().getId()); + } + + /** + * Clones a Git repository from a specified URL to a directory. + * + * @param url The URL of the Git repository. + * @param dir The directory to clone the repository into. + * @return A Result object containing an instance of Git if the cloning is successful, or an error + * if an exception occurs. + */ + private static Result checkoutRepo(String url, Path dir) { + try { + cleanAndCreateFolder(dir); + return cloneRepositoryFromUrl(url, dir); + } catch (Exception e) { + logger.atSevere().withCause(e).log("Error while cloning %s to %s", url, dir); + return Result.error(e); + } + } + + /** + * Clones a Git repository from a specified URL to a directory. + * + * @param url The URL of the Git repository. + * @param dir The directory to clone the repository into. + * @return A Result object containing an instance of Git if the cloning is successful, or an error + * if an exception occurs. + * @throws GitAPIException if an error occurs during the Git cloning process. + */ + @NotNull + private static Result cloneRepositoryFromUrl(String url, Path dir) throws GitAPIException { + return Result.ok(Git.cloneRepository().setURI(url).setDirectory(dir.toFile()).call()); + } + + /** + * Cleans the given directory by deleting all its contents and then creates the directory. + * + * @param dir the directory to clean and create + * @throws IOException if an I/O error occurs + */ + private static void cleanAndCreateFolder(Path dir) throws IOException { + FileUtils.deleteDirectory(dir.toFile()); + Files.createDirectories(dir); + } +} diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/QodanaResult.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/QodanaResult.java index 8b9b026c8..951700554 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/QodanaResult.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/QodanaResult.java @@ -1,7 +1,7 @@ package io.github.martinwitt.laughing_train.data; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.domain.entity.AnalyzerResult; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import java.io.Serializable; import java.util.List; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/request/AnalyzerRequest.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/request/AnalyzerRequest.java index e7a2b7f90..2959eda5e 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/request/AnalyzerRequest.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/request/AnalyzerRequest.java @@ -1,6 +1,6 @@ package io.github.martinwitt.laughing_train.data.request; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; +import io.github.martinwitt.laughing_train.commons.GitProject; import java.io.Serializable; public sealed interface AnalyzerRequest extends Serializable { diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/result/CodeAnalyzerResult.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/result/CodeAnalyzerResult.java index b98810e45..73c7d8174 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/result/CodeAnalyzerResult.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/data/result/CodeAnalyzerResult.java @@ -1,7 +1,7 @@ package io.github.martinwitt.laughing_train.data.result; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.domain.entity.AnalyzerResult; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import java.io.Serializable; import java.util.List; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/github/GitHubIssueSearch.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/github/GitHubIssueSearch.java index eed6fccd8..c94eba027 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/github/GitHubIssueSearch.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/github/GitHubIssueSearch.java @@ -4,15 +4,14 @@ import io.github.martinwitt.laughing_train.commons.GitHubConnector; import io.github.martinwitt.laughing_train.commons.result.Result; import jakarta.enterprise.context.ApplicationScoped; -import org.kohsuke.github.GHIssue; -import org.kohsuke.github.GHIssueSearchBuilder; -import org.kohsuke.github.GHIssueState; -import org.kohsuke.github.GitHub; - import java.io.IOException; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; +import org.kohsuke.github.GHIssue; +import org.kohsuke.github.GHIssueSearchBuilder; +import org.kohsuke.github.GHIssueState; +import org.kohsuke.github.GitHub; @ApplicationScoped public class GitHubIssueSearch { diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/ProjectService.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/ProjectService.java deleted file mode 100644 index 7c158a599..000000000 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/gitprojects/ProjectService.java +++ /dev/null @@ -1,139 +0,0 @@ -package io.github.martinwitt.laughing_train.gitprojects; - -import com.google.common.flogger.FluentLogger; -import io.github.martinwitt.laughing_train.commons.result.Result; -import io.vertx.core.Vertx; -import jakarta.enterprise.context.ApplicationScoped; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Random; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.GitAPIException; -import org.eclipse.jgit.lib.ObjectId; -import org.jetbrains.annotations.NotNull; - -@ApplicationScoped -public class ProjectService { - - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - private static final Random random = new Random(); - - private final Vertx vertx; - - public ProjectService(Vertx vertx) { - this.vertx = vertx; - } - - public Result processProjectRequest(String repoUrl) { - try { - String repoName = extractRepoName(repoUrl); - Path projectDirectory = createProjectDir(repoName); - - Result checkedOutRepoResult = checkoutRepo(repoUrl, projectDirectory); - if (checkedOutRepoResult.isError()) { - return cleanupAndReturnError(projectDirectory); - } - Git gitRepository = checkedOutRepoResult.get(); - logger.atInfo().log("Cloned %s to %s", repoUrl, projectDirectory); - - Result commitHash = getLatestCommitHash(gitRepository); - if (commitHash.isError()) { - return cleanupAndReturnError(projectDirectory); - } - return Result.ok(createProject(repoName, repoUrl, projectDirectory, gitRepository)); - } catch (Exception e) { - logger.atSevere().withCause(e).log("Error while handling project request %s", repoUrl); - return Result.error(e); - } - } - - private String extractRepoName(String repoURL) { - return StringUtils.substringAfterLast(repoURL, "/").replace(".git", ""); - } - - private GitProject createProject( - String repoName, String repoURL, Path projectDirectory, Git gitRepository) { - String commitHash = getLatestCommitHash(gitRepository).get(); - return new GitProject(repoName, repoURL, projectDirectory.toFile(), ".", commitHash); - } - - private Path createProjectDir(String repoName) throws IOException { - Path projectDir = Files.createTempDirectory("laughing-train-" + repoName + random.nextLong()); - cleanAfter60min(projectDir); - return projectDir; - } - - private Result cleanupAndReturnError(Path projectDir) { - FileUtils.deleteQuietly(projectDir.toFile()); - return Result.error(new IllegalArgumentException("Could not checkout repo")); - } - - private void cleanAfter60min(Path dir) { - vertx.setTimer( - Duration.ofMinutes(60).toMillis(), - unused -> { - if (Files.exists(dir)) { - FileUtils.deleteQuietly(dir.toFile()); - logger.atInfo().log("Deleted %s", dir); - } - }); - } - - /** - * Retrieves the latest commit hash from a Git repository. - * - * @param git the Git object representing the repository - * @return a Result object containing the commit hash if successful, or an error if an exception - * occurs - */ - private Result getLatestCommitHash(Git git) { - try { - return Result.ok(getLatestCommitId(git)); - } catch (GitAPIException e) { - return Result.error(e); - } - } - - private static String getLatestCommitId(Git git) throws GitAPIException { - return ObjectId.toString(git.log().call().iterator().next().getId()); - } - - private Result checkoutRepo(String url, Path dir) { - try { - cleanAndCreateFolder(dir); - return cloneRepositoryFromUrl(url, dir); - } catch (Exception e) { - logger.atSevere().withCause(e).log("Error while cloning %s to %s", url, dir); - return Result.error(e); - } - } - - /** - * Clones a Git repository from a specified URL to a directory. - * - * @param url The URL of the Git repository. - * @param dir The directory to clone the repository into. - * @return A Result object containing an instance of Git if the cloning is successful, or an error - * if an exception occurs. - * @throws GitAPIException if an error occurs during the Git cloning process. - */ - @NotNull - private static Result cloneRepositoryFromUrl(String url, Path dir) throws GitAPIException { - return Result.ok(Git.cloneRepository().setURI(url).setDirectory(dir.toFile()).call()); - } - - /** - * Cleans the given directory by deleting all its contents and then creates the directory. - * - * @param dir the directory to clean and create - * @throws IOException if an I/O error occurs - */ - private static void cleanAndCreateFolder(Path dir) throws IOException { - FileUtils.deleteDirectory(dir.toFile()); - Files.createDirectories(dir); - } -} diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java index 54e7df0eb..8b9269c2f 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/AnalyzerResultsPersistence.java @@ -1,13 +1,13 @@ package io.github.martinwitt.laughing_train.mining; import com.google.common.flogger.FluentLogger; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult.Failure; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult.Success; import io.github.martinwitt.laughing_train.domain.entity.AnalyzerStatus; import io.github.martinwitt.laughing_train.domain.entity.GitHubCommit; import io.github.martinwitt.laughing_train.domain.entity.RemoteProject; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import io.github.martinwitt.laughing_train.mining.requests.StoreResults; import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository; import io.vertx.core.AbstractVerticle; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/ProjectSupplier.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/ProjectSupplier.java index b306716ef..fcf58e82b 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/ProjectSupplier.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/ProjectSupplier.java @@ -1,9 +1,9 @@ package io.github.martinwitt.laughing_train.mining; +import io.github.martinwitt.laughing_train.commons.GitProject; +import io.github.martinwitt.laughing_train.commons.GitRepoHandler; import io.github.martinwitt.laughing_train.commons.result.Result; import io.github.martinwitt.laughing_train.domain.entity.RemoteProject; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; -import io.github.martinwitt.laughing_train.gitprojects.ProjectService; import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository; import io.quarkus.logging.Log; import io.vertx.core.AbstractVerticle; @@ -18,20 +18,15 @@ public class ProjectSupplier extends AbstractVerticle { private static final Random random = new Random(); private final SearchProjectService searchProjectService; private final ProjectRepository projectRepository; - private final ProjectService projectService; @Produces Random random() { return new Random(); } - ProjectSupplier( - SearchProjectService searchProjectService, - ProjectRepository projectRepository, - ProjectService projectService) { + ProjectSupplier(SearchProjectService searchProjectService, ProjectRepository projectRepository) { this.searchProjectService = searchProjectService; this.projectRepository = projectRepository; - this.projectService = projectService; } Result supplyProject() { @@ -46,7 +41,7 @@ Result supplyProject() { } private Result checkoutProject(RemoteProject project) throws IOException { - return projectService.processProjectRequest(project.getProjectUrl()); + return GitRepoHandler.cloneGitProject(project.getProjectUrl()); } private RemoteProject getRandomProject() throws IOException { diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/SpoonPeriodicMiner.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/SpoonPeriodicMiner.java index e75f6b37c..69487c962 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/SpoonPeriodicMiner.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/SpoonPeriodicMiner.java @@ -1,10 +1,10 @@ package io.github.martinwitt.laughing_train.mining; import com.google.common.flogger.FluentLogger; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.commons.result.Result; import io.github.martinwitt.laughing_train.data.request.AnalyzerRequest; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import io.github.martinwitt.laughing_train.mining.requests.MineNextProject; import io.github.martinwitt.laughing_train.mining.requests.StoreResults; import io.github.martinwitt.laughing_train.services.SpoonAnalyzerService; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/requests/StoreResults.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/requests/StoreResults.java index 9d5d75d2a..7ae55d712 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/requests/StoreResults.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/requests/StoreResults.java @@ -1,7 +1,7 @@ package io.github.martinwitt.laughing_train.mining.requests; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import java.io.Serializable; public record StoreResults(GitProject gitProject, CodeAnalyzerResult result, String analyzerName) diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/AnalyzerResultPersistenceService.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/AnalyzerResultPersistenceService.java index 9ddab6473..371ab1d0e 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/AnalyzerResultPersistenceService.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/AnalyzerResultPersistenceService.java @@ -1,9 +1,9 @@ package io.github.martinwitt.laughing_train.services; import com.google.common.flogger.FluentLogger; +import io.github.martinwitt.laughing_train.commons.GitProject; import io.github.martinwitt.laughing_train.data.QodanaResult; import io.github.martinwitt.laughing_train.data.result.CodeAnalyzerResult; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; import io.github.martinwitt.laughing_train.persistence.BadSmell; import io.github.martinwitt.laughing_train.persistence.repository.BadSmellRepository; import io.smallrye.mutiny.Multi; diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/RefactorService.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/RefactorService.java index 6929e8bf8..a43822065 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/RefactorService.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/RefactorService.java @@ -4,11 +4,11 @@ import com.google.errorprone.annotations.Var; import io.github.martinwitt.laughing_train.ChangelogPrinter; import io.github.martinwitt.laughing_train.commons.GitHubConnector; +import io.github.martinwitt.laughing_train.commons.GitProject; +import io.github.martinwitt.laughing_train.commons.GitRepoHandler; import io.github.martinwitt.laughing_train.commons.result.Result; import io.github.martinwitt.laughing_train.github.BranchNameSupplier; import io.github.martinwitt.laughing_train.github.GitHubUtils; -import io.github.martinwitt.laughing_train.gitprojects.GitProject; -import io.github.martinwitt.laughing_train.gitprojects.ProjectService; import io.github.martinwitt.laughing_train.persistence.BadSmell; import jakarta.enterprise.context.ApplicationScoped; import java.io.File; @@ -39,15 +39,10 @@ public class RefactorService { private static final String LABEL_NAME = "laughing-train-repair"; final BranchNameSupplier branchNameSupplier; final ChangelogPrinter changelogPrinter; - final ProjectService projectService; final DiffCleaner diffCleaner; - public RefactorService( - ProjectService projectService, - BranchNameSupplier branchNameSupplier, - ChangelogPrinter changelogPrinter) { + public RefactorService(BranchNameSupplier branchNameSupplier, ChangelogPrinter changelogPrinter) { diffCleaner = new DiffCleaner(); - this.projectService = projectService; this.branchNameSupplier = branchNameSupplier; this.changelogPrinter = changelogPrinter; } @@ -73,7 +68,7 @@ public String refactor(Collection badSmells) { private String refactorSpoon(List badSmells) { String projectUrl = badSmells.get(0).getProjectUrl(); - Result project = projectService.processProjectRequest(projectUrl); + Result project = GitRepoHandler.cloneGitProject(projectUrl); if (project.isOk()) { File folder = project.get().folder(); try { @@ -97,7 +92,7 @@ private String refactorSpoon(List badSmells) { private void refactorQodana(List badSmells) { String projectUrl = badSmells.get(0).getProjectUrl(); - Result projectResult = projectService.processProjectRequest(projectUrl); + Result projectResult = GitRepoHandler.cloneGitProject(projectUrl); createPullRequest(projectResult, badSmells); } diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/summary/PeriodicRefactoringSummary.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/summary/PeriodicRefactoringSummary.java index 73e59a056..68508ec6f 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/summary/PeriodicRefactoringSummary.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/summary/PeriodicRefactoringSummary.java @@ -8,15 +8,13 @@ import io.github.martinwitt.laughing_train.persistence.repository.BadSmellRepository; import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository; import io.quarkus.scheduler.Scheduled; -import org.kohsuke.github.GHIssue; -import org.kohsuke.github.GHIssueState; -import org.kohsuke.github.GitHub; - import java.io.IOException; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - +import org.kohsuke.github.GHIssue; +import org.kohsuke.github.GHIssueState; +import org.kohsuke.github.GitHub; public class PeriodicRefactoringSummary {