return getMapper(dbSession).bindingCount(alm.getId(), repoId) == 1;
}
+ public Optional<ProjectAlmBindingDto> selectByProjectUuid(DbSession session, String projectUuid) {
+ return Optional.ofNullable(getMapper(session).selectByProjectUuid(projectUuid));
+ }
+
/**
* Gets a list of bindings by their repo_id. The result does NOT contain {@code null} values for bindings not found, so
* the size of result may be less than the number of ids.
private static ProjectAlmBindingsMapper getMapper(DbSession dbSession) {
return dbSession.getMapper(ProjectAlmBindingsMapper.class);
}
+
}
List<ProjectAlmBindingDto> selectByRepoIds(@Param("almId") String almId, @Param("repoIds") List<String> repoIds);
ProjectAlmBindingDto selectByRepoId(@Param("almId") String almId, @Param("repoId") String repoId);
+
+ ProjectAlmBindingDto selectByProjectUuid(@Param("projectUuid") String projectUuid);
}
and repo_id = #{repoId, jdbcType=VARCHAR}
</select>
+ <select id="selectByProjectUuid" parameterType="map" resultType="ProjectAlmBinding">
+ select
+ uuid,
+ alm_id as almId,
+ repo_id as repoId,
+ project_uuid as projectUuid,
+ github_slug as githubSlug,
+ url
+ from project_alm_bindings
+ where
+ project_uuid = #{projectUuid, jdbcType=VARCHAR}
+ </select>
+
</mapper>
assertThat(dto.get().getGithubSlug()).isEqualTo(A_GITHUB_SLUG);
}
+ @Test
+ public void select_by_project_uuid() {
+ when(system2.now()).thenReturn(DATE);
+ when(uuidFactory.create())
+ .thenReturn("uuid1")
+ .thenReturn("uuid2")
+ .thenReturn("uuid3");
+ underTest.insertOrUpdate(dbSession, GITHUB, A_REPO, A_UUID, A_GITHUB_SLUG, A_URL);
+ underTest.insertOrUpdate(dbSession, GITHUB, ANOTHER_REPO, ANOTHER_UUID, null, ANOTHER_URL);
+ underTest.insertOrUpdate(dbSession, BITBUCKETCLOUD, ANOTHER_REPO, "foo", null, "http://foo");
+
+ assertThat(underTest.selectByProjectUuid(dbSession, "missing")).isNotPresent();
+
+ Optional<ProjectAlmBindingDto> dto = underTest.selectByProjectUuid(dbSession, A_UUID);
+ assertThat(dto).isPresent();
+ assertThat(dto.get().getUuid()).isEqualTo("uuid1");
+ assertThat(dto.get().getAlmId()).isEqualTo(GITHUB.getId());
+ assertThat(dto.get().getRepoId()).isEqualTo(A_REPO);
+ assertThat(dto.get().getProjectUuid()).isEqualTo(A_UUID);
+ assertThat(dto.get().getUrl()).isEqualTo(A_URL);
+ assertThat(dto.get().getGithubSlug()).isEqualTo(A_GITHUB_SLUG);
+ }
+
@Test
public void select_by_repo_ids() {
when(system2.now()).thenReturn(DATE);
import org.sonar.api.web.page.Page;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.alm.ProjectAlmBindingDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
.setResponseExample(getClass().getResource("component-example.json"))
.setSince("5.2")
.setChangelog(
- new Change("6.4", "The 'visibility' field is added"));
+ new Change("6.4", "The 'visibility' field is added"),
+ new Change("7.3", "The 'almRepoUrl' and 'almId' fields are added"));
action.createParam(PARAM_COMPONENT)
.setDescription("A component key.")
JsonWriter json = response.newJsonWriter();
json.beginObject();
writeComponent(json, session, component, org, analysis.orElse(null));
+ writeAlmDetails(json, session, component);
writeProfiles(json, session, component);
writeQualityGate(json, session, org, project);
if (userSession.hasComponentPermission(ADMIN, 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())
+ .prop("almRepoUrl", b.getUrl()));
+ }
+
private static Consumer<QualityProfile> writeToJson(JsonWriter json) {
return profile -> json.beginObject()
.prop("key", profile.getQpKey())
import org.sonar.core.platform.PluginRepository;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.alm.ALM;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
assertThat(action.description()).isNotNull();
assertThat(action.responseExample()).isNotNull();
assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder(
- tuple("6.4", "The 'visibility' field is added"));
+ tuple("6.4", "The 'visibility' field is added"),
+ tuple("7.3", "The 'almRepoUrl' and 'almId' fields are added"));
WebService.Param componentId = action.param(PARAM_COMPONENT);
assertThat(componentId.isRequired()).isFalse();
assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4");
}
+ @Test
+ public void return_component_alm_info() {
+ 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_component_info_with_alm.json");
+ }
+
private ComponentDto insertOrganizationAndProject() {
OrganizationDto organization = db.organizations().insert(o -> o.setKey("my-org"));
db.qualityGates().createDefaultQualityGate(organization);
--- /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"
+ }
+ ]
+}