]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13126 add summary of analysis to GH discussion tab
authorJacek <jacek.poreda@sonarsource.com>
Wed, 26 Feb 2020 14:06:07 +0000 (15:06 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 6 Mar 2020 20:04:32 +0000 (20:04 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java
server/sonar-db-dao/src/main/protobuf/db-project-branches.proto

index 47b90029d0c62816a98acff335b98ab4090bd1f0..1af15d840dc7d05327447b97a77a0d78bab5f021 100644 (file)
@@ -62,7 +62,7 @@ public class BranchPersisterImpl implements BranchPersister {
       .orElseThrow(() -> new IllegalStateException("Component has been deleted by end-user during analysis"));
 
     // insert or update in table project_branches
-    dbClient.branchDao().upsert(dbSession, toBranchDto(branchComponentDto, branch, checkIfExcludedFromPurge()));
+    dbClient.branchDao().upsert(dbSession, toBranchDto(dbSession, branchComponentDto, branch, checkIfExcludedFromPurge()));
   }
 
   private boolean checkIfExcludedFromPurge() {
@@ -76,12 +76,13 @@ public class BranchPersisterImpl implements BranchPersister {
       .anyMatch(excludePattern -> excludePattern.matcher(analysisMetadataHolder.getBranch().getName()).matches());
   }
 
-  protected BranchDto toBranchDto(ComponentDto componentDto, Branch branch, boolean excludeFromPurge) {
+  protected BranchDto toBranchDto(DbSession dbSession, ComponentDto componentDto, Branch branch, boolean excludeFromPurge) {
     BranchDto dto = new BranchDto();
     dto.setUuid(componentDto.uuid());
 
     // MainBranchProjectUuid will be null if it's a main branch
-    dto.setProjectUuid(firstNonNull(componentDto.getMainBranchProjectUuid(), componentDto.projectUuid()));
+    String projectUuid = firstNonNull(componentDto.getMainBranchProjectUuid(), componentDto.projectUuid());
+    dto.setProjectUuid(projectUuid);
     dto.setBranchType(branch.getType());
     dto.setExcludeFromPurge(excludeFromPurge);
 
@@ -91,9 +92,10 @@ public class BranchPersisterImpl implements BranchPersister {
     }
 
     if (branch.getType() == BranchType.PULL_REQUEST) {
-      dto.setKey(analysisMetadataHolder.getPullRequestKey());
+      String pullRequestKey = analysisMetadataHolder.getPullRequestKey();
+      dto.setKey(pullRequestKey);
 
-      DbProjectBranches.PullRequestData pullRequestData = DbProjectBranches.PullRequestData.newBuilder()
+      DbProjectBranches.PullRequestData pullRequestData = getBuilder(dbSession, projectUuid, pullRequestKey)
         .setBranch(branch.getName())
         .setTitle(branch.getName())
         .setTarget(branch.getTargetBranchName())
@@ -106,6 +108,13 @@ public class BranchPersisterImpl implements BranchPersister {
     return dto;
   }
 
+  private DbProjectBranches.PullRequestData.Builder getBuilder(DbSession dbSession, String projectUuid, String pullRequestKey) {
+    return dbClient.branchDao().selectByPullRequestKey(dbSession, projectUuid, pullRequestKey)
+      .map(BranchDto::getPullRequestData)
+      .map(DbProjectBranches.PullRequestData::toBuilder)
+      .orElse(DbProjectBranches.PullRequestData.newBuilder());
+  }
+
   private static <T> T firstNonNull(@Nullable T first, T second) {
     return (first != null) ? first : second;
   }
index f3d5fcd49f05fa8390094f83c6f179805f4abeb1..3d627bdfbf1513788f0d78db1e39b70a110afe86 100644 (file)
@@ -37,4 +37,5 @@ message PullRequestData {
   map<string, string> attributes = 4;
 
   string target = 5;
+  int64 summary_comment_id = 6;
 }