Java Code Examples for jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy#MERGE

The following examples show how to use jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy#MERGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 2
Source File: NamedBranchBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new NamedBranchBuildStrategyImpl(Collections.<NamedBranchBuildStrategyImpl.NameFilter>singletonList(
                        new NamedBranchBuildStrategyImpl.RegexNameFilter("^.*$", false))
                ).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 3
Source File: TagBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new TagBuildStrategyImpl(null, null).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 4
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__origin_change__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "new-dummy"),
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy")
                ),
                is(true)
        );
    }
}
 
Example 5
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_target_changes__when__first_build__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(true, false).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 6
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__untrusted_revision__then__isAutomaticBuild_returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master", MockChangeRequestFlags.UNTRUSTED);

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 7
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__trusted_revision__then__isAutomaticBuild_returns_true() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master");

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(true)
        );
    }
}
 
Example 8
Source File: BranchBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 6 votes vote down vote up
@Test
public void given__cr_head__when__isAutomaticBuild__then__returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, 1, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);
        assertThat(
                new BranchBuildStrategyImpl().isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 9
Source File: ChangeRequestBuildStrategyImplTest.java    From basic-branch-build-strategies-plugin with MIT License 5 votes vote down vote up
@Test
public void given__cr_head_ignoring_untrusted_changes_when__trusted_unavailable__then__isAutomaticBuild_returns_false() throws Exception {
    try (MockSCMController c = MockSCMController.create()) {
        c.createRepository("dummy", MockRepositoryFlags.TRUST_AWARE);
        Integer crNum = c.openChangeRequest("dummy", "master");

        MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(SCMHeadOrigin.DEFAULT, crNum, "master",
                ChangeRequestCheckoutStrategy.MERGE, true);

        c.addFault(new MockFailure() {
            @Override
            public void check(String repository, String branchOrCR, String revision, boolean actions)
                    throws IOException {
                throw new IOException("Fail");
            }
        });
        assertThat(
                new ChangeRequestBuildStrategyImpl(false, true).isAutomaticBuild(
                        new MockSCMSource(c, "dummy"),
                        head,
                        new MockChangeRequestSCMRevision(head,
                                new MockSCMRevision(new MockSCMHead("master"), "dummy"), "dummy"),
                        null,
                        null,
                        null
                ),
                is(false)
        );
    }
}
 
Example 10
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
public PullRequestSCMHead(@NonNull String name, String sourceOwner, String sourceRepo, String sourceBranch, int number,
                   BranchSCMHead target, SCMHeadOrigin origin, ChangeRequestCheckoutStrategy strategy) {
    super(name);
    this.merge = ChangeRequestCheckoutStrategy.MERGE == strategy;
    this.number = number;
    this.target = target;
    this.sourceOwner = sourceOwner;
    this.sourceRepo = sourceRepo;
    this.sourceBranch = sourceBranch;
    this.origin = origin;
}
 
Example 11
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_norev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(nullValue()));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is(nullValue()));
}
 
Example 12
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example 13
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example 14
Source File: PullRequestSCMHead.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
FixMetadata(String name, Boolean merge, int number, BranchSCMHead branchSCMHead) {
    super(name, null, null, null, number, branchSCMHead, null, merge ? ChangeRequestCheckoutStrategy.MERGE : ChangeRequestCheckoutStrategy.HEAD);
}
 
Example 15
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_norev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(nullValue()));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is(nullValue()));
}
 
Example 16
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example 17
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_norev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(nullValue()));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.test/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.test/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-pass"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.test/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is(nullValue()));
}
 
Example 18
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser, notNullValue());
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "test-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is("deadbeefcafebabedeadbeefcafebabedeadbeef"));
}
 
Example 19
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullMerge_norev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(false, null);
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    source.setCredentialsId(null);
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null);
    assertThat(instance.credentialsId(), is(nullValue()));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(nullValue()));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.com/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.com/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("https://github.com/tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("https://github.com/tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is(nullValue()));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("https://github.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(MergeWithGitSCMExtension.class)
    ));
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is(nullValue()));
}
 
Example 20
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_norev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.MERGE);
    source.setCredentialsId("user-key");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null);
    assertThat(instance.credentialsId(), is("user-key"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(nullValue()));
    assertThat(instance.refSpecs(), contains("+refs/pull/1/head:refs/remotes/@{remote}/PR-1"));
    assertThat("expecting guess value until withGitHubRemote called",
            instance.remote(), is("https://github.test/tester/test-repo.git"));
    assertThat(instance.browser(), instanceOf(GithubWeb.class));
    assertThat(instance.browser().getRepoUrl(), is("https://github.test/qa/qa-repo"));

    instance.withGitHubRemote();
    assertThat(instance.remote(), is("[email protected]:tester/test-repo.git"));

    GitSCM actual = instance.build();
    assertThat(actual.getBrowser(), instanceOf(GithubWeb.class));
    assertThat(actual.getBrowser().getRepoUrl(), is("https://github.test/qa/qa-repo"));
    assertThat(actual.getGitTool(), nullValue());
    assertThat(actual.getUserRemoteConfigs(), hasSize(1));
    UserRemoteConfig config = actual.getUserRemoteConfigs().get(0);
    assertThat(config.getName(), is("origin"));
    assertThat(config.getRefspec(), is("+refs/pull/1/head:refs/remotes/origin/PR-1 "
            + "+refs/heads/test-branch:refs/remotes/origin/test-branch"));
    assertThat(config.getUrl(), is("[email protected]:tester/test-repo.git"));
    assertThat(config.getCredentialsId(), is("user-key"));
    RemoteConfig origin = actual.getRepositoryByName("origin");
    assertThat(origin, notNullValue());
    assertThat(origin.getURIs(), hasSize(1));
    assertThat(origin.getURIs().get(0).toString(), is("[email protected]:tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(2));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/pull/1/head"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/PR-1"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(origin.getFetchRefSpecs().get(1).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(1).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(1).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(MergeWithGitSCMExtension.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    MergeWithGitSCMExtension merge = getExtension(actual, MergeWithGitSCMExtension.class);
    assertThat(merge, notNullValue());
    assertThat(merge.getBaseName(), is("remotes/origin/test-branch"));
    assertThat(merge.getBaseHash(), is(nullValue()));
}