Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #143 from stephenc/jenkins-41246
[FIXED JENKINS-41246] Guard against PRs from deleted forks
  • Loading branch information
stephenc committed Jul 5, 2017
2 parents 675bb4a + 9abb96c commit ab97be9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Expand Up @@ -619,12 +619,14 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta
}
continue;
}
boolean trusted = collaboratorNames != null
&& collaboratorNames.contains(ghPullRequest.getHead().getRepository().getOwnerName());
GHRepository repository = ghPullRequest.getHead().getRepository();
// repository may be null for deleted forks (JENKINS-41246) in which case they are not trusted
boolean trusted = repository != null && collaboratorNames != null
&& collaboratorNames.contains(repository.getOwnerName());
if (!trusted) {
listener.getLogger().format(" (not from a trusted source)%n");
}
for (boolean merge : new boolean[] {false, true}) {
for (boolean merge : new boolean[]{false, true}) {
String branchName = "PR-" + number;
if (merge && fork) {
if (!buildForkPRMerge) {
Expand Down Expand Up @@ -671,7 +673,7 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta
user.getLogin(),
user.getName(),
user.getEmail()
));
));
pullRequestMetadataKeys.add(number);
PullRequestSCMHead head = new PullRequestSCMHead(ghPullRequest, branchName, merge);
if (includes != null && !includes.contains(head)) {
Expand Down Expand Up @@ -708,10 +710,12 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta
} else {
baseHash = ghPullRequest.getBase().getSha();
}
PullRequestSCMRevision rev = new PullRequestSCMRevision(head, baseHash, ghPullRequest.getHead().getSha());
PullRequestSCMRevision rev =
new PullRequestSCMRevision(head, baseHash, ghPullRequest.getHead().getSha());
observer.observe(head, rev);
if (!observer.isObserving()) {
listener.getLogger().format("%n %d pull requests were processed (query completed)%n", pullrequests);
listener.getLogger()
.format("%n %d pull requests were processed (query completed)%n", pullrequests);
return;
}
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;

/**
* Head corresponding to a pull request.
Expand Down Expand Up @@ -61,8 +62,9 @@ public final class PullRequestSCMHead extends SCMHead implements ChangeRequestSC
this.number = pr.getNumber();
this.target = new BranchSCMHead(pr.getBase().getRef());
// the source stuff is immutable for a pull request on github, so safe to store here
this.sourceOwner = pr.getHead().getRepository().getOwnerName();
this.sourceRepo = pr.getHead().getRepository().getName();
GHRepository repository = pr.getHead().getRepository(); // may be null for deleted forks JENKINS-41246
this.sourceOwner = repository == null ? null : repository.getOwnerName();
this.sourceRepo = repository == null ? null : repository.getName();
this.sourceBranch = pr.getHead().getRef();
}

Expand Down

0 comments on commit ab97be9

Please sign in to comment.