Skip to content
Permalink
Browse files
[JENKINS-34395] Update to 1.89 of github-api and guard against 404 in…
… repos without any tags
  • Loading branch information
stephenc committed Sep 25, 2017
1 parent 51fc6ef commit 4d47488b3116e2a605ff786353f4ac49319e9d69
@@ -51,7 +51,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.87-20170901.115941-1</version>
<version>1.89</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -65,6 +65,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@@ -112,6 +113,7 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.github.GHBranch;
import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHFileNotFoundException;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHMyself;
import org.kohsuke.github.GHOrganization;
@@ -2000,8 +2002,8 @@ public void observe(GHPullRequest pr) {
pr.getHtmlUrl().toExternalForm()
)
);
GHUser user = pr.getUser();
try {
GHUser user = pr.getUser();
if (users.containsKey(user.getLogin())) {
// looked up this user already
user = users.get(user.getLogin());
@@ -2083,7 +2085,58 @@ public LazyTags(GitHubSCMSourceRequest request, GHRepository repo) {
return Collections.singletonList(repo.getRef("tags/" + tagName));
}
request.listener().getLogger().format("%n Getting remote tags...%n");
return repo.listRefs("tags");
// GitHub will give a 404 if the repository does not have any tags
// we could rework the code that iterates to expect the 404, but that
// would mean leaking the strange behaviour in every trait that consults the list
// of tags. (And GitHub API is probably correct in throwing the GHFileNotFoundException
// from a PagedIterable, so we don't want to fix that)
//
// Instead we just return a wrapped iterator that does the right thing.
final Iterable<GHRef> iterable = repo.listRefs("tags");
return new Iterable<GHRef>() {
@Override
public Iterator<GHRef> iterator() {
final Iterator<GHRef> iterator;
try {
iterator = iterable.iterator();
} catch (Error e) {
if (e.getCause() instanceof GHFileNotFoundException) {
return Collections.<GHRef>emptyList().iterator();
}
throw e;
}
return new Iterator<GHRef>() {
@Override
public boolean hasNext() {
try {
return iterator.hasNext();
} catch (Error e) {
if (e.getCause() instanceof GHFileNotFoundException) {
return false;
}
throw e;
}
}

@Override
public GHRef next() {
try {
return iterator.next();
} catch (Error e) {
if (e.getCause() instanceof GHFileNotFoundException) {
throw new NoSuchElementException();
}
throw e;
}
}

@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
}
};
} catch (IOException | InterruptedException e) {
throw new GitHubSCMSource.WrappedException(e);
}
@@ -26,6 +26,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.InvisibleAction;
import java.io.IOException;
import java.net.URL;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.actions.ChangeRequestAction;
@@ -47,7 +48,7 @@
private final String userLogin;
private final String baseRef;

PullRequestAction(GHPullRequest pr) {
PullRequestAction(GHPullRequest pr) throws IOException {
number = pr.getNumber();
url = pr.getHtmlUrl();
title = pr.getTitle();
@@ -60,6 +60,7 @@
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;

import static com.google.common.collect.Sets.immutableEnumSet;
@@ -266,7 +267,14 @@ public String getSourceName() {
// fake repository name
return Collections.emptyMap();
}
String prOwnerName = ghPullRequest.getHead().getUser().getLogin();
GHUser user;
try {
user = ghPullRequest.getHead().getUser();
} catch (IOException e) {
// fake owner name
return Collections.emptyMap();
}
String prOwnerName = user.getLogin();
if (!prOwnerName.matches(GitHubSCMSource.VALID_GITHUB_USER_NAME)) {
// fake owner name
return Collections.emptyMap();

0 comments on commit 4d47488

Please sign in to comment.