]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11249 Fix display of quality gate on long-lived branch prj page 3185/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 13 Nov 2018 10:32:58 +0000 (11:32 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 15 Nov 2018 09:48:33 +0000 (10:48 +0100)
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java

index a55d2ebcfe89ebe952f0d2bfcb7098c6838d3195..dac671c6b031fc8984598415c3fd2db7002f5a1a 100644 (file)
@@ -140,6 +140,7 @@ public class ComponentAction implements NavigationWsAction {
         !userSession.isSystemAdministrator()) {
         throw insufficientPrivilegesException();
       }
+      ComponentDto project = component.getMainBranchProjectUuid() == null ? component : componentFinder.getByUuid(session, component.getMainBranchProjectUuid());
       OrganizationDto org = componentFinder.getOrganization(session, component);
       Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.projectUuid());
 
@@ -147,7 +148,7 @@ public class ComponentAction implements NavigationWsAction {
       json.beginObject();
       writeComponent(json, session, component, org, analysis.orElse(null));
       writeProfiles(json, session, component);
-      writeQualityGate(json, session, component);
+      writeQualityGate(json, session, project);
       if (userSession.hasComponentPermission(ADMIN, component) ||
         userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) ||
         userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) {
index 536795e12b1273365fb54b1831ab34cd01a95e93..7966b9a8ae53533a699d255a0882dc64de759076 100644 (file)
@@ -71,6 +71,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
 import static org.sonar.api.web.page.Page.Scope.COMPONENT;
+import static org.sonar.db.component.BranchType.LONG;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
@@ -291,6 +292,25 @@ public class ComponentActionTest {
     executeAndVerify(project.getDbKey(), "return_quality_gate.json");
   }
 
+  @Test
+  public void quality_gate_for_a_long_living_branch() {
+    dbTester.qualityGates().createDefaultQualityGate("Default");
+    ComponentDto project = dbTester.components().insertPrivateProject();
+    ComponentDto longLivingBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(LONG));
+    QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way");
+    dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
+    userSession.addProjectPermission(UserRole.USER, project);
+    init();
+
+    String json = ws.newRequest()
+      .setParam("componentKey", longLivingBranch.getKey())
+      .setParam("branch", longLivingBranch.getBranch())
+      .execute()
+      .getInput();
+
+    verify(json, "return_quality_gate.json");
+  }
+
   @Test
   public void return_default_quality_gate() throws Exception {
     init();