Java Code Examples for jenkins.plugins.git.AbstractGitSCMSource#SpecificRevisionBuildChooser

The following examples show how to use jenkins.plugins.git.AbstractGitSCMSource#SpecificRevisionBuildChooser . 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: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_branch_rev_anon__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    BranchSCMHead head = new BranchSCMHead("test-branch");
    AbstractGitSCMSource.SCMRevisionImpl revision =
            new AbstractGitSCMSource.SCMRevisionImpl(head, "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/heads/test-branch:refs/remotes/@{remote}/test-branch"));
    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/tester/test-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/tester/test-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/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(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    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"));
}
 
Example 2
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_branch_rev_userpass__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    BranchSCMHead head = new BranchSCMHead("test-branch");
    AbstractGitSCMSource.SCMRevisionImpl revision =
            new AbstractGitSCMSource.SCMRevisionImpl(head, "cafebabedeadbeefcafebabedeadbeefcafebabe");
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    assertThat(instance.head(), is(head));
    assertThat(instance.revision(), is(revision));
    assertThat(instance.refSpecs(), contains("+refs/heads/test-branch:refs/remotes/@{remote}/test-branch"));
    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/tester/test-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/tester/test-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/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(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    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"));
}
 
Example 3
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_branch_rev_userkey__when__build__then__scmBuilt() throws Exception {
    createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git");
    BranchSCMHead head = new BranchSCMHead("test-branch");
    AbstractGitSCMSource.SCMRevisionImpl revision =
            new AbstractGitSCMSource.SCMRevisionImpl(head, "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/heads/test-branch:refs/remotes/@{remote}/test-branch"));
    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/tester/test-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/tester/test-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/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(1));
    assertThat(origin.getFetchRefSpecs().get(0).getSource(), is("refs/heads/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).getDestination(), is("refs/remotes/origin/test-branch"));
    assertThat(origin.getFetchRefSpecs().get(0).isForceUpdate(), is(true));
    assertThat(origin.getFetchRefSpecs().get(0).isWildcard(), is(false));
    assertThat(actual.getExtensions(), containsInAnyOrder(
            instanceOf(GitSCMSourceDefaults.class),
            instanceOf(BuildChooserSetting.class)
    ));
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    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"));
}
 
Example 4
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_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.HEAD);
    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"));
    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(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 5
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_rev_userpass__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.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    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"));
    assertThat(config.getUrl(), is("https://github.com/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.com/tester/test-repo.git"));
    assertThat(origin.getFetchRefSpecs(), hasSize(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 6
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() throws Exception {
    PullRequestSCMHead head = new PullRequestSCMHead("PR-1", "qa", "qa-repo", "qa-branch", 1,
            new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"),
            ChangeRequestCheckoutStrategy.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    createGitHubSCMSourceForTest(false,null);
    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"));
    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(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 7
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_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.HEAD);
    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"));
    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(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 8
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_rev_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.HEAD);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    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"));
    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(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 9
Source File: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullHead_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.HEAD);
    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"));
    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(1));
    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(actual.getExtensions(), containsInAnyOrder(
            instanceOf(BuildChooserSetting.class),
            instanceOf(GitSCMSourceDefaults.class))
    );
    BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class);
    assertThat(chooser.getBuildChooser(), instanceOf(AbstractGitSCMSource.SpecificRevisionBuildChooser.class));
    AbstractGitSCMSource.SpecificRevisionBuildChooser revChooser =
            (AbstractGitSCMSource.SpecificRevisionBuildChooser) chooser.getBuildChooser();
    Collection<Revision> revisions = revChooser
            .getCandidateRevisions(false, "qa-branch", Mockito.mock(GitClient.class), new LogTaskListener(
                    Logger.getAnonymousLogger(), Level.FINEST), null, null);
    assertThat(revisions, hasSize(1));
    assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe"));
}
 
Example 10
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 11
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_userpass__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-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    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("user-pass"));
    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 12
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 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: GitHubSCMBuilderTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void given__server_pullMerge_rev_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);
    PullRequestSCMRevision revision = new PullRequestSCMRevision(
            head,
            "deadbeefcafebabedeadbeefcafebabedeadbeef",
            "cafebabedeadbeefcafebabedeadbeefcafebabe"
    );
    source.setCredentialsId("user-pass");
    GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision);
    assertThat(instance.credentialsId(), is("user-pass"));
    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("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(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 15
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"));
}