Skip to content

Commit

Permalink
Merge pull request #5 from jglick/retrieve-SCMHead-JENKINS-31319
Browse files Browse the repository at this point in the history
[JENKINS-31319] Implement retrieve(SCMHead, TaskListener) overload
  • Loading branch information
jglick committed Nov 2, 2015
2 parents e8eab69 + e4b34bb commit 7845c27
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
target
work
/github-branch-source.iml
/.idea
Expand Up @@ -250,9 +250,25 @@ protected SCMSourceCriteria.Probe getProbe(final String branch, final String thi
}

@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 {
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -88,6 +89,11 @@ protected List<RefSpec> getRefSpecs() {
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() {
Expand Down

0 comments on commit 7845c27

Please sign in to comment.