]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11729 implemented PrDecorator for Bitbucket Server
authorMichal Duda <michal.duda@sonarsource.com>
Mon, 18 Feb 2019 16:52:18 +0000 (17:52 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 18 Mar 2019 19:20:58 +0000 (20:20 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListener.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImpl.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/changeevent/QGChangeEventListenersImplTest.java
sonar-core/src/main/resources/org/sonar/l10n/core.properties
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java

index 7af703f9a8b6308dd603edfba4254862f462e4a2..a2d55a04a4a0953560d37c9e32ef3a3ce994a22d 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.qualitygate.changeevent;
 
+import java.util.EnumSet;
 import java.util.Set;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.server.ServerSide;
@@ -34,11 +35,18 @@ public interface QGChangeEventListener {
   void onIssueChanges(QGChangeEvent qualityGateEvent, Set<ChangedIssue> changedIssues);
 
   interface ChangedIssue {
+
     String getKey();
 
     Status getStatus();
 
     RuleType getType();
+
+    String getSeverity();
+
+    default boolean isNotClosed() {
+      return !Status.CLOSED_STATUSES.contains(getStatus());
+    }
   }
 
   enum Status {
@@ -47,7 +55,9 @@ public interface QGChangeEventListener {
     REOPENED,
     RESOLVED_FP,
     RESOLVED_WF,
-    RESOLVED_FIXED
+    RESOLVED_FIXED;
+
+    protected static final Set<Status> CLOSED_STATUSES = EnumSet.of(CONFIRMED, RESOLVED_FIXED, RESOLVED_FP, RESOLVED_WF);
   }
 
 }
index d8241a54e69d45b7d34aa6c945c2859f01951935..bb8bea4b7ed56061000065bfed95f62f9f1b4165 100644 (file)
@@ -101,11 +101,13 @@ public class QGChangeEventListenersImpl implements QGChangeEventListeners {
     private final String key;
     private final QGChangeEventListener.Status status;
     private final RuleType type;
+    private final String severity;
 
-    private ChangedIssueImpl(DefaultIssue issue) {
+    ChangedIssueImpl(DefaultIssue issue) {
       this.key = issue.key();
       this.status = statusOf(issue);
       this.type = issue.type();
+      this.severity = issue.severity();
     }
 
     static QGChangeEventListener.Status statusOf(DefaultIssue issue) {
@@ -153,12 +155,18 @@ public class QGChangeEventListenersImpl implements QGChangeEventListeners {
       return type;
     }
 
+    @Override
+    public String getSeverity() {
+      return severity;
+    }
+
     @Override
     public String toString() {
       return "ChangedIssueImpl{" +
         "key='" + key + '\'' +
         ", status=" + status +
         ", type=" + type +
+        ", severity=" + severity +
         '}';
     }
   }
index d990508381940a612d8cd401dbea43c8f8538d72..73ca7f593f904a4a599c1defef4863408282a511 100644 (file)
@@ -227,6 +227,32 @@ public class QGChangeEventListenersImplTest {
     verifyNoMoreInteractions(listener1, listener2, listener3);
   }
 
+  @Test
+  public void isNotClosed_returns_true_if_issue_in_one_of_opened_states() {
+    DefaultIssue defaultIssue = new DefaultIssue();
+    defaultIssue.setStatus(Issue.STATUS_REOPENED);
+    defaultIssue.setKey("abc");
+    defaultIssue.setType(RuleType.BUG);
+    defaultIssue.setSeverity("BLOCKER");
+
+    ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+    assertThat(changedIssue.isNotClosed()).isTrue();
+  }
+
+  @Test
+  public void isNotClosed_returns_false_if_issue_in_one_of_closed_states() {
+    DefaultIssue defaultIssue = new DefaultIssue();
+    defaultIssue.setStatus(Issue.STATUS_CONFIRMED);
+    defaultIssue.setKey("abc");
+    defaultIssue.setType(RuleType.BUG);
+    defaultIssue.setSeverity("BLOCKER");
+
+    ChangedIssue changedIssue = new ChangedIssueImpl(defaultIssue);
+
+    assertThat(changedIssue.isNotClosed()).isFalse();
+  }
+
   @Test
   public void test_status_mapping() {
     assertThat(ChangedIssueImpl.statusOf(new DefaultIssue().setStatus(Issue.STATUS_OPEN))).isEqualTo(QGChangeEventListener.Status.OPEN);
@@ -267,7 +293,7 @@ public class QGChangeEventListenersImplTest {
       .toArray(Tuple[]::new);
     assertThat(changedIssues)
       .hasSize(issues.length)
-      .extracting(ChangedIssue::getKey, t -> t.getStatus(), ChangedIssue::getType)
+      .extracting(ChangedIssue::getKey, ChangedIssue::getStatus, ChangedIssue::getType)
       .containsOnly(expected);
   }
 
index fcf8332f2287423e39af57dde8558a368121107d..6759d6c8aff0977d2423374dd2102ffb66868805 100644 (file)
@@ -1808,7 +1808,7 @@ metric.new_duplicated_lines.name=Duplicated Lines on New Code
 metric.new_duplicated_lines.extra_short_name=Duplicated Lines
 metric.new_duplicated_lines.description=Duplicated Lines on New Code
 metric.new_duplicated_lines_density.description=Duplicated lines on new code balanced by statements
-metric.new_duplicated_lines_density.name=Duplicated Lines on New Code (%)
+metric.new_duplicated_lines_density.name=Duplicated Lines on New Code
 metric.new_duplicated_lines_density.short_name=Duplications
 metric.new_duplicated_lines_density.extra_short_name=Density
 metric.new_info_violations.description=New Info issues
index a8d6b9c34f6fdc4805bf2b2fd62b613858bbe554..0d6349bc8f89d5831e0c58674027fb6ead1c86c4 100644 (file)
@@ -751,7 +751,7 @@ public final class CoreMetrics {
   /**
    * @since 6.1
    */
-  public static final Metric<Integer> NEW_DUPLICATED_LINES_DENSITY = new Metric.Builder(NEW_DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines on New Code (%)",
+  public static final Metric<Integer> NEW_DUPLICATED_LINES_DENSITY = new Metric.Builder(NEW_DUPLICATED_LINES_DENSITY_KEY, "Duplicated Lines on New Code",
     Metric.ValueType.PERCENT)
     .setDescription("Duplicated lines on new code balanced by statements")
     .setDirection(Metric.DIRECTION_WORST)