From f2911115af4199eb23e1a8529585c50a3ff37041 Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 26 Feb 2020 15:06:07 +0100 Subject: [PATCH] SONAR-13126 add summary of analysis to GH discussion tab --- .../component/BranchPersisterImpl.java | 19 ++++++++++++++----- .../main/protobuf/db-project-branches.proto | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java index 47b90029d0c..1af15d840dc 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java @@ -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 firstNonNull(@Nullable T first, T second) { return (first != null) ? first : second; } diff --git a/server/sonar-db-dao/src/main/protobuf/db-project-branches.proto b/server/sonar-db-dao/src/main/protobuf/db-project-branches.proto index f3d5fcd49f0..3d627bdfbf1 100644 --- a/server/sonar-db-dao/src/main/protobuf/db-project-branches.proto +++ b/server/sonar-db-dao/src/main/protobuf/db-project-branches.proto @@ -37,4 +37,5 @@ message PullRequestData { map attributes = 4; string target = 5; + int64 summary_comment_id = 6; } -- 2.39.5