Skip to content
Permalink
Browse files

Merge pull request #5 from jglick/retrieve-SCMHead-JENKINS-31319

[JENKINS-31319] Implement retrieve(SCMHead, TaskListener) overload
  • Loading branch information...
jglick committed Nov 2, 2015
2 parents e8eab69 + e4b34bb commit 7845c276e0de7baee9091f2234a89c7293dbbd22
@@ -1,2 +1,4 @@
target
work
/github-branch-source.iml
/.idea
@@ -250,9 +250,25 @@ public String getRemote() {
}

@Override
@CheckForNull
protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOException, InterruptedException {
// TODO reimplement using GitHub API
return super.retrieve(head, listener);
StandardCredentials credentials = Connector.lookupScanCredentials(getOwner(), apiUri, scanCredentialsId);
if (credentials == null) {
listener.getLogger().println("No scan credentials, skipping");
return null;
}
listener.getLogger().format("Connecting to %s using %s%n", getDescriptor().getDisplayName(), CredentialsNameProvider.name(credentials));
GitHub github = Connector.connect(apiUri, credentials);
String fullName = repoOwner + "/" + repository;
GHRepository repo = github.getRepository(fullName);
return doRetrieve(head, listener, repo);
}

protected /*abstract*/ SCMRevision doRetrieve(SCMHead head, TaskListener listener, GHRepository repo) throws IOException, InterruptedException {
listener.error("Please implement " + getClass().getName() + ".doRetrieve(SCMHead, TaskListener, GHRepository)");
SCMHeadObserver.Selector selector = SCMHeadObserver.select(head);
doRetrieve(selector, listener, repo);
return selector.result();
}

public static abstract class AbstractGitHubSCMSourceDescriptor extends SCMSourceDescriptor {
@@ -38,6 +38,7 @@
import jenkins.scm.api.SCMSourceCriteria;
import org.eclipse.jgit.transport.RefSpec;
import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHRef;
import org.kohsuke.github.GHRepository;
import org.kohsuke.stapler.DataBoundConstructor;

@@ -88,6 +89,11 @@
listener.getLogger().format(" %d branches were processed%n", branches);
}

@Override protected SCMRevision doRetrieve(SCMHead head, TaskListener listener, GHRepository repo) throws IOException, InterruptedException {
GHRef ref = repo.getRef("heads/" + head.getName());
return new SCMRevisionImpl(head, ref.getObject().getSha());
}

@Extension public static class DescriptorImpl extends AbstractGitHubSCMSourceDescriptor {

@Override public String getDisplayName() {

0 comments on commit 7845c27

Please sign in to comment.
You can’t perform that action at this time.