Skip to content

Commit 06c39fd

Browse files
committed
[JENKINS-73791] Validate PR earlier to prevent branch scan interruptions
1 parent afe92fd commit 06c39fd

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,19 @@ public GHPermissionType fetch(String username) throws IOException, InterruptedEx
10531053
}
10541054
});
10551055

1056+
if (request.isFetchPRs()) {
1057+
// JENKINS-56996 / JENKINS-73791
1058+
// PRs are one the most error prone areas for scans
1059+
// Branches and tags are contained only the current repo, PRs go across forks
1060+
// FileNotFoundException can occur in a number of situations
1061+
// When this happens, it is not ideal behavior but it is better to let the PR be
1062+
// orphaned
1063+
// and the orphan strategy control the result than for this error to stop scanning
1064+
// (For Org scanning this is particularly important.)
1065+
// If some more general IO exception is thrown, we will still fail.
1066+
validatePullRequests(request);
1067+
}
1068+
10561069
if (request.isFetchBranches()
10571070
&& !request.isComplete()
10581071
&& this.shouldRetrieve(observer, event, BranchSCMHead.class)) {
@@ -1067,6 +1080,7 @@ public GHPermissionType fetch(String username) throws IOException, InterruptedEx
10671080
HyperlinkNote.encodeTo(
10681081
resolvedRepositoryUrl + "/tree/" + branchName, branchName));
10691082
BranchSCMHead head = new BranchSCMHead(branchName);
1083+
10701084
if (request.process(
10711085
head,
10721086
new SCMRevisionImpl(head, branch.getSHA1()),
@@ -1081,8 +1095,6 @@ public SCMSourceCriteria.Probe create(
10811095
}
10821096
},
10831097
new CriteriaWitness(listener))) {
1084-
listener.getLogger()
1085-
.format("%n %d branches were processed (query completed)%n", count);
10861098
break;
10871099
}
10881100
}
@@ -1095,18 +1107,6 @@ public SCMSourceCriteria.Probe create(
10951107
int count = 0;
10961108
int errorCount = 0;
10971109
Map<Boolean, Set<ChangeRequestCheckoutStrategy>> strategies = request.getPRStrategies();
1098-
1099-
// JENKINS-56996
1100-
// PRs are one the most error prone areas for scans
1101-
// Branches and tags are contained only the current repo, PRs go across forks
1102-
// FileNotFoundException can occur in a number of situations
1103-
// When this happens, it is not ideal behavior but it is better to let the PR be
1104-
// orphaned
1105-
// and the orphan strategy control the result than for this error to stop scanning
1106-
// (For Org scanning this is particularly important.)
1107-
// If some more general IO exception is thrown, we will still fail.
1108-
1109-
validatePullRequests(request);
11101110
for (final GHPullRequest pr : request.getPullRequests()) {
11111111
int number = pr.getNumber();
11121112
try {

0 commit comments

Comments
 (0)