!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());
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)) {
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;
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();