-
Notifications
You must be signed in to change notification settings - Fork 369
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -671,7 +673,7 @@ private void doRetrieve(SCMSourceCriteria criteria, SCMHeadObserver observer, Ta | |
user.getLogin(), | ||
user.getName(), | ||
user.getEmail() | ||
)); | ||
)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
|
@@ -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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gratuitous |
||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest marking getters |
||
this.sourceBranch = pr.getHead().getRef(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gratuitous