setNullable(component.getBranch(), issueBuilder::setBranch);
ComponentDto project = data.getComponentByUuid(dto.getProjectUuid());
if (project != null) {
- issueBuilder.setProject(project.getDbKey());
+ issueBuilder.setProject(project.getKey());
ComponentDto subProject = data.getComponentByUuid(dto.getModuleUuid());
if (subProject != null && !subProject.getDbKey().equals(project.getDbKey())) {
- issueBuilder.setSubProject(subProject.getDbKey());
+ issueBuilder.setSubProject(subProject.getKey());
}
}
issueBuilder.setRule(dto.getRuleKey().toString());
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES;
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
+import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
public class ComponentAction implements NavigationWsAction {
static final String PARAM_COMPONENT = "component";
+ static final String PARAM_BRANCH = "branch";
private static final String PROPERTY_CONFIGURABLE = "configurable";
private static final String PROPERTY_HAS_ROLE_POLICY = "hasRolePolicy";
.setDescription("A component key.")
.setDeprecatedKey("componentKey", "6.4")
.setExampleValue(KEY_PROJECT_EXAMPLE_001);
+
+ projectNavigation
+ .createParam(PARAM_BRANCH)
+ .setDescription("Branch key")
+ .setInternal(true)
+ .setExampleValue(KEY_BRANCH_EXAMPLE_001);
}
@Override
public void handle(Request request, Response response) throws Exception {
String componentKey = request.mandatoryParam(PARAM_COMPONENT);
try (DbSession session = dbClient.openSession(false)) {
- ComponentDto component = componentFinder.getByKey(session, componentKey);
+ String branch = request.param(PARAM_BRANCH);
+ ComponentDto component = componentFinder.getByKeyAndOptionalBranch(session, componentKey, branch);
if (!userSession.hasComponentPermission(USER, component) &&
!userSession.hasComponentPermission(ADMIN, component) &&
!userSession.isSystemAdministrator()) {
for (ComponentDto c : breadcrumb) {
json.beginObject()
- .prop("key", c.getDbKey())
+ .prop("key", c.getKey())
.prop("name", c.name())
.prop("qualifier", c.qualifier())
.endObject();
executeAndVerify(project.getDbKey(), "return_component_info_when_snapshot.json");
}
+ @Test
+ public void return_component_info_when_file_on_master() throws Exception {
+ init();
+ OrganizationDto organization = dbTester.organizations().insertForKey("my-org2");
+ ComponentDto main = componentDbTester.insertMainBranch(organization, p -> p.setName("Sample"), p -> p.setDbKey("sample"));
+ userSession.addProjectPermission(UserRole.USER, main);
+
+ ComponentDto dirDto = componentDbTester.insertComponent(newDirectory(main, "src"));
+
+ ComponentDto fileDto = componentDbTester.insertComponent(newFileDto(main, dirDto)
+ .setUuid("abcd")
+ .setName("Main.xoo")
+ .setDbKey("sample:src/Main.xoo"));
+
+ executeAndVerify(fileDto.getDbKey(), "return_component_info_when_file_on_master.json");
+ }
+
+ @Test
+ public void return_component_info_when_file_on_branch() throws Exception {
+ init();
+ OrganizationDto organization = dbTester.organizations().insertForKey("my-org2");
+ ComponentDto project = componentDbTester.insertMainBranch(organization, p -> p.setName("Sample"), p -> p.setDbKey("sample"));
+ ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1"));
+ userSession.addProjectPermission(UserRole.USER, project);
+
+ ComponentDto dirDto = componentDbTester.insertComponent(newDirectory(branch, "src"));
+
+ ComponentDto fileDto = componentDbTester.insertComponent(newFileDto(branch, dirDto)
+ .setUuid("abcd")
+ .setName("Main.xoo")
+ .setDbKey("sample:src/Main.xoo"));
+
+ String json = ws.newRequest()
+ .setParam("componentKey", fileDto.getDbKey())
+ .setParam("branch", branch.getBranch())
+ .execute()
+ .getInput();
+ verify(json, "return_component_info_when_file_on_branch.json");
+ }
+
@Test
public void return_quality_profiles() throws Exception {
init();
--- /dev/null
+{
+ "key": "sample:src/Main.xoo",
+ "organization": "my-org2",
+ "id": "abcd",
+ "name": "Main.xoo",
+ "isFavorite": false,
+ "extensions": [],
+ "qualityProfiles": [],
+ "breadcrumbs": [
+ {
+ "key": "sample",
+ "name": "Sample",
+ "qualifier": "TRK"
+ },
+ {
+ "key": "sample:src",
+ "name": "src",
+ "qualifier": "DIR"
+ },
+ {
+ "key": "sample:src/Main.xoo",
+ "name": "Main.xoo",
+ "qualifier": "FIL"
+ }
+ ]
+}
--- /dev/null
+{
+ "key": "sample:src/Main.xoo",
+ "organization": "my-org2",
+ "id": "abcd",
+ "name": "Main.xoo",
+ "isFavorite": false,
+ "extensions": [],
+ "qualityProfiles": [],
+ "breadcrumbs": [
+ {
+ "key": "sample",
+ "name": "Sample",
+ "qualifier": "TRK"
+ },
+ {
+ "key": "sample:src",
+ "name": "src",
+ "qualifier": "DIR"
+ },
+ {
+ "key": "sample:src/Main.xoo",
+ "name": "Main.xoo",
+ "qualifier": "FIL"
+ }
+ ]
+}