]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10252 Project page of long living branches displays the link to the correct...
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 30 Apr 2018 13:12:58 +0000 (15:12 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 1 May 2018 18:20:53 +0000 (20:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualitygate/QualityGateFinder.java
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 d1abced201ed5ee35aea4c37e633d27e3a4abc57..89b7e64783eef186711b6c28c0cea6465769653b 100644 (file)
@@ -43,7 +43,7 @@ public class QualityGateFinder {
   /**
    * Return effective quality gate of a project.
    *
-   * It will first try to get the quality gate explicitly defined on a project, if none it will try to return default quality gate ofI the organization
+   * It will first try to get the quality gate explicitly defined on a project, if none it will try to return default quality gate of the organization
    */
   public QualityGateData getQualityGate(DbSession dbSession, OrganizationDto organization, ComponentDto component) {
     Optional<Long> qualityGateId = dbClient.projectQgateAssociationDao().selectQGateIdByComponentId(dbSession, component.getId());
index 6dfb2d4a919b9aa45c92f32d80d1ebb7a4782239..76c55684e0bd2969752aae1ba950505d991a1f48 100644 (file)
@@ -106,7 +106,7 @@ public class ComponentAction implements NavigationWsAction {
 
   @Override
   public void define(NewController context) {
-    NewAction projectNavigation = context.createAction("component")
+    NewAction action = context.createAction("component")
       .setDescription("Get information concerning component navigation for the current user. " +
         "Requires the 'Browse' permission on the component's project.")
       .setHandler(this)
@@ -116,18 +116,18 @@ public class ComponentAction implements NavigationWsAction {
       .setChangelog(
         new Change("6.4", "The 'visibility' field is added"));
 
-    projectNavigation.createParam(PARAM_COMPONENT)
+    action.createParam(PARAM_COMPONENT)
       .setDescription("A component key.")
       .setDeprecatedKey("componentKey", "6.4")
       .setExampleValue(KEY_PROJECT_EXAMPLE_001);
 
-    projectNavigation
+    action
       .createParam(PARAM_BRANCH)
       .setDescription("Branch key")
       .setInternal(true)
       .setExampleValue(KEY_BRANCH_EXAMPLE_001);
 
-    projectNavigation
+    action
       .createParam(PARAM_PULL_REQUEST)
       .setDescription("Pull request id")
       .setInternal(true)
@@ -141,6 +141,7 @@ public class ComponentAction implements NavigationWsAction {
       String branch = request.param(PARAM_BRANCH);
       String pullRequest = request.param(PARAM_PULL_REQUEST);
       ComponentDto component = componentFinder.getByKeyAndOptionalBranchOrPullRequest(session, componentKey, branch, pullRequest);
+      ComponentDto project = component.getMainBranchProjectUuid() == null ? component : componentFinder.getByUuid(session, component.getMainBranchProjectUuid());
       if (!userSession.hasComponentPermission(USER, component) &&
         !userSession.hasComponentPermission(ADMIN, component) &&
         !userSession.isSystemAdministrator()) {
@@ -153,7 +154,7 @@ public class ComponentAction implements NavigationWsAction {
       json.beginObject();
       writeComponent(json, session, component, org, analysis.orElse(null));
       writeProfiles(json, session, component);
-      writeQualityGate(json, session, org, component);
+      writeQualityGate(json, session, org, project);
       if (userSession.hasComponentPermission(ADMIN, component) ||
         userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) ||
         userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) {
index 91cf01b13a809b0e9c88adcaf90d07b93c7411da..ec18a37b36d59f11b7013c2d7c59c0d97d8a3691 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.core.component.DefaultResourceTypes;
 import org.sonar.core.platform.PluginRepository;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
@@ -253,6 +254,26 @@ public class ComponentActionTest {
     executeAndVerify(project.getDbKey(), "return_quality_gate.json");
   }
 
+  @Test
+  public void quality_gate_for_a_long_living_branch() {
+    OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org"));
+    db.qualityGates().createDefaultQualityGate(organization);
+    ComponentDto project = db.components().insertPrivateProject(organization);
+    ComponentDto longLivingBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.LONG));
+    QualityGateDto qualityGateDto = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("Sonar way"));
+    db.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() {
     OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org"));
@@ -587,8 +608,8 @@ public class ComponentActionTest {
     return ws.newRequest().setParam("componentKey", componentKey).execute().getInput();
   }
 
-  private void verify(String json, String expectedJson) {
-    assertJson(json).isSimilarTo(getClass().getResource(ComponentActionTest.class.getSimpleName() + "/" + expectedJson));
+  private void verify(String json, String jsonFile) {
+    assertJson(json).isSimilarTo(getClass().getResource(ComponentActionTest.class.getSimpleName() + "/" + jsonFile));
   }
 
   private void executeAndVerify(String componentKey, String expectedJson) {