]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11605 No changed lines detected in P/R and SLB if target branch is not explicit...
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 9 Jan 2019 13:16:56 +0000 (14:16 +0100)
committerSonarTech <sonartech@sonarsource.com>
Wed, 9 Jan 2019 19:21:08 +0000 (20:21 +0100)
server/sonar-server/src/main/resources/org/sonar/server/branch/ws/list-example.json
server/sonar-server/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java

index 5fa613fe94df55b938eaed7529ab4d2b1a974681..2e95cea4b2e263625cdfe8acc7f99d6b460f3134 100644 (file)
@@ -1,19 +1,10 @@
 {
   "branches": [
-    {
-      "name": "feature/bar",
-      "isMain": false,
-      "type": "LONG",
-      "status": {
-        "qualityGateStatus": "OK"
-      },
-      "analysisDate": "2017-04-01T01:15:42+0100"
-    },
     {
       "name": "feature/foo",
       "isMain": false,
       "type": "SHORT",
-      "mergeBranch": "feature/bar",
+      "mergeBranch": "master",
       "status": {
         "qualityGateStatus": "OK",
         "bugs": 1,
         "codeSmells": 0
       },
       "analysisDate": "2017-04-03T13:37:00+0100"
+    },
+    {
+      "name": "master",
+      "isMain": true,
+      "type": "LONG",
+      "status": {
+        "qualityGateStatus": "ERROR"
+      },
+      "analysisDate": "2017-04-01T01:15:42+0100"
     }
   ]
 }
index b40e2548b534627a1b28657addb8397d6e9b394f..091cb5079e44a7fb3860f1211530a45bdd116b8b 100644 (file)
@@ -107,16 +107,13 @@ public class ListActionTest {
 
   @Test
   public void test_example() {
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube"));
-
-    ComponentDto longLivingBranch = db.components()
-      .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG));
+    ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube"));
     db.getDbClient().snapshotDao().insert(db.getSession(),
-      newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
-    db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK"));
+      newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+    db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
 
     ComponentDto shortLivingBranch = db.components()
-      .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid()));
+      .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid()));
     db.getDbClient().snapshotDao().insert(db.getSession(),
       newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
     db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK"));
@@ -139,16 +136,13 @@ public class ListActionTest {
 
   @Test
   public void test_with_SCAN_EXCUTION_permission() {
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube"));
-
-    ComponentDto longLivingBranch = db.components()
-      .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG));
+    ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube"));
     db.getDbClient().snapshotDao().insert(db.getSession(),
-      newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
-    db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK"));
+      newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+    db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
 
     ComponentDto shortLivingBranch = db.components()
-      .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid()));
+      .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid()));
     db.getDbClient().snapshotDao().insert(db.getSession(),
       newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
     db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK"));
index f04cbf78ab03a331a5a32f3e79088bd09f4b6601..4b9d463a164b52ab4bbaa360071247ed0670892c 100644 (file)
@@ -73,7 +73,6 @@ public class ChangedLinesPublisher implements ReportPublisherStep {
   }
 
   private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) {
-
     Path rootBaseDir = inputModuleHierarchy.root().getBaseDir();
     Map<Path, DefaultInputFile> changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false)
       .collect(Collectors.toMap(DefaultInputFile::path, f -> f));
index 05aa97c274fb05162148069c998b6f925ed87a74..4398c3dc3a86609428b55fa5943873dee3938b31 100644 (file)
@@ -23,7 +23,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 
 /**
@@ -31,10 +30,7 @@ import javax.annotation.concurrent.Immutable;
  */
 @Immutable
 public class ProjectBranches {
-
   private final Map<String, BranchInfo> branches;
-
-  @Nullable
   private final String defaultBranchName;
 
   public ProjectBranches(List<BranchInfo> branchInfos) {
@@ -59,7 +55,6 @@ public class ProjectBranches {
     return branches.isEmpty();
   }
 
-  @CheckForNull
   public String defaultBranchName() {
     return defaultBranchName;
   }
index 9c3feab2c22eca404529913bfac95a97def7257e..93132a99b6551aa2ddab9cab24039422a7a6d8d6 100644 (file)
@@ -32,16 +32,11 @@ import javax.annotation.concurrent.Immutable;
  */
 @Immutable
 public class ProjectPullRequests {
-
+  private static final BinaryOperator<PullRequestInfo> PICK_MOST_RECENT_ANALYSIS = (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a;
   private final Map<String, PullRequestInfo> pullRequestsByBranchName;
 
   public ProjectPullRequests(List<PullRequestInfo> pullRequestInfos) {
-    BinaryOperator<PullRequestInfo> mergeFunction = pickMostRecentAnalysis();
-    this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), mergeFunction));
-  }
-
-  private static BinaryOperator<PullRequestInfo> pickMostRecentAnalysis() {
-    return (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a;
+    this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), PICK_MOST_RECENT_ANALYSIS));
   }
 
   @CheckForNull