@Test public void testForkRepositoriesFound() throws Exception { DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class); GHRepository contentRepo1 = mock(GHRepository.class); GHRepository contentRepo2 = mock(GHRepository.class); GHRepository contentRepo3 = mock(GHRepository.class); GHContent content1 = mock(GHContent.class); when(content1.getOwner()).thenReturn(contentRepo1); GHContent content2 = mock(GHContent.class); when(content2.getOwner()).thenReturn(contentRepo2); GHContent content3 = mock(GHContent.class); when(content3.getOwner()).thenReturn(contentRepo3); PagedSearchIterable<GHContent> contentsWithImage = mock(PagedSearchIterable.class); PagedIterator<GHContent> contentsWithImageIterator = mock(PagedIterator.class); when(contentsWithImageIterator.hasNext()).thenReturn(true, true, true, false); when(contentsWithImageIterator.next()).thenReturn(content1, content2, content3, null); when(contentsWithImage.iterator()).thenReturn(contentsWithImageIterator); All all = new All(); all.loadDockerfileGithubUtil(dockerfileGitHubUtil); all.forkRepositoriesFound(ArrayListMultimap.create(), ArrayListMultimap.create(), contentsWithImage, "image"); Mockito.verify(dockerfileGitHubUtil, times(3)).getOrCreateFork(any()); }
protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo, Multimap<String, String> imagesFoundInParentRepo, PagedSearchIterable<GHContent> contentsWithImage, String image) throws IOException { log.info("Forking {} repositories...", contentsWithImage.getTotalCount()); List<String> parentReposForked = new ArrayList<>(); GHRepository parent; String parentRepoName = null; for (GHContent c : contentsWithImage) { parent = c.getOwner(); parentRepoName = parent.getFullName(); if (parent.isFork()) { log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.", parentRepoName); } else { if (!parentReposForked.contains(parentRepoName)) { GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent); GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent); if (pr != null) { log.info("closing existing pr: {}", pr.getUrl()); try { pr.close(); } catch (IOException e) { log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl()); } } if (fork == null) { log.info("Could not fork {}", parentRepoName); } else { pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath()); imagesFoundInParentRepo.put(parentRepoName, image); parentReposForked.add(parentRepoName); } } } } log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo); log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo); }
All implements ExecutableWithNamespace { protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo, Multimap<String, String> imagesFoundInParentRepo, PagedSearchIterable<GHContent> contentsWithImage, String image) throws IOException { log.info("Forking {} repositories...", contentsWithImage.getTotalCount()); List<String> parentReposForked = new ArrayList<>(); GHRepository parent; String parentRepoName = null; for (GHContent c : contentsWithImage) { parent = c.getOwner(); parentRepoName = parent.getFullName(); if (parent.isFork()) { log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.", parentRepoName); } else { if (!parentReposForked.contains(parentRepoName)) { GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent); GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent); if (pr != null) { log.info("closing existing pr: {}", pr.getUrl()); try { pr.close(); } catch (IOException e) { log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl()); } } if (fork == null) { log.info("Could not fork {}", parentRepoName); } else { pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath()); imagesFoundInParentRepo.put(parentRepoName, image); parentReposForked.add(parentRepoName); } } } } log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo); log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo); } }
All implements ExecutableWithNamespace { protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo, Multimap<String, String> imagesFoundInParentRepo, PagedSearchIterable<GHContent> contentsWithImage, String image) throws IOException { log.info("Forking {} repositories...", contentsWithImage.getTotalCount()); List<String> parentReposForked = new ArrayList<>(); GHRepository parent; String parentRepoName = null; for (GHContent c : contentsWithImage) { parent = c.getOwner(); parentRepoName = parent.getFullName(); if (parent.isFork()) { log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.", parentRepoName); } else { if (!parentReposForked.contains(parentRepoName)) { GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent); GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent); if (pr != null) { log.info("closing existing pr: {}", pr.getUrl()); try { pr.close(); } catch (IOException e) { log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl()); } } if (fork == null) { log.info("Could not fork {}", parentRepoName); } else { pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath()); imagesFoundInParentRepo.put(parentRepoName, image); parentReposForked.add(parentRepoName); } } } } log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo); log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo); }  }
All implements ExecutableWithNamespace { protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo, Multimap<String, String> imagesFoundInParentRepo, PagedSearchIterable<GHContent> contentsWithImage, String image) throws IOException { log.info("Forking {} repositories...", contentsWithImage.getTotalCount()); List<String> parentReposForked = new ArrayList<>(); GHRepository parent; String parentRepoName = null; for (GHContent c : contentsWithImage) { parent = c.getOwner(); parentRepoName = parent.getFullName(); if (parent.isFork()) { log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.", parentRepoName); } else { if (!parentReposForked.contains(parentRepoName)) { GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent); GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent); if (pr != null) { log.info("closing existing pr: {}", pr.getUrl()); try { pr.close(); } catch (IOException e) { log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl()); } } if (fork == null) { log.info("Could not fork {}", parentRepoName); } else { pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath()); imagesFoundInParentRepo.put(parentRepoName, image); parentReposForked.add(parentRepoName); } } } } log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo); log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo); }  @Override void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil); }
All implements ExecutableWithNamespace { protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo, Multimap<String, String> imagesFoundInParentRepo, PagedSearchIterable<GHContent> contentsWithImage, String image) throws IOException { log.info("Forking {} repositories...", contentsWithImage.getTotalCount()); List<String> parentReposForked = new ArrayList<>(); GHRepository parent; String parentRepoName = null; for (GHContent c : contentsWithImage) { parent = c.getOwner(); parentRepoName = parent.getFullName(); if (parent.isFork()) { log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.", parentRepoName); } else { if (!parentReposForked.contains(parentRepoName)) { GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent); GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent); if (pr != null) { log.info("closing existing pr: {}", pr.getUrl()); try { pr.close(); } catch (IOException e) { log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl()); } } if (fork == null) { log.info("Could not fork {}", parentRepoName); } else { pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath()); imagesFoundInParentRepo.put(parentRepoName, image); parentReposForked.add(parentRepoName); } } } } log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo); log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo); }  @Override void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil);  }