@Test public void testCreateOrUpdateForkBranchToParentDefaultDoesNotHaveBranch() throws IOException, InterruptedException { GitHubUtil gitHubUtil = mock(GitHubUtil.class); DockerfileGitHubUtil dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil); GHRepository parent = mock(GHRepository.class); String defaultBranch = "default"; when(parent.getDefaultBranch()).thenReturn(defaultBranch); GHBranch parentBranch = mock(GHBranch.class); String sha = "abcdef"; when(parentBranch.getSHA1()).thenReturn(sha); when(parent.getBranch(defaultBranch)).thenReturn(parentBranch); GHRepository fork = mock(GHRepository.class); GitForkBranch gitForkBranch = new GitForkBranch("imageName", "imageTag", null); when(gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())).thenReturn(false); dockerfileGitHubUtil.createOrUpdateForkBranchToParentDefault(parent, fork, gitForkBranch); verify(fork, times(1)).createRef(anyString(), matches(sha)); }
public void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch) throws IOException, InterruptedException { GHBranch parentBranch = parent.getBranch(parent.getDefaultBranch()); String sha1 = parentBranch.getSHA1(); gitHubUtil.tryRetrievingBranch(fork, parent.getDefaultBranch()); String branchRefName = String.format("refs/heads/%s", gitForkBranch.getBranchName()); if (gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())) { fork.getRef(branchRefName).updateTo(sha1, true); } else { fork.createRef(branchRefName, sha1); } }
DockerfileGitHubUtil { public void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch) throws IOException, InterruptedException { GHBranch parentBranch = parent.getBranch(parent.getDefaultBranch()); String sha1 = parentBranch.getSHA1(); gitHubUtil.tryRetrievingBranch(fork, parent.getDefaultBranch()); String branchRefName = String.format("refs/heads/%s", gitForkBranch.getBranchName()); if (gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())) { fork.getRef(branchRefName).updateTo(sha1, true); } else { fork.createRef(branchRefName, sha1); } } }
DockerfileGitHubUtil { public void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch) throws IOException, InterruptedException { GHBranch parentBranch = parent.getBranch(parent.getDefaultBranch()); String sha1 = parentBranch.getSHA1(); gitHubUtil.tryRetrievingBranch(fork, parent.getDefaultBranch()); String branchRefName = String.format("refs/heads/%s", gitForkBranch.getBranchName()); if (gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())) { fork.getRef(branchRefName).updateTo(sha1, true); } else { fork.createRef(branchRefName, sha1); } } DockerfileGitHubUtil(GitHubUtil gitHubUtil); }
DockerfileGitHubUtil { public void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch) throws IOException, InterruptedException { GHBranch parentBranch = parent.getBranch(parent.getDefaultBranch()); String sha1 = parentBranch.getSHA1(); gitHubUtil.tryRetrievingBranch(fork, parent.getDefaultBranch()); String branchRefName = String.format("refs/heads/%s", gitForkBranch.getBranchName()); if (gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())) { fork.getRef(branchRefName).updateTo(sha1, true); } else { fork.createRef(branchRefName, sha1); } } 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); }
DockerfileGitHubUtil { public void createOrUpdateForkBranchToParentDefault(GHRepository parent, GHRepository fork, GitForkBranch gitForkBranch) throws IOException, InterruptedException { GHBranch parentBranch = parent.getBranch(parent.getDefaultBranch()); String sha1 = parentBranch.getSHA1(); gitHubUtil.tryRetrievingBranch(fork, parent.getDefaultBranch()); String branchRefName = String.format("refs/heads/%s", gitForkBranch.getBranchName()); if (gitHubUtil.repoHasBranch(fork, gitForkBranch.getBranchName())) { fork.getRef(branchRefName).updateTo(sha1, true); } else { fork.createRef(branchRefName, sha1); } } 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);  }