Java Code Examples for hudson.plugins.git.GitSCM#getRepositoryByName()
The following examples show how to use
hudson.plugins.git.GitSCM#getRepositoryByName() .
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 | 5 votes |
@Test public void given__server_branch_norev_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git"); BranchSCMHead head = new BranchSCMHead("test-branch"); 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/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(), contains(instanceOf(GitSCMSourceDefaults.class))); }
Example 2
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test public void given__server_branch_norev_userpass__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(true, "https://github.test/tester/test-repo.git"); BranchSCMHead head = new BranchSCMHead("test-branch"); 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/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(), contains(instanceOf(GitSCMSourceDefaults.class))); }
Example 3
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_pullHead_norev_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); 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.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(), contains(instanceOf(GitSCMSourceDefaults.class))); }
Example 4
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 5
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 6
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_pullHead_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.HEAD); 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")); 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(), contains(instanceOf(GitSCMSourceDefaults.class))); }
Example 7
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 8
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__server_pullHead_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.HEAD); 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")); 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(), contains(instanceOf(GitSCMSourceDefaults.class))); }
Example 9
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 10
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 11
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new 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.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-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/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.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/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(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example 12
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 13
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userkey_sshtrait_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new 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.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait("user-key"); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/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(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example 14
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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())); }
Example 15
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 16
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userkey_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new 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.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/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(nullValue())); 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(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example 17
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_userpass_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new 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.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/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(nullValue())); 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(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example 18
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__cloud_branch_rev_anon_sshtrait_anon__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); SCMRevisionImpl revision = new 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.com/tester/test-repo.git")); assertThat(instance.browser(), instanceOf(GithubWeb.class)); assertThat(instance.browser().getRepoUrl(), is("https://github.com/tester/test-repo")); instance.withGitHubRemote(); assertThat(instance.remote(), is("https://github.com/tester/test-repo.git")); SSHCheckoutTrait sshTrait = new SSHCheckoutTrait(null); sshTrait.decorateBuilder(instance); GitSCM actual = instance.build(); assertThat(instance.credentialsId(), is(nullValue())); assertThat(instance.remote(), is("[email protected]:tester/test-repo.git")); assertThat(actual.getBrowser(), instanceOf(GithubWeb.class)); assertThat(actual.getBrowser().getRepoUrl(), is("https://github.com/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(nullValue())); 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(BuildChooserSetting.class), instanceOf(GitSCMSourceDefaults.class)) ); BuildChooserSetting chooser = getExtension(actual, BuildChooserSetting.class); assertThat(chooser.getBuildChooser(), instanceOf(SpecificRevisionBuildChooser.class)); SpecificRevisionBuildChooser revChooser = (SpecificRevisionBuildChooser) chooser.getBuildChooser(); Collection<Revision> revisions = revChooser .getCandidateRevisions(false, "test-branch", mock(GitClient.class), new LogTaskListener( getAnonymousLogger(), FINEST), null, null); assertThat(revisions, hasSize(1)); assertThat(revisions.iterator().next().getSha1String(), is("cafebabedeadbeefcafebabedeadbeefcafebabe")); }
Example 19
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@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 20
Source File: GitHubSCMBuilderTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void given__server_pullHead_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.HEAD); 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")); 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(), contains(instanceOf(GitSCMSourceDefaults.class))); }