public static void validateRepo(String repoName, String image, String testTag, GitHub github, GitHubUtil gitHubUtil) throws Exception {
String login = github.getMyself().getLogin();
for (int attempt = 0; attempt < 5; attempt++) {
GHRepository repo = gitHubUtil.tryRetrievingRepository(Paths.get(login, repoName).toString());
if (repo == null) {
fail("Repository not found: " + Paths.get(login, repoName).toString());
}
String latestCommit = repo.getBranches().get(repo.getDefaultBranch()).getSHA1();
GHContent content = gitHubUtil.tryRetrievingContent(repo, "Dockerfile", latestCommit);
if (content.getSize() > MAX_CONTENT_SIZE) {
fail(String.format("Content is suspiciously large: %s, should be below %s", content.getSize(), MAX_CONTENT_SIZE));
}
String dockerfileContent = IOUtils.toString(content.read());
if (dockerfileContent.contains(testTag)) {
assertThat(dockerfileContent).startsWith("FROM");
assertThat(dockerfileContent).contains(image);
assertThat(dockerfileContent).contains(testTag);
validatePullRequestCreation(repo, true);
return;
}
log.info("Dockerfile (commitref: {}, contents: {}) in {} did not contain tag {}, try #{}",
latestCommit, dockerfileContent, repo.getFullName(), testTag, attempt);
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
}
fail(String.format("Didn't find tag (%s) in Dockerfile in repo (%s)", testTag, repoName));
}