Skip to content

Commit

Permalink
Merge pull request #23 from Andne/ghe-anon
Browse files Browse the repository at this point in the history
[JENKINS-33183] Allow anon credentials when retrieving commit
  • Loading branch information
recena committed Mar 4, 2016
2 parents b407e67 + 5b64de6 commit e378438
Showing 1 changed file with 18 additions and 8 deletions.
Expand Up @@ -350,15 +350,25 @@ protected SCMSourceCriteria.Probe getProbe(final String branch, final String thi
@CheckForNull
protected SCMRevision retrieve(SCMHead head, TaskListener listener) throws IOException, InterruptedException {
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);
try {
if (credentials != null && !github.isCredentialValid()) {
listener.getLogger().format("Invalid scan credentials, skipping%n");
return null;
}
if (!github.isAnonymous()) {
listener.getLogger().format("Connecting to %s using %s%n", getDescriptor().getDisplayName(),
CredentialsNameProvider.name(credentials));
} else {
listener.getLogger().format("Connecting to %s using anonymous access%n", getDescriptor().getDisplayName());
}
String fullName = repoOwner + "/" + repository;
GHRepository repo = github.getRepository(fullName);
return doRetrieve(head, listener, repo);
} catch (RateLimitExceededException rle) {
listener.getLogger().format("%n%s%n%n", rle.getMessage());
throw new InterruptedException();
}
}

protected SCMRevision doRetrieve(SCMHead head, TaskListener listener, GHRepository repo) throws IOException, InterruptedException {
Expand Down

0 comments on commit e378438

Please sign in to comment.