Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-41246] Guard against PRs from deleted forks #143

Merged
merged 2 commits into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gratuitous

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()
));
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gratuitous

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gratuitous

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gratuitous

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest marking getters @CheckForNull.

this.sourceBranch = pr.getHead().getRef();
}

Expand Down