From 5379d2f21d809a8ac20ce7974e8f21cfbfd37b09 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 13 Nov 2018 11:32:58 +0100 Subject: [PATCH] SONAR-11249 Fix display of quality gate on long-lived branch prj page --- .../sonar/server/ui/ws/ComponentAction.java | 3 ++- .../server/ui/ws/ComponentActionTest.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index a55d2ebcfe8..dac671c6b03 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -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 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)) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 536795e12b1..7966b9a8ae5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -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(); -- 2.39.5