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

PR fetch should be more lenient #148

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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 @@ -134,33 +134,43 @@
String.format("No pull request found for SonarQube task '%s'", taskId));
}

ProjectPullRequests.PullRequest pullRequest =
sonarClient.projectPullRequests().list(new ListRequest().setProject(componentKey))
.getPullRequestsList().stream()
.filter(pr -> pullRequestKey.equals(pr.getKey()))
.findFirst()
.orElseThrow(
() ->
new IllegalStateException(
String.format(
"No pull request found for project '%s' and key '%s'.",
componentKey, pullRequestKey)));
ProjectPullRequests.PullRequest pullRequest;
while (true) {
pullRequest =
sonarClient.projectPullRequests().list(new ListRequest().setProject(componentKey))
.getPullRequestsList().stream()
.filter(pr -> pullRequestKey.equals(pr.getKey()))
.findFirst()
.orElse(null);
if (pullRequest != null) {
break;
}
TaskListenerLogger.log(
listener,
"Waiting %s before re-performing lookup of pull request '%s' on project '%s' ...",
CE_TASK_COMPLETION_CHECK_INTERVAL,
pullRequestKey,
componentKey);
Thread.sleep(CE_TASK_COMPLETION_CHECK_INTERVAL.toMillis());
}

SearchRequest issueSearchRequest =
new SearchRequest()
.setComponentKeys(Collections.singletonList(componentKey))
.setPullRequest(pullRequestKey);

Issues.SearchWsResponse issueSearchResponse = sonarClient.issues().search(issueSearchRequest);

Components components =
new Components(
issueSearchResponse.getComponentsList().stream()
.map(PullRequestComponent::new)
.collect(Collectors.toList()));

ProjectPullRequests.PullRequest finalPullRequest = pullRequest;

return issueSearchResponse.getIssuesList().stream()
.map(issue -> new PullRequestIssue(pullRequest, components, issue, serverUrl))
.map(issue -> new PullRequestIssue(finalPullRequest, components, issue, serverUrl))

Check warning on line 173 in src/main/java/org/jenkinsci/plugins/sonargerrit/sonar/pull_request_analysis/PullRequestAnalysisTask.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 139-173 are not covered by tests
.collect(Collectors.toList());
}

Expand Down
Loading