@Test public void testDoNotForkReposWhichDoNotQualify() throws Exception { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GHRepository contentRepo1 = mock(GHRepository.class); when(contentRepo1.getFullName()).thenReturn("1"); GHContent content1 = mock(GHContent.class); when(content1.getOwner()).thenReturn(contentRepo1); when(contentRepo1.isFork()).thenReturn(true); PagedSearchIterable<GHContent> contentsWithImage = mock(PagedSearchIterable.class); PagedIterator<GHContent> contentsWithImageIterator = mock(PagedIterator.class); when(contentsWithImageIterator.hasNext()).thenReturn(true, false); when(contentsWithImageIterator.next()).thenReturn(content1, null); when(contentsWithImage.iterator()).thenReturn(contentsWithImageIterator); when(dockerfileGitHubUtil.getRepo(any())).thenReturn(contentRepo1); ForkableRepoValidator forkableRepoValidator = mock(ForkableRepoValidator.class); when(forkableRepoValidator.shouldFork(any(), any(), any())).thenReturn(ShouldForkResult.shouldNotForkResult("")); GitHubPullRequestSender pullRequestSender = new GitHubPullRequestSender(dockerfileGitHubUtil, forkableRepoValidator); Multimap<String, GitHubContentToProcess> repoMap = pullRequestSender.forkRepositoriesFoundAndGetPathToDockerfiles(contentsWithImage, null); verify(dockerfileGitHubUtil, never()).getOrCreateFork(any()); assertEquals(repoMap.size(), 0); }
public Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles( PagedSearchIterable<GHContent> contentsWithImage, GitForkBranch gitForkBranch) { log.info("Forking repositories..."); Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = HashMultimap.create(); GHRepository parent; String parentRepoName; int totalContentsFound = 0; int contentsShouldFork = 0; for (GHContent ghContent : contentsWithImage) { totalContentsFound++; parent = ghContent.getOwner(); parentRepoName = parent.getFullName(); try { parent = dockerfileGitHubUtil.getRepo(parentRepoName); ShouldForkResult shouldForkResult = forkableRepoValidator.shouldFork(parent, ghContent, gitForkBranch); if (shouldForkResult.isForkable()) { contentsShouldFork++; ensureForkedAndAddToListForProcessing(pathToDockerfilesInParentRepo, parent, parentRepoName, ghContent); } else { log.warn("Skipping {} because {}", parentRepoName, shouldForkResult.getReason()); } } catch (IOException exception) { log.warn("Could not refresh details of {}", parentRepoName); } } log.info("Out of {} content search results processed, {} were deemed eligible for forking to yield {} repositories to fork.", totalContentsFound, contentsShouldFork, pathToDockerfilesInParentRepo.keys().size()); log.info("Path to Dockerfiles in repos: {}", pathToDockerfilesInParentRepo); return pathToDockerfilesInParentRepo; }
GitHubPullRequestSender { public Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles( PagedSearchIterable<GHContent> contentsWithImage, GitForkBranch gitForkBranch) { log.info("Forking repositories..."); Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = HashMultimap.create(); GHRepository parent; String parentRepoName; int totalContentsFound = 0; int contentsShouldFork = 0; for (GHContent ghContent : contentsWithImage) { totalContentsFound++; parent = ghContent.getOwner(); parentRepoName = parent.getFullName(); try { parent = dockerfileGitHubUtil.getRepo(parentRepoName); ShouldForkResult shouldForkResult = forkableRepoValidator.shouldFork(parent, ghContent, gitForkBranch); if (shouldForkResult.isForkable()) { contentsShouldFork++; ensureForkedAndAddToListForProcessing(pathToDockerfilesInParentRepo, parent, parentRepoName, ghContent); } else { log.warn("Skipping {} because {}", parentRepoName, shouldForkResult.getReason()); } } catch (IOException exception) { log.warn("Could not refresh details of {}", parentRepoName); } } log.info("Out of {} content search results processed, {} were deemed eligible for forking to yield {} repositories to fork.", totalContentsFound, contentsShouldFork, pathToDockerfilesInParentRepo.keys().size()); log.info("Path to Dockerfiles in repos: {}", pathToDockerfilesInParentRepo); return pathToDockerfilesInParentRepo; } }
GitHubPullRequestSender { public Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles( PagedSearchIterable<GHContent> contentsWithImage, GitForkBranch gitForkBranch) { log.info("Forking repositories..."); Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = HashMultimap.create(); GHRepository parent; String parentRepoName; int totalContentsFound = 0; int contentsShouldFork = 0; for (GHContent ghContent : contentsWithImage) { totalContentsFound++; parent = ghContent.getOwner(); parentRepoName = parent.getFullName(); try { parent = dockerfileGitHubUtil.getRepo(parentRepoName); ShouldForkResult shouldForkResult = forkableRepoValidator.shouldFork(parent, ghContent, gitForkBranch); if (shouldForkResult.isForkable()) { contentsShouldFork++; ensureForkedAndAddToListForProcessing(pathToDockerfilesInParentRepo, parent, parentRepoName, ghContent); } else { log.warn("Skipping {} because {}", parentRepoName, shouldForkResult.getReason()); } } catch (IOException exception) { log.warn("Could not refresh details of {}", parentRepoName); } } log.info("Out of {} content search results processed, {} were deemed eligible for forking to yield {} repositories to fork.", totalContentsFound, contentsShouldFork, pathToDockerfilesInParentRepo.keys().size()); log.info("Path to Dockerfiles in repos: {}", pathToDockerfilesInParentRepo); return pathToDockerfilesInParentRepo; } GitHubPullRequestSender(DockerfileGitHubUtil dockerfileGitHubUtil, ForkableRepoValidator forkableRepoValidator); }
GitHubPullRequestSender { public Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles( PagedSearchIterable<GHContent> contentsWithImage, GitForkBranch gitForkBranch) { log.info("Forking repositories..."); Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = HashMultimap.create(); GHRepository parent; String parentRepoName; int totalContentsFound = 0; int contentsShouldFork = 0; for (GHContent ghContent : contentsWithImage) { totalContentsFound++; parent = ghContent.getOwner(); parentRepoName = parent.getFullName(); try { parent = dockerfileGitHubUtil.getRepo(parentRepoName); ShouldForkResult shouldForkResult = forkableRepoValidator.shouldFork(parent, ghContent, gitForkBranch); if (shouldForkResult.isForkable()) { contentsShouldFork++; ensureForkedAndAddToListForProcessing(pathToDockerfilesInParentRepo, parent, parentRepoName, ghContent); } else { log.warn("Skipping {} because {}", parentRepoName, shouldForkResult.getReason()); } } catch (IOException exception) { log.warn("Could not refresh details of {}", parentRepoName); } } log.info("Out of {} content search results processed, {} were deemed eligible for forking to yield {} repositories to fork.", totalContentsFound, contentsShouldFork, pathToDockerfilesInParentRepo.keys().size()); log.info("Path to Dockerfiles in repos: {}", pathToDockerfilesInParentRepo); return pathToDockerfilesInParentRepo; } GitHubPullRequestSender(DockerfileGitHubUtil dockerfileGitHubUtil, ForkableRepoValidator forkableRepoValidator); Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles(
            PagedSearchIterable<GHContent> contentsWithImage,
            GitForkBranch gitForkBranch); }
