aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-02-28 13:12:24 +0100
committersonartech <sonartech@sonarsource.com>2020-03-06 20:04:32 +0000
commita91ea17d6efbbd6bd8e17a98c248000d0dd70c17 (patch)
tree303dc362d63515d0b27a67467f9384f610b7c3b5 /server/sonar-db-dao
parent1c5db0e2fe3c69ecc21253f9378790ecea382567 (diff)
downloadsonarqube-a91ea17d6efbbd6bd8e17a98c248000d0dd70c17.tar.gz
sonarqube-a91ea17d6efbbd6bd8e17a98c248000d0dd70c17.zip
SONAR-13139 Add 'summaryCommentEnable' property to allow enable/disable of showing summary of analysis in discussion tab for GitHub
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.java15
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml42
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java30
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java3
5 files changed, 78 insertions, 15 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.java
index 622416fdaf4..519c2ea6d4d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDto.java
@@ -56,6 +56,12 @@ public class ProjectAlmSettingDto {
*/
private String almSlug;
+ /**
+ * Boolean flag which enable/disable inserting summary of analysis as a comment
+ * It will be null when the ALM is other than GitHub
+ */
+ private Boolean summaryCommentEnabled;
+
private long updatedAt;
private long createdAt;
@@ -105,6 +111,15 @@ public class ProjectAlmSettingDto {
return this;
}
+ public Boolean getSummaryCommentEnabled() {
+ return summaryCommentEnabled;
+ }
+
+ public ProjectAlmSettingDto setSummaryCommentEnabled(@Nullable Boolean summaryCommentEnabled) {
+ this.summaryCommentEnabled = summaryCommentEnabled;
+ return this;
+ }
+
long getUpdatedAt() {
return updatedAt;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
index 7b6a7f86262..283d8f15757 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/ProjectAlmSettingMapper.xml
@@ -9,6 +9,7 @@
p.alm_setting_uuid as almSettingUuid,
p.alm_repo as almRepo,
p.alm_slug as almSlug,
+ p.summary_comment_enabled as summaryCommentEnabled,
p.created_at as createdAt,
p.updated_at as updatedAt
</sql>
@@ -41,6 +42,7 @@
alm_setting_uuid,
alm_repo,
alm_slug,
+ summary_comment_enabled,
created_at,
updated_at
)
@@ -50,6 +52,32 @@
#{dto.almSettingUuid, jdbcType=VARCHAR},
#{dto.almRepo, jdbcType=VARCHAR},
#{dto.almSlug, jdbcType=VARCHAR},
+ #{dto.summaryCommentEnabled, jdbcType=BOOLEAN},
+ #{now, jdbcType=BIGINT},
+ #{now, jdbcType=BIGINT}
+ )
+ </insert>
+
+ <!-- Oracle -->
+ <insert id="insert" parameterType="Map" useGeneratedKeys="false" databaseId="oracle">
+ INSERT INTO project_alm_settings
+ (
+ uuid,
+ project_uuid,
+ alm_setting_uuid,
+ alm_repo,
+ alm_slug,
+ summary_comment_enabled,
+ created_at,
+ updated_at
+ )
+ VALUES (
+ #{uuid, jdbcType=VARCHAR},
+ #{dto.projectUuid, jdbcType=VARCHAR},
+ #{dto.almSettingUuid, jdbcType=VARCHAR},
+ #{dto.almRepo, jdbcType=VARCHAR},
+ #{dto.almSlug, jdbcType=VARCHAR},
+ #{dto.summaryCommentEnabled, jdbcType=NUMERIC},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
@@ -61,6 +89,20 @@
alm_setting_uuid = #{dto.almSettingUuid, jdbcType=VARCHAR},
alm_repo = #{dto.almRepo, jdbcType=VARCHAR},
alm_slug = #{dto.almSlug, jdbcType=VARCHAR},
+ summary_comment_enabled = #{dto.summaryCommentEnabled, jdbcType=BOOLEAN},
+ updated_at = #{now, jdbcType=BIGINT}
+ WHERE
+ project_uuid = #{dto.projectUuid, jdbcType=VARCHAR}
+ </update>
+
+ <!-- Oracle -->
+ <update id="update" parameterType="map" databaseId="oracle">
+ UPDATE project_alm_settings
+ SET
+ alm_setting_uuid = #{dto.almSettingUuid, jdbcType=VARCHAR},
+ alm_repo = #{dto.almRepo, jdbcType=VARCHAR},
+ alm_slug = #{dto.almSlug, jdbcType=VARCHAR},
+ summary_comment_enabled = #{dto.summaryCommentEnabled, jdbcType=NUMERIC},
updated_at = #{now, jdbcType=BIGINT}
WHERE
project_uuid = #{dto.projectUuid, jdbcType=VARCHAR}
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 17a3cd04dc3..2589b2325b3 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -631,7 +631,8 @@ CREATE TABLE "PROJECT_ALM_SETTINGS"(
"ALM_REPO" VARCHAR(256),
"ALM_SLUG" VARCHAR(256),
"UPDATED_AT" BIGINT NOT NULL,
- "CREATED_AT" BIGINT NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "SUMMARY_COMMENT_ENABLED" BOOLEAN
);
ALTER TABLE "PROJECT_ALM_SETTINGS" ADD CONSTRAINT "PK_PROJECT_ALM_SETTINGS" PRIMARY KEY("UUID");
CREATE UNIQUE INDEX "UNIQ_PROJECT_ALM_SETTINGS" ON "PROJECT_ALM_SETTINGS"("PROJECT_UUID");
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
index cdbfa161c5d..9a81c0d9b56 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
@@ -31,6 +31,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.almsettings.AlmSettingsTesting.newBitbucketProjectAlmSettingDto;
@@ -65,10 +66,11 @@ public class ProjectAlmSettingDaoTest {
assertThat(underTest.selectByProject(dbSession, project).get())
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug,
- ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt)
+ ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt,
+ ProjectAlmSettingDto::getSummaryCommentEnabled)
.containsExactly(A_UUID, githubAlmSettingDto.getUuid(), project.getUuid(),
githubProjectAlmSettingDto.getAlmRepo(), githubProjectAlmSettingDto.getAlmSlug(),
- A_DATE, A_DATE);
+ A_DATE, A_DATE, githubProjectAlmSettingDto.getSummaryCommentEnabled());
assertThat(underTest.selectByProject(dbSession, anotherProject)).isNotPresent();
}
@@ -79,19 +81,19 @@ public class ProjectAlmSettingDaoTest {
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting();
ProjectDto project = db.components().insertPrivateProjectDto();
- ProjectAlmSettingDto githubProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
- githubProjectAlmSettingDto.setAlmSlug("slug1");
- underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
- ProjectAlmSettingDto githubProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
- githubProjectAlmSettingDto2.setAlmSlug("slug2");
+ ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project);
+ bitbucketProjectAlmSettingDto.setAlmSlug("slug1");
+ underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto);
+ ProjectAlmSettingDto bitbucketProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto());
+ bitbucketProjectAlmSettingDto2.setAlmSlug("slug2");
when(uuidFactory.create()).thenReturn(A_UUID + 1);
- underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2);
+ underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2);
Set<String> slugs = new HashSet<>();
slugs.add("slug1");
assertThat(underTest.selectByAlmSettingAndSlugs(dbSession, almSettingsDto, slugs))
- .extracting(ProjectAlmSettingDto::getProjectUuid)
- .containsExactly(project.getUuid());
+ .extracting(ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getSummaryCommentEnabled)
+ .containsExactly(tuple(project.getUuid(), bitbucketProjectAlmSettingDto2.getSummaryCommentEnabled()));
}
@Test
@@ -113,16 +115,18 @@ public class ProjectAlmSettingDaoTest {
AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting();
when(system2.now()).thenReturn(A_DATE_LATER);
- ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project);
+ ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project)
+ .setSummaryCommentEnabled(false);
underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto);
assertThat(underTest.selectByProject(dbSession, project).get())
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug,
- ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt)
+ ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt,
+ ProjectAlmSettingDto::getSummaryCommentEnabled)
.containsExactly(projectAlmSettingDto.getUuid(), anotherGithubAlmSetting.getUuid(), project.getUuid(),
newProjectAlmSettingDto.getAlmRepo(), newProjectAlmSettingDto.getAlmSlug(),
- A_DATE, A_DATE_LATER);
+ A_DATE, A_DATE_LATER, newProjectAlmSettingDto.getSummaryCommentEnabled());
}
@Test
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java
index 54a56f82afe..76b3c3cb0c1 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java
@@ -64,7 +64,8 @@ public class AlmSettingsTesting {
return new ProjectAlmSettingDto()
.setAlmSettingUuid(githubAlmSetting.getUuid())
.setProjectUuid(project.getUuid())
- .setAlmRepo(randomAlphanumeric(256));
+ .setAlmRepo(randomAlphanumeric(256))
+ .setSummaryCommentEnabled(true);
}
static ProjectAlmSettingDto newGitlabProjectAlmSettingDto(AlmSettingDto gitlabAlmSetting, ProjectDto project) {