DockerfileGitHubUtil { public PagedSearchIterable<GHContent> findFilesWithImage(String query, String org) throws IOException { GHContentSearchBuilder search = gitHubUtil.startSearch(); search.filename("Dockerfile"); if (org != null) { search.user(org); } if (query.substring(query.lastIndexOf(' ') + 1).length() <= 1) { throw new IOException("Invalid image name."); } search.q("\"FROM " + query + "\""); log.debug("Searching for {}", query); PagedSearchIterable<GHContent> files = search.list(); int totalCount = files.getTotalCount(); if (totalCount > 1000) { log.warn("Number of search results is above 1000! The GitHub Search API will only return around 1000 results - https: } log.info("Number of files found for {}:{}", query, totalCount); return files; } DockerfileGitHubUtil(GitHubUtil gitHubUtil); GHRepository getOrCreateFork(GHRepository parent); GHMyself getMyself(); GHRepository getRepo(String repoName); PagedSearchIterable<GHContent> findFilesWithImage(String query, String org); List<GHRepository> getGHRepositories(Multimap<String, String> pathToDockerfileInParentRepo,
                                                            GHMyself currentUser); void modifyAllOnGithub(GHRepository repo, String branch,
                                  String img, String tag); GHContent tryRetrievingContent(GHRepository repo, String path, String branch); void modifyOnGithub(GHContent content,
                               String branch, String img, String tag, String customMessage); GitHubJsonStore getGitHubJsonStore(String store); void createPullReq(GHRepository origRepo,
                              String branch, GHRepository forkRepo,
                              PullRequestInfo pullRequestInfo); Optional<GHPullRequest> getPullRequestForImageBranch(GHRepository repository, GitForkBranch gitForkBranch); void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch); boolean thisUserIsOwner(GHRepository repo); Optional<PagedSearchIterable<GHContent>> getGHContents(String org, String img);  }
@Test(dataProvider = "inputEmptyImages", expectedExceptions = IOException.class) public void testFindFiles_EmptyQuery(String query, String org) throws Exception { gitHubUtil = mock(GitHubUtil.class); GHContentSearchBuilder ghContentSearchBuilder = mock(GHContentSearchBuilder.class); PagedSearchIterable<GHContent> list = mock(PagedSearchIterable.class); when(list.getTotalCount()).thenReturn(0); when(ghContentSearchBuilder.list()).thenReturn(list); when(gitHubUtil.startSearch()).thenReturn(ghContentSearchBuilder); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); dockerfileGitHubUtil.findFilesWithImage(query, org); }
@Test public void testFindFiles() throws Exception { gitHubUtil = mock(GitHubUtil.class); GHContentSearchBuilder ghContentSearchBuilder = mock(GHContentSearchBuilder.class); PagedSearchIterable<GHContent> list = mock(PagedSearchIterable.class); when(list.getTotalCount()).thenReturn(100); when(ghContentSearchBuilder.list()).thenReturn(list); when(gitHubUtil.startSearch()).thenReturn(ghContentSearchBuilder); dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); assertEquals(dockerfileGitHubUtil.findFilesWithImage("test", "test"), list); }