GitHubPullRequestSender { public Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles( PagedSearchIterable<GHContent> contentsWithImage, GitForkBranch gitForkBranch) { log.info("Forking repositories..."); Multimap<String, GitHubContentToProcess> pathToDockerfilesInParentRepo = HashMultimap.create(); GHRepository parent; String parentRepoName; int totalContentsFound = 0; int contentsShouldFork = 0; for (GHContent ghContent : contentsWithImage) { totalContentsFound++; parent = ghContent.getOwner(); parentRepoName = parent.getFullName(); try { parent = dockerfileGitHubUtil.getRepo(parentRepoName); ShouldForkResult shouldForkResult = forkableRepoValidator.shouldFork(parent, ghContent, gitForkBranch); if (shouldForkResult.isForkable()) { contentsShouldFork++; ensureForkedAndAddToListForProcessing(pathToDockerfilesInParentRepo, parent, parentRepoName, ghContent); } else { log.warn("Skipping {} because {}", parentRepoName, shouldForkResult.getReason()); } } catch (IOException exception) { log.warn("Could not refresh details of {}", parentRepoName); } } log.info("Out of {} content search results processed, {} were deemed eligible for forking to yield {} repositories to fork.", totalContentsFound, contentsShouldFork, pathToDockerfilesInParentRepo.keys().size()); log.info("Path to Dockerfiles in repos: {}", pathToDockerfilesInParentRepo); return pathToDockerfilesInParentRepo; } GitHubPullRequestSender(DockerfileGitHubUtil dockerfileGitHubUtil, ForkableRepoValidator forkableRepoValidator); Multimap<String, GitHubContentToProcess> forkRepositoriesFoundAndGetPathToDockerfiles(
            PagedSearchIterable<GHContent> contentsWithImage,
            GitForkBranch gitForkBranch); static final String REPO_IS_FORK; }