/**
* 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());
@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)
.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)
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()) {
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)) {
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;
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"));
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) {