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

[JENKINS-73791] Prevent PR 404 on details to break Branches scan #811

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,19 @@ public GHPermissionType fetch(String username) throws IOException, InterruptedEx
}
});

if (request.isFetchPRs()) {
// JENKINS-56996 / JENKINS-73791
// PRs are one the most error prone areas for scans
// Branches and tags are contained only the current repo, PRs go across forks
// FileNotFoundException can occur in a number of situations
// When this happens, it is not ideal behavior but it is better to let the PR be
// orphaned
// and the orphan strategy control the result than for this error to stop scanning
// (For Org scanning this is particularly important.)
// If some more general IO exception is thrown, we will still fail.
validatePullRequests(request);
}

if (request.isFetchBranches()
&& !request.isComplete()
&& this.shouldRetrieve(observer, event, BranchSCMHead.class)) {
Expand All @@ -1039,6 +1052,7 @@ public GHPermissionType fetch(String username) throws IOException, InterruptedEx
HyperlinkNote.encodeTo(
resolvedRepositoryUrl + "/tree/" + branchName, branchName));
BranchSCMHead head = new BranchSCMHead(branchName);

if (request.process(
head,
new SCMRevisionImpl(head, branch.getSHA1()),
Expand All @@ -1053,8 +1067,6 @@ public SCMSourceCriteria.Probe create(
}
},
new CriteriaWitness(listener))) {
listener.getLogger()
.format("%n %d branches were processed (query completed)%n", count);
break;
}
}
Expand All @@ -1067,17 +1079,6 @@ public SCMSourceCriteria.Probe create(
int count = 0;
int errorCount = 0;
Map<Boolean, Set<ChangeRequestCheckoutStrategy>> strategies = request.getPRStrategies();

// JENKINS-56996
// PRs are one the most error prone areas for scans
// Branches and tags are contained only the current repo, PRs go across forks
// FileNotFoundException can occur in a number of situations
// When this happens, it is not ideal behavior but it is better to let the PR be
// orphaned
// and the orphan strategy control the result than for this error to stop scanning
// (For Org scanning this is particularly important.)
// If some more general IO exception is thrown, we will still fail.

validatePullRequests(request);
for (final GHPullRequest pr : request.getPullRequests()) {
int number = pr.getNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ public boolean isHead(@NonNull Probe probe, @NonNull TaskListener listener) thro

@Test
public void fetchSmokes_badUser() throws Exception {
source.setTraits(Arrays.asList(
new BranchDiscoveryTrait(true, false),
new ForkPullRequestDiscoveryTrait(
EnumSet.of(ChangeRequestCheckoutStrategy.MERGE),
new ForkPullRequestDiscoveryTrait.TrustContributors())));
// make it so PR-2 returns a file not found for user
githubApi.stubFor(get(urlMatching("(/api/v3)?/repos/cloudbeers/yolo/pulls/2"))
.inScenario("Pull Request Merge Hash")
Expand Down
Loading