]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15138 - Download Report Action
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Fri, 30 Jul 2021 07:17:47 +0000 (09:17 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 9 Aug 2021 20:03:18 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentFinder.java

index b765298133448c2783847fae8489b3bbc456867a..8bcdb08f73a29eda042d1bcf91c93b80490d558e 100644 (file)
@@ -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());
   }