From 215c107d7f79fe008030689c4556a34347d0072e Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Fri, 30 Jul 2021 09:17:47 +0200 Subject: [PATCH] SONAR-15138 - Download Report Action --- .../server/component/ComponentFinder.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java index b7652981334..8bcdb08f73a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -100,16 +100,25 @@ public class ComponentFinder { return value; } + public BranchDto getBranchOrPullRequest(DbSession dbSession, ComponentDto project, @Nullable String branchKey, @Nullable String pullRequestKey) { + return getBranchOrPullRequest(dbSession, project.uuid(), project.getKey(), branchKey, pullRequestKey); + } + public BranchDto getBranchOrPullRequest(DbSession dbSession, ProjectDto project, @Nullable String branchKey, @Nullable String pullRequestKey) { + return getBranchOrPullRequest(dbSession, project.getUuid(), project.getKey(), branchKey, pullRequestKey); + } + + public BranchDto getBranchOrPullRequest(DbSession dbSession, String projectUuid, String projectKey, + @Nullable String branchKey, @Nullable String pullRequestKey) { if (branchKey != null) { - return dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), branchKey) - .orElseThrow(() -> new NotFoundException(String.format("Branch '%s' in project '%s' not found", branchKey, project.getKey()))); + return dbClient.branchDao().selectByBranchKey(dbSession, projectUuid, branchKey) + .orElseThrow(() -> new NotFoundException(String.format("Branch '%s' in project '%s' not found", branchKey, projectKey))); } else if (pullRequestKey != null) { - return dbClient.branchDao().selectByPullRequestKey(dbSession, project.getUuid(), pullRequestKey) - .orElseThrow(() -> new NotFoundException(String.format("Pull request '%s' in project '%s' not found", pullRequestKey, project.getKey()))); + return dbClient.branchDao().selectByPullRequestKey(dbSession, projectUuid, pullRequestKey) + .orElseThrow(() -> new NotFoundException(String.format("Pull request '%s' in project '%s' not found", pullRequestKey, projectKey))); } - return dbClient.branchDao().selectByUuid(dbSession, project.getUuid()) - .orElseThrow(() -> new NotFoundException(String.format("Main branch in project '%s' not found", project.getKey()))); + return dbClient.branchDao().selectByUuid(dbSession, projectUuid) + .orElseThrow(() -> new NotFoundException(String.format("Main branch in project '%s' not found", projectKey))); } public BranchDto getMainBranch(DbSession dbSession, ProjectDto projectDto) { @@ -117,6 +126,11 @@ public class ComponentFinder { .orElseThrow(() -> new IllegalStateException(String.format("Can't find main branch for project '%s'", projectDto.getKey()))); } + public BranchDto getMainBranch(DbSession dbSession, ComponentDto projectDto) { + return dbClient.branchDao().selectByUuid(dbSession, projectDto.uuid()) + .orElseThrow(() -> new IllegalStateException(String.format("Can't find main branch for project '%s'", projectDto.getKey()))); + } + private static void checkByUuidOrKey(@Nullable String componentUuid, @Nullable String componentKey, ParamNames parameterNames) { checkArgument(componentUuid != null ^ componentKey != null, MSG_COMPONENT_ID_OR_KEY_TEMPLATE, parameterNames.getUuidParam(), parameterNames.getKeyParam()); } -- 2.39.5