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());
+ ComponentDto rootProjectOrBranch = getRootProjectOrBranch(component, session);
+ ComponentDto rootProject = rootProjectOrBranch.getMainBranchProjectUuid() == null ? rootProjectOrBranch
+ : componentFinder.getByUuid(session, rootProjectOrBranch.getMainBranchProjectUuid());
if (!userSession.hasComponentPermission(USER, component) &&
!userSession.hasComponentPermission(ADMIN, component) &&
!userSession.isSystemAdministrator()) {
JsonWriter json = response.newJsonWriter();
json.beginObject();
writeComponent(json, session, component, org, analysis.orElse(null));
- writeAlmDetails(json, session, component);
+ writeAlmDetails(json, session, rootProject);
writeProfiles(json, session, component);
- writeQualityGate(json, session, org, project);
+ writeQualityGate(json, session, org, rootProject);
if (userSession.hasComponentPermission(ADMIN, component) ||
userSession.hasPermission(ADMINISTER_QUALITY_PROFILES, org) ||
userSession.hasPermission(ADMINISTER_QUALITY_GATES, org)) {
}
}
+ private ComponentDto getRootProjectOrBranch(ComponentDto component, DbSession session) {
+ if (!component.isRootProject()) {
+ return dbClient.componentDao().selectOrFailByUuid(session, component.projectUuid());
+ } else {
+ return component;
+ }
+ }
+
private void writeAlmDetails(JsonWriter json, DbSession session, ComponentDto component) {
Optional<ProjectAlmBindingDto> bindingOpt = dbClient.projectAlmBindingsDao().selectByProjectUuid(session, component.uuid());
bindingOpt.ifPresent(b -> json.prop("almId", b.getAlmId())
import org.sonar.api.web.page.Page.Qualifier;
import org.sonar.api.web.page.PageDefinition;
import org.sonar.core.component.DefaultResourceTypes;
+import org.sonar.core.extension.CoreExtensionRepository;
import org.sonar.core.platform.PluginInfo;
import org.sonar.core.platform.PluginRepository;
import org.sonar.db.DbClient;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.core.extension.CoreExtensionRepository;
import org.sonar.server.organization.BillingValidations;
import org.sonar.server.organization.BillingValidationsProxy;
import org.sonar.server.qualitygate.QualityGateFinder;
}
@Test
- public void return_component_alm_info() {
+ public void return_alm_info_on_project() {
+ ComponentDto project = insertOrganizationAndProject();
+ dbClient.projectAlmBindingsDao().insertOrUpdate(db.getSession(), ALM.BITBUCKETCLOUD, "{123456789}", project.uuid(), null, "http://bitbucket.org/foo/bar");
+ db.getSession().commit();
+ userSession.addProjectPermission(UserRole.USER, project);
+ init();
+
+ executeAndVerify(project.getDbKey(), "return_alm_infos_on_project.json");
+ }
+
+ @Test
+ public void return_alm_info_on_module() {
ComponentDto project = insertOrganizationAndProject();
+ ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap"));
dbClient.projectAlmBindingsDao().insertOrUpdate(db.getSession(), ALM.BITBUCKETCLOUD, "{123456789}", project.uuid(), null, "http://bitbucket.org/foo/bar");
db.getSession().commit();
userSession.addProjectPermission(UserRole.USER, project);
init();
- executeAndVerify(project.getDbKey(), "return_component_info_with_alm.json");
+ executeAndVerify(module.getDbKey(), "return_alm_infos_on_module.json");
+ }
+
+ @Test
+ public void return_alm_info_on_branch() {
+ ComponentDto project = insertOrganizationAndProject();
+ ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz"));
+ dbClient.projectAlmBindingsDao().insertOrUpdate(db.getSession(), ALM.BITBUCKETCLOUD, "{123456789}", project.uuid(), null, "http://bitbucket.org/foo/bar");
+ db.getSession().commit();
+ userSession.addProjectPermission(UserRole.USER, project);
+ init();
+
+ verify(ws.newRequest()
+ .setParam("componentKey", project.getDbKey())
+ .setParam("branch", branch.getBranch())
+ .execute()
+ .getInput(), "return_alm_infos_on_branch.json");
}
private ComponentDto insertOrganizationAndProject() {
--- /dev/null
+{
+ "organization": "my-org",
+ "key": "polop",
+ "id": "xyz",
+ "branch": "feature1",
+ "name": "Polop",
+ "description": "test project",
+ "almId": "bitbucketcloud",
+ "almRepoUrl": "http://bitbucket.org/foo/bar"
+}
--- /dev/null
+{
+ "organization": "my-org",
+ "key": "palap",
+ "id": "bcde",
+ "name": "Palap",
+ "almId": "bitbucketcloud",
+ "almRepoUrl": "http://bitbucket.org/foo/bar"
+}
--- /dev/null
+{
+ "organization": "my-org",
+ "key": "polop",
+ "id": "abcd",
+ "name": "Polop",
+ "description": "test project",
+ "almId": "bitbucketcloud",
+ "almRepoUrl": "http://bitbucket.org/foo/bar"
+}
+++ /dev/null
-{
- "organization": "my-org",
- "key": "polop",
- "id": "abcd",
- "name": "Polop",
- "description": "test project",
- "almId": "bitbucketcloud",
- "almRepoUrl": "http://bitbucket.org/foo/bar",
- "breadcrumbs": [
- {
- "key": "polop",
- "name": "Polop",
- "qualifier": "TRK"
- }
- ]
-}