diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java index b5e6b4920..8bb1b338a 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java @@ -295,23 +295,22 @@ public static StandardCredentials lookupScanCredentials( @CheckForNull String repoOwner) { if (Util.fixEmpty(scanCredentialsId) == null) { return null; - } else { - StandardCredentials c = CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( - StandardUsernameCredentials.class, - context, - context instanceof Queue.Task - ? ((Queue.Task) context).getDefaultAuthentication() - : ACL.SYSTEM, - githubDomainRequirements(apiUri)), - CredentialsMatchers.allOf( - CredentialsMatchers.withId(scanCredentialsId), githubScanCredentialsMatcher())); - if (c instanceof GitHubAppCredentials && repoOwner != null) { - return ((GitHubAppCredentials) c).withOwner(repoOwner); - } else { - return c; - } } + StandardCredentials c = CredentialsMatchers.firstOrNull( + CredentialsProvider.lookupCredentialsInItem( + StandardUsernameCredentials.class, + context, + context instanceof Queue.Task + ? ((Queue.Task) context).getDefaultAuthentication2() + : ACL.SYSTEM2, + githubDomainRequirements(apiUri)), + CredentialsMatchers.allOf( + CredentialsMatchers.withId(scanCredentialsId), githubScanCredentialsMatcher())); + + if (c instanceof GitHubAppCredentials && repoOwner != null) { + c = ((GitHubAppCredentials) c).withOwner(repoOwner); + } + return c; } /** diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java index bf867d7ac..44bd2ee37 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java @@ -124,7 +124,6 @@ public GitHubSCMBuilder( if (repoUrl != null) { withBrowser(new GithubWeb(repoUrl)); } - withCredentials(credentialsId(), null); } /** @@ -189,7 +188,9 @@ public final RepositoryUriResolver uriResolver() { * {@code null} to detect the the protocol based on the credentialsId. Defaults to HTTP if * credentials are {@code null}. Enables support for blank SSH credentials. * @return {@code this} for method chaining. + * @deprecated Use {@link #withCredentials(String)} and {@link #withResolver(RepositoryUriResolver)} */ + @Deprecated @NonNull public GitHubSCMBuilder withCredentials(String credentialsId, RepositoryUriResolver uriResolver) { if (uriResolver == null) { @@ -200,6 +201,12 @@ public GitHubSCMBuilder withCredentials(String credentialsId, RepositoryUriResol return withCredentials(credentialsId); } + @NonNull + public GitHubSCMBuilder withResolver(RepositoryUriResolver uriResolver) { + this.uriResolver = uriResolver; + return this; + } + /** * Returns a {@link RepositoryUriResolver} according to credentials configuration. * @@ -215,12 +222,12 @@ public static RepositoryUriResolver uriResolver( return HTTPS; } else { StandardCredentials credentials = CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( + CredentialsProvider.lookupCredentialsInItem( StandardCredentials.class, context, context instanceof Queue.Task - ? ((Queue.Task) context).getDefaultAuthentication() - : ACL.SYSTEM, + ? ((Queue.Task) context).getDefaultAuthentication2() + : ACL.SYSTEM2, URIRequirementBuilder.create() .withHostname(RepositoryUriResolver.hostnameFromApiUri(apiUri)) .build()), diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java index 26af55efc..6dc522c57 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java @@ -211,6 +211,9 @@ public class GitHubSCMNavigator extends SCMNavigator { private transient Boolean buildForkPRHead; private static final LoadingCache privateModeCache = createPrivateModeCache(); + /** The cache of the credentials object */ + @CheckForNull + private transient volatile StandardCredentials credentials; /** * Constructor. @@ -252,6 +255,15 @@ public GitHubSCMNavigator(String apiUri, String repoOwner, String scanCredential } } + @CheckForNull + @Restricted(NoExternalUse.class) + private StandardCredentials getCredentials(@CheckForNull Item context, boolean forceRefresh) { + if (credentials == null || forceRefresh) { + credentials = Connector.lookupScanCredentials(context, getApiUri(), getCredentialsId(), getRepoOwner()); + } + return credentials; + } + /** * Gets the API endpoint for the GitHub server. * @@ -962,9 +974,7 @@ public void visitSources(SCMSourceObserver observer) throws IOException, Interru throw new AbortException("Must specify user or organization"); } - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) observer.getContext(), apiUri, credentialsId, repoOwner); - + StandardCredentials credentials = getCredentials(observer.getContext(), true); // Github client and validation GitHub github = Connector.connect(apiUri, credentials); try { @@ -1278,9 +1288,7 @@ public void visitSource(String sourceName, SCMSourceObserver observer) throws IO throw new AbortException("Must specify user or organization"); } - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) observer.getContext(), apiUri, credentialsId, repoOwner); - + StandardCredentials credentials = getCredentials(observer.getContext(), false); // Github client and validation GitHub github; try { @@ -1544,9 +1552,7 @@ public List retrieveActions( listener.getLogger().printf("Looking up details of %s...%n", getRepoOwner()); List result = new ArrayList<>(); String apiUri = Util.fixEmptyAndTrim(getApiUri()); - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner); - GitHub hub = Connector.connect(getApiUri(), credentials); + GitHub hub = Connector.connect(getApiUri(), getCredentials(owner, true)); Connector.configureLocalRateLimitChecker(listener, hub); boolean privateMode = !isEnableAvatar() || determinePrivateMode(apiUri); try { @@ -1642,9 +1648,7 @@ public void afterSave(@NonNull SCMNavigatorOwner owner) { GitHubWebHook.get().registerHookFor(owner); try { // FIXME MINOR HACK ALERT - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) owner, getApiUri(), credentialsId, repoOwner); - GitHub hub = Connector.connect(getApiUri(), credentials); + GitHub hub = Connector.connect(getApiUri(), getCredentials(owner, true)); try { GitHubOrgWebHook.register(hub, repoOwner); } finally { @@ -1984,6 +1988,7 @@ public SourceFactory(GitHubSCMNavigatorRequest request) { public SCMSource create(@NonNull String name) { return new GitHubSCMSourceBuilder(getId() + "::" + name, apiUri, credentialsId, repoOwner, name) .withRequest(request) + .withCredentials(credentials) .build(); } } diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java index 7e1d00f1f..5f6f12db5 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java @@ -30,6 +30,7 @@ import static org.apache.commons.lang.StringUtils.removeEnd; import static org.jenkinsci.plugins.github_branch_source.Connector.isCredentialValid; import static org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.API_V3; +import static org.jenkinsci.plugins.github_branch_source.GitHubSCMBuilder.HTTPS; import com.cloudbees.jenkins.GitHubWebHook; import com.cloudbees.plugins.credentials.CredentialsNameProvider; @@ -272,6 +273,9 @@ public class GitHubSCMSource extends AbstractGitSCMSource { /** The cache of {@link ObjectMetadataAction} instances for each open PR. */ @NonNull private transient /*effectively final*/ Map pullRequestContributorCache; + /** The cache of the credentials object */ + @CheckForNull + private transient volatile StandardCredentials credentials; /** * Used during upgrade from 1.x to 2.2.0+ only. @@ -317,6 +321,19 @@ public GitHubSCMSource(String repoOwner, String repository, String repositoryUrl this.traits = new ArrayList<>(); } + /** + * Constructor that passes a looked up credentials object. + * + * @param repoOwner the repository owner. + * @param repository the repository name. + * @param credentials a {@link com.cloudbees.plugins.credentials.common.StandardCredentials} + */ + @Restricted(NoExternalUse.class) + GitHubSCMSource(String repoOwner, String repository, StandardCredentials credentials) { + this(repoOwner, repository, null, false); + this.credentials = credentials; + } + /** * Legacy constructor. * @@ -362,6 +379,15 @@ public GitHubSCMSource( } } + @CheckForNull + @Restricted(NoExternalUse.class) + private StandardCredentials getCredentials(@CheckForNull Item context, boolean forceRefresh) { + if (credentials == null || forceRefresh) { + credentials = Connector.lookupScanCredentials(context, getApiUri(), getCredentialsId(), getRepoOwner()); + } + return credentials; + } + @Restricted(NoExternalUse.class) public boolean isConfiguredByUrl() { return repositoryUrl != null; @@ -598,8 +624,8 @@ public static void setCacheSize(int cacheSize) { /** {@inheritDoc} */ @Override public String getRemote() { - return GitHubSCMBuilder.uriResolver(getOwner(), apiUri, credentialsId) - .getRepositoryUri(apiUri, repoOwner, repository); + // Only HTTPS is applicable to the source remote with Username / Password credentials + return HTTPS.getRepositoryUri(apiUri, repoOwner, repository); } /** {@inheritDoc} */ @@ -619,7 +645,7 @@ public String getPronoun() { @Restricted(DoNotUse.class) @RestrictedSince("2.2.0") public RepositoryUriResolver getUriResolver() { - return GitHubSCMBuilder.uriResolver(getOwner(), apiUri, credentialsId); + return HTTPS; } @Restricted(NoExternalUse.class) @@ -977,8 +1003,10 @@ protected final void retrieve( @CheckForNull SCMHeadEvent event, @NonNull final TaskListener listener) throws IOException, InterruptedException { - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); + // In case we are in an Organization Scan - i.e. (observer instanceof SCMHeadObserver.Any) - use the cached + // credentials + // https://github.com/jenkinsci/branch-api-plugin/blob/2.1169.va_f810c56e895/src/main/java/jenkins/branch/MultiBranchProjectFactory.java#L262 + StandardCredentials credentials = getCredentials(getOwner(), !(observer instanceof SCMHeadObserver.Any)); // Github client and validation final GitHub github = Connector.connect(apiUri, credentials); try { @@ -1279,10 +1307,8 @@ public SCMRevision create(@NonNull PullRequestSCMHead head, @Nullable Void ignor @Override protected Set retrieveRevisions(@NonNull TaskListener listener, Item retrieveContext) throws IOException, InterruptedException { - StandardCredentials credentials = - Connector.lookupScanCredentials(retrieveContext, apiUri, credentialsId, repoOwner); // Github client and validation - final GitHub github = Connector.connect(apiUri, credentials); + final GitHub github = Connector.connect(apiUri, getCredentials(retrieveContext, false)); try { Connector.configureLocalRateLimitChecker(listener, github); Set result = new TreeSet<>(); @@ -1385,10 +1411,8 @@ protected Set retrieveRevisions(@NonNull TaskListener listener, Item ret @Override protected SCMRevision retrieve(@NonNull String headName, @NonNull TaskListener listener, Item retrieveContext) throws IOException, InterruptedException { - StandardCredentials credentials = - Connector.lookupScanCredentials(retrieveContext, apiUri, credentialsId, repoOwner); // Github client and validation - final GitHub github = Connector.connect(apiUri, credentials); + final GitHub github = Connector.connect(apiUri, getCredentials(retrieveContext, false)); try { Connector.configureLocalRateLimitChecker(listener, github); // Input data validation @@ -1614,10 +1638,8 @@ public void unwrap() throws IOException, InterruptedException { @NonNull @Override protected SCMProbe createProbe(@NonNull SCMHead head, @CheckForNull final SCMRevision revision) throws IOException { - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); // Github client and validation - GitHub github = Connector.connect(apiUri, credentials); + GitHub github = Connector.connect(apiUri, getCredentials(getOwner(), false)); try { String fullName = repoOwner + "/" + repository; final GHRepository repo = github.getRepository(fullName); @@ -1632,11 +1654,8 @@ protected SCMProbe createProbe(@NonNull SCMHead head, @CheckForNull final SCMRev @Override @CheckForNull protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOException, InterruptedException { - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); - // Github client and validation - GitHub github = Connector.connect(apiUri, credentials); + GitHub github = Connector.connect(apiUri, getCredentials(getOwner(), false)); try { try { Connector.checkConnectionValidity(apiUri, listener, credentials, github); @@ -1783,11 +1802,9 @@ PullRequestSource retrievePullRequestSource(int number) { if (StringUtils.isNotBlank(repository)) { String fullName = repoOwner + "/" + repository; LOGGER.log(Level.INFO, "Getting remote pull requests from {0}", fullName); - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); LogTaskListener listener = new LogTaskListener(LOGGER, Level.INFO); try { - GitHub github = Connector.connect(apiUri, credentials); + GitHub github = Connector.connect(apiUri, getCredentials(getOwner(), false)); try { Connector.configureLocalRateLimitChecker(listener, github); ghRepository = github.getRepository(fullName); @@ -1952,8 +1969,7 @@ protected List retrieveActions(@CheckForNull SCMSourceEvent event, @NonN result.add(new GitHubRepoMetadataAction()); String repository = this.repository; - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); + StandardCredentials credentials = getCredentials(getOwner(), true); GitHub hub = Connector.connect(apiUri, credentials); try { Connector.checkConnectionValidity(apiUri, listener, credentials, hub); @@ -2857,8 +2873,7 @@ protected Set create() { .format( "Connecting to %s to obtain list of collaborators for %s/%s%n", apiUri, repoOwner, repository); - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); + StandardCredentials credentials = getCredentials(getOwner(), false); // Github client and validation try { GitHub github = Connector.connect(apiUri, credentials); @@ -2922,9 +2937,7 @@ public GHPermissionType fetch(String username) throws IOException, InterruptedEx .format( "Connecting to %s to check permissions of obtain list of %s for %s/%s%n", apiUri, username, repoOwner, repository); - StandardCredentials credentials = - Connector.lookupScanCredentials((Item) getOwner(), apiUri, credentialsId, repoOwner); - github = Connector.connect(apiUri, credentials); + github = Connector.connect(apiUri, getCredentials(getOwner(), false)); String fullName = repoOwner + "/" + repository; repo = github.getRepository(fullName); } diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceBuilder.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceBuilder.java index 09c308bf7..30d240ae7 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceBuilder.java @@ -23,6 +23,7 @@ */ package org.jenkinsci.plugins.github_branch_source; +import com.cloudbees.plugins.credentials.common.StandardCredentials; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import jenkins.scm.api.trait.SCMSourceBuilder; @@ -45,6 +46,9 @@ public class GitHubSCMSourceBuilder extends SCMSourceBuilder withCredentials(StandardCredentials credentials) { + this.credentials = credentials; + return this; + } + /** {@inheritDoc} */ @NonNull @Override public GitHubSCMSource build() { - GitHubSCMSource result = new GitHubSCMSource(repoOwner, projectName()); + GitHubSCMSource result = new GitHubSCMSource(repoOwner, projectName(), credentials); result.setId(id()); result.setApiUri(apiUri()); result.setCredentialsId(credentialsId()); diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/SSHCheckoutTrait.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/SSHCheckoutTrait.java index 76b0e40e6..67ecdad4b 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/SSHCheckoutTrait.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/SSHCheckoutTrait.java @@ -98,7 +98,7 @@ public final String getCredentialsId() { /** {@inheritDoc} */ @Override protected void decorateBuilder(SCMBuilder builder) { - ((GitHubSCMBuilder) builder).withCredentials(credentialsId, GitHubSCMBuilder.SSH); + ((GitHubSCMBuilder) builder).withCredentials(credentialsId).withResolver(GitHubSCMBuilder.SSH); } /** Our descriptor. */ @@ -190,24 +190,24 @@ public FormValidation doCheckCredentialsId( return FormValidation.ok(); } if (CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( + CredentialsProvider.lookupCredentialsInItem( SSHUserPrivateKey.class, context, context instanceof Queue.Task - ? ((Queue.Task) context).getDefaultAuthentication() - : ACL.SYSTEM, + ? ((Queue.Task) context).getDefaultAuthentication2() + : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverUrl).build()), CredentialsMatchers.withId(value)) != null) { return FormValidation.ok(); } if (CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentials( + CredentialsProvider.lookupCredentialsInItem( StandardUsernameCredentials.class, context, context instanceof Queue.Task - ? ((Queue.Task) context).getDefaultAuthentication() - : ACL.SYSTEM, + ? ((Queue.Task) context).getDefaultAuthentication2() + : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverUrl).build()), CredentialsMatchers.withId(value)) != null) { diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java index 98a1bbdbc..1f1ef4d95 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilderTest.java @@ -223,8 +223,9 @@ public void given__cloud_branch_rev_userkey__when__build__then__scmBuilt() throw 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); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -406,8 +407,9 @@ public void given__cloud_branch_rev_userkey_sshtrait_anon__when__build__then__sc 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); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -595,8 +597,9 @@ public void given__cloud_branch_rev_userkey_sshtrait_userkey__when__build__then_ 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); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -741,8 +744,9 @@ public void given__cloud_branch_norev_userpass__when__build__then__scmBuilt() th public void given__cloud_branch_norev_userkey__when__build__then__scmBuilt() throws Exception { createGitHubSCMSourceForTest(false, null); BranchSCMHead head = new BranchSCMHead("test-branch"); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue())); @@ -903,8 +907,9 @@ public void given__server_branch_rev_userkey__when__build__then__scmBuilt() thro 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); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -1044,8 +1049,9 @@ public void given__server_branch_norev_userpass__when__build__then__scmBuilt() t 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); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue())); @@ -1230,8 +1236,9 @@ public void given__cloud_pullHead_rev_userkey__when__build__then__scmBuilt() thr PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe"); createGitHubSCMSourceForTest(false, null); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -1395,8 +1402,9 @@ public void given__cloud_pullHead_norev_userkey__when__build__then__scmBuilt() t new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.HEAD); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue())); @@ -1581,8 +1589,9 @@ public void given__server_pullHead_rev_userkey__when__build__then__scmBuilt() th ChangeRequestCheckoutStrategy.HEAD); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe"); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -1746,8 +1755,9 @@ public void given__server_pullHead_norev_userkey__when__build__then__scmBuilt() new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.HEAD); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue())); @@ -1962,8 +1972,9 @@ public void given__cloud_pullMerge_rev_userkey__when__build__then__scmBuilt() th ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe"); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -2166,8 +2177,9 @@ public void given__cloud_pullMerge_norev_userkey__when__build__then__scmBuilt() new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue())); @@ -2394,8 +2406,9 @@ public void given__server_pullMerge_rev_userkey__when__build__then__scmBuilt() t ChangeRequestCheckoutStrategy.MERGE); PullRequestSCMRevision revision = new PullRequestSCMRevision( head, "deadbeefcafebabedeadbeefcafebabedeadbeef", "cafebabedeadbeefcafebabedeadbeefcafebabe"); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, revision) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(revision)); @@ -2600,8 +2613,9 @@ public void given__server_pullMerge_norev_userkey__when__build__then__scmBuilt() new BranchSCMHead("test-branch"), new SCMHeadOrigin.Fork("qa/qa-repo"), ChangeRequestCheckoutStrategy.MERGE); - source.setCredentialsId("user-key"); - GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null); + GitHubSCMBuilder instance = new GitHubSCMBuilder(source, head, null) + .withCredentials("user-key") + .withResolver(GitHubSCMBuilder.SSH); assertThat(instance.credentialsId(), is("user-key")); assertThat(instance.head(), is(head)); assertThat(instance.revision(), is(nullValue()));