GitHubBranchTrigger extends GitHubTrigger<GitHubBranchTrigger> { @Override public void doRun() { doRun(null); } @Restricted(value = NoExternalUse.class)  GitHubBranchTrigger(); @DataBoundConstructor  GitHubBranchTrigger(String spec, GitHubPRTriggerMode triggerMode, List<GitHubBranchEvent> events); @Override String getFinishMsg(); @DataBoundSetter void setPreStatus(boolean preStatus); boolean isPreStatus(); @Nonnull List<GitHubBranchEvent> getEvents(); @CheckForNull void setEvents(List<GitHubBranchEvent> events); @Override void start(Job item, boolean newInstance); @Override void run(); @Override void doRun(); @Override @CheckForNull GitHubBranchPollingLogAction getPollingLogAction(); @Override DescriptorImpl getDescriptor(); @Deprecated void queueRun(Job<?, ?> job, final String branch); void queueRun(final String branch); synchronized void doRun(String branch); static void updateLocalRepository(@CheckForNull String requestedBranch,
                                             Set<GHBranch> remoteBranches, GitHubBranchRepository localRepository); static final String FINISH_MSG; }
@LocalData @Test public void someTest() throws Exception { FreeStyleProject prj = jRule.createFreeStyleProject("project"); prj.addProperty(new GithubProjectProperty("http: final List<GitHubBranchEvent> events = new ArrayList<>(); events.add(new GitHubBranchCreatedEvent()); events.add(new GitHubBranchHashChangedEvent()); final GitHubBranchTrigger trigger = new GitHubBranchTrigger("", CRON, events); prj.addTrigger(trigger); prj.save(); jRule.configRoundtrip(prj); final GitHubBranchTrigger branchTrigger = prj.getTrigger(GitHubBranchTrigger.class); assertThat(branchTrigger.getRemoteRepository(), notNullValue()); GitHubBranchRepository localRepo = prj.getAction(GitHubBranchRepository.class); assertThat(localRepo, notNullValue()); assertThat(localRepo.getBranches().size(), is(2)); assertThat(localRepo.getBranches(), hasKey("for-removal")); assertThat(localRepo.getBranches(), hasKey("should-change")); GitHubBranch shouldChange = localRepo.getBranches().get("should-change"); assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffbb")); branchTrigger.doRun("should-change"); jRule.waitUntilNoActivity(); assertThat(prj.getBuilds(), hasSize(1)); FreeStyleBuild lastBuild = prj.getLastBuild(); GitHubBranchCause cause = lastBuild.getCause(GitHubBranchCause.class); assertThat(cause, notNullValue()); assertThat(cause.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg")); assertThat(cause.getBranchName(), is("should-change")); localRepo = prj.getAction(GitHubBranchRepository.class); assertThat(localRepo, notNullValue()); assertThat(localRepo.getBranches().size(), is(2)); assertThat(localRepo.getBranches(), hasKey("for-removal")); assertThat(localRepo.getBranches(), hasKey("should-change")); shouldChange = localRepo.getBranches().get("should-change"); assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg")); branchTrigger.doRun(); jRule.waitUntilNoActivity(); assertThat(prj.getBuilds(), hasSize(2)); lastBuild = prj.getLastBuild(); assertThat(lastBuild, notNullValue()); cause = lastBuild.getCause(GitHubBranchCause.class); assertThat(cause, notNullValue()); assertThat(cause.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); assertThat(cause.getBranchName(), is("new-branch")); localRepo = prj.getAction(GitHubBranchRepository.class); assertThat(localRepo.getBranches().size(), is(2)); assertThat(localRepo.getBranches(), not(hasKey("for-removal"))); assertThat(localRepo.getBranches(), hasKey("should-change")); shouldChange = localRepo.getBranches().get("should-change"); assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg")); assertThat(localRepo.getBranches(), hasKey("new-branch")); GitHubBranch branch = localRepo.getBranches().get("new-branch"); assertThat(branch.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); }
@LocalData @Test public void actualiseRepo() throws Exception { Thread.sleep(1000); FreeStyleProject project = (FreeStyleProject) jRule.getInstance().getItem("project"); GitHubBranchTrigger branchTrigger = ghBranchTriggerFromJob(project); GitHubRepositoryName repoFullName = branchTrigger.getRepoFullName(); assertThat(repoFullName.getHost(), Matchers.is("github.com")); assertThat(repoFullName.getUserName(), Matchers.is("KostyaSha-auto")); assertThat(repoFullName.getRepositoryName(), Matchers.is("test")); GitHubBranchRepository localRepo = project.getAction(GitHubBranchRepository.class); assertThat(localRepo, notNullValue()); assertThat(localRepo.getFullName(), is("KostyaSha-auto/test")); assertThat(localRepo.getGithubUrl(), notNullValue()); assertThat(localRepo.getGithubUrl().toString(), is("https: assertThat(localRepo.getSshUrl(), is("git@github.com:KostyaSha-auto/test.git")); assertThat(localRepo.getGitUrl(), is("git: assertThat(localRepo.getBranches().size(), is(2)); assertThat(localRepo.getBranches(), hasKey("old-repo")); assertThat(localRepo.getBranches(), hasKey("old-branch")); GitHubBranch oldRepo = localRepo.getBranches().get("old-repo"); assertThat(oldRepo.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193fffb")); assertThat(oldRepo.getHtmlUrl(), is("https: assertThat(oldRepo.getName(), is("old-repo")); GitHubBranch oldBranch = localRepo.getBranches().get("old-branch"); assertThat(oldBranch.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffbe")); assertThat(oldBranch.getHtmlUrl(), is("https: assertThat(oldBranch.getName(), is("old-branch")); project.addProperty(new GithubProjectProperty("http: GitHubPluginRepoProvider repoProvider = new GitHubPluginRepoProvider(); repoProvider.setManageHooks(false); repoProvider.setRepoPermission(GHPermission.PULL); final List<GitHubBranchEvent> events = new ArrayList<>(); events.add(new GitHubBranchCreatedEvent()); events.add(new GitHubBranchHashChangedEvent()); branchTrigger = new GitHubBranchTrigger("", CRON, events); branchTrigger.setRepoProvider(repoProvider); project.addTrigger(branchTrigger); project.save(); jRule.configRoundtrip(project); branchTrigger = project.getTrigger(GitHubBranchTrigger.class); branchTrigger.doRun(); jRule.waitUntilNoActivity(); repoFullName = branchTrigger.getRepoFullName(); assertThat(repoFullName.getHost(), Matchers.is("localhost")); assertThat(repoFullName.getUserName(), Matchers.is("org")); assertThat(repoFullName.getRepositoryName(), Matchers.is("repo")); GitHubBranchPollingLogAction logAction = project.getAction(GitHubBranchPollingLogAction.class); assertThat(logAction, Matchers.notNullValue()); assertThat(logAction.getLog(), containsString("Repository full name changed from 'KostyaSha-auto/test' to 'org/repo'.\n")); assertThat(logAction.getLog(), containsString("Changing GitHub url from 'https: "to 'http: assertThat(logAction.getLog(), containsString("Changing Git url from 'git: "to 'git: assertThat(logAction.getLog(), containsString("Changing SSH url from 'git@github.com:KostyaSha-auto/test.git' " + "to 'git@localhost:org/repo.git'.\n")); assertThat(logAction.getLog(), containsString("Local settings changed, removing branches in repository!")); assertThat(project.getBuilds(), hasSize(2)); localRepo = project.getAction(GitHubBranchRepository.class); assertThat(localRepo.getFullName(), is("org/repo")); assertThat(localRepo.getGithubUrl(), notNullValue()); assertThat(localRepo.getGithubUrl().toString(), is("http: assertThat(localRepo.getGitUrl(), is("git: assertThat(localRepo.getSshUrl(), is("git@localhost:org/repo.git")); assertThat(localRepo.getBranches().size(), is(2)); assertThat(localRepo.getBranches(), not(hasKey("old-branch"))); assertThat(localRepo.getBranches(), not(hasKey("old-repo"))); assertThat(localRepo.getBranches(), hasKey("should-change")); GitHubBranch shouldChange = localRepo.getBranches().get("should-change"); assertThat(shouldChange.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193ffgg")); assertThat(shouldChange.getHtmlUrl(), is("http: assertThat(localRepo.getBranches(), hasKey("new-branch")); GitHubBranch newBranch = localRepo.getBranches().get("new-branch"); assertThat(newBranch.getCommitSha(), is("6dcb09b5b57875f334f61aebed695e2e4193db5e")); assertThat(newBranch.getHtmlUrl(), is("http: }