diff options
author | Eric Giffon <eric.giffon@sonarsource.com> | 2023-12-22 14:47:59 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-01-17 20:02:44 +0000 |
commit | 529b1f2c82ae59db5cf8eb10f16ce286d2b7c8b3 (patch) | |
tree | 9f620bf1ae5d1e950a5ab4ead753ea7303ed34b7 | |
parent | 65e00c508dd877e31a9a412a4b9704dc2eb51ad6 (diff) | |
download | sonarqube-529b1f2c82ae59db5cf8eb10f16ce286d2b7c8b3.tar.gz sonarqube-529b1f2c82ae59db5cf8eb10f16ce286d2b7c8b3.zip |
SONAR-21259 Fix code issues
2 files changed, 12 insertions, 10 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index 1222629845f..8a982b76466 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -41,6 +41,7 @@ import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -179,18 +180,19 @@ public class IssueQueryFactory { if (request.getFixedInPullRequest() != null) { issueKeys = getIssuesFixedByPullRequest(dbSession, request); } - if (request.getIssues() != null && !request.getIssues().isEmpty()) { + List<String> requestIssues = request.getIssues(); + if (requestIssues != null && !requestIssues.isEmpty()) { if (issueKeys == null) { issueKeys = new ArrayList<>(); } - issueKeys.addAll(request.getIssues()); + issueKeys.addAll(requestIssues); } - return issueKeys; } private Collection<String> getIssuesFixedByPullRequest(DbSession dbSession, SearchRequest request) { String fixedInPullRequest = request.getFixedInPullRequest(); + checkArgument(StringUtils.isNotBlank(fixedInPullRequest), "Parameter '%s' is empty", PARAM_FIXED_IN_PULL_REQUEST); List<String> componentKeys = request.getComponentKeys(); if (componentKeys == null || componentKeys.size() != 1) { throw new IllegalArgumentException("Exactly one project needs to be provided in the " + @@ -200,14 +202,15 @@ public class IssueQueryFactory { ProjectDto projectDto = dbClient.projectDao().selectProjectByKey(dbSession, projectKey) .orElseThrow(() -> new IllegalArgumentException("Project with key '" + projectKey + "' does not exist")); BranchDto pullRequest = dbClient.branchDao().selectByPullRequestKey(dbSession, projectDto.getUuid(), fixedInPullRequest) - .orElseThrow(() -> new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not exist for a project " + + .orElseThrow(() -> new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not exist for project " + projectKey)); - if (request.getBranch() != null) { - BranchDto targetBranch = dbClient.branchDao().selectByBranchKey(dbSession, projectDto.getUuid(), request.getBranch()) - .orElseThrow(() -> new IllegalArgumentException("Branch with key '" + request.getBranch() + "' does not exist")); + String branch = request.getBranch(); + if (branch != null) { + BranchDto targetBranch = dbClient.branchDao().selectByBranchKey(dbSession, projectDto.getUuid(), branch) + .orElseThrow(() -> new IllegalArgumentException("Branch with key '" + branch + "' does not exist")); if (!Objects.equals(targetBranch.getUuid(), pullRequest.getMergeBranchUuid())) { - throw new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not target branch '" + request.getBranch() + "'"); + throw new IllegalArgumentException("Pull request with key '" + fixedInPullRequest + "' does not target branch '" + branch + "'"); } } return dbClient.issueFixedDao().selectByPullRequest(dbSession, pullRequest.getUuid()) @@ -216,7 +219,6 @@ public class IssueQueryFactory { .collect(Collectors.toSet()); } - private static Optional<ZoneId> parseTimeZone(@Nullable String timeZone) { if (timeZone == null) { return Optional.empty(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java index e9fc5f67010..57bf527f6b8 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java @@ -2228,7 +2228,7 @@ public class SearchActionIT { assertThatThrownBy(request::execute) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Pull request with key 'wrongPullRequest' does not exist for a project " + project.projectKey()); + .hasMessage("Pull request with key 'wrongPullRequest' does not exist for project " + project.projectKey()); } @Test |