Skip to content

Commit

Permalink
PR fetch should be more lenient
Browse files Browse the repository at this point in the history
This change tries to account for issue like the one described in
mc1arke/sonarqube-community-branch-plugin#759 (comment)
  • Loading branch information
reda-alaoui committed Oct 24, 2023
1 parent db75526 commit 890738e
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,25 @@ public List<Issue> fetchIssues(TaskListener listener) throws InterruptedExceptio
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()
Expand All @@ -159,8 +167,10 @@ public List<Issue> fetchIssues(TaskListener listener) throws InterruptedExceptio
.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))
.collect(Collectors.toList());
}

Expand Down

0 comments on commit 890738e

Please sign in to comment.