Skip to content

Commit

Permalink
[FIXES JENKINS-30223] Migrate to new version of GH Plugin in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lanwen committed Aug 31, 2015
1 parent 10cd2e0 commit ab9c85d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Expand Up @@ -125,7 +125,7 @@ private GitHub connect(GitHubRepositoryName gitHubRepoName) {
Iterator<GitHub> withAuth = GitHubPlugin.configuration()
.findGithubConfig(withHost(gitHubRepoName.getHost())).iterator();

if(withAuth.hasNext()) {
if (withAuth.hasNext()) {
return withAuth.next();
} else {
LOGGER.warning(format("Cannot find any credential for GitHub at {0}", gitHubRepoName.getHost()));
Expand Down
Expand Up @@ -12,9 +12,8 @@

package com.elasticbox.jenkins.tests;

import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.elasticbox.jenkins.util.Condition;
import com.cloudbees.jenkins.Credential;
import com.cloudbees.jenkins.GitHubPushTrigger;
import com.elasticbox.Client;
import com.elasticbox.ClientException;
import com.elasticbox.jenkins.triggers.PullRequestBuildTrigger;
Expand Down Expand Up @@ -60,6 +59,9 @@
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.jenkinsci.plugins.github.config.GitHubTokenCredentialsCreator;
import org.junit.Assert;
import org.junit.Before;
import org.kohsuke.github.*;
Expand Down Expand Up @@ -125,8 +127,14 @@ public void setup() throws Exception {
ghPullRequest.close();
pullRequest = new MockPullRequest(ghPullRequest);
testTag = UUID.randomUUID().toString().substring(0, 30);
GitHubPushTrigger.DescriptorImpl descriptor = (GitHubPushTrigger.DescriptorImpl) jenkins.getInstance().getDescriptor(GitHubPushTrigger.class);
descriptor.getCredentials().add(new Credential(TestUtils.GITHUB_USER, apiGithubAddress, TestUtils.GITHUB_ACCESS_TOKEN));

StandardCredentials creds = jenkins.getInstance()
.getDescriptorByType(GitHubTokenCredentialsCreator.class)
.createCredentials(apiGithubAddress, TestUtils.GITHUB_ACCESS_TOKEN, TestUtils.GITHUB_USER);
GitHubServerConfig config = new GitHubServerConfig(creds.getId());
config.setApiUrl(apiGithubAddress);
GitHubPlugin.configuration().getConfigs().add(config);

TestUtils.TemplateResolver templateResolver = new TemplateResolveImpl() {

@Override
Expand Down

0 comments on commit ab9c85d

Please sign in to comment.