aboutsummaryrefslogtreecommitdiffstats
path: root/server
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
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')
-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
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettings.java50
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java32
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHub.java52
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/package-info.java23
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest.java68
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java42
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java140
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest/schema.sql13
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest/schema.sql28
16 files changed, 529 insertions, 16 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) {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
index 1d3754e6f39..a7d9d6ed89a 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
@@ -28,6 +28,7 @@ import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
import org.sonar.server.platform.db.migration.version.v80.DbVersion80;
import org.sonar.server.platform.db.migration.version.v81.DbVersion81;
import org.sonar.server.platform.db.migration.version.v82.DbVersion82;
+import org.sonar.server.platform.db.migration.version.v83.DbVersion83;
public class MigrationConfigurationModule extends Module {
@Override
@@ -38,6 +39,7 @@ public class MigrationConfigurationModule extends Module {
DbVersion80.class,
DbVersion81.class,
DbVersion82.class,
+ DbVersion83.class,
// migration steps
MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettings.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettings.java
new file mode 100644
index 00000000000..1d51c95478b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettings.java
@@ -0,0 +1,50 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class AddSummaryEnabledColumnToAlmSettings extends DdlChange {
+ private static final String TABLE = "project_alm_settings";
+ private static final String NEW_COLUMN = "summary_comment_enabled";
+
+ private static final BooleanColumnDef SUMMARY_COMMENT_ENABLED = newBooleanColumnDefBuilder()
+ .setColumnName(NEW_COLUMN)
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .build();
+
+ public AddSummaryEnabledColumnToAlmSettings(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(SUMMARY_COMMENT_ENABLED)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
new file mode 100644
index 00000000000..63845bbbd6b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java
@@ -0,0 +1,32 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+public class DbVersion83 implements DbVersion {
+ @Override
+ public void addSteps(MigrationStepRegistry registry) {
+ registry
+ .add(3300, "Add 'summary_comment_enabled' boolean column to 'project_alm_settings'", AddSummaryEnabledColumnToAlmSettings.class)
+ .add(3301, "Enable 'summary_comment_enabled' for GitHub based projects", PopulateSummaryCommentEnabledColumnForGitHub.class);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHub.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHub.java
new file mode 100644
index 00000000000..4d077e013bd
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHub.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateSummaryCommentEnabledColumnForGitHub extends DataChange {
+
+ private final System2 system;
+
+ public PopulateSummaryCommentEnabledColumnForGitHub(Database db, System2 system) {
+ super(db);
+ this.system = system;
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select uuid from alm_settings where alm_id = ? ")
+ .setString(1, "github");
+ massUpdate.update("update project_alm_settings set summary_comment_enabled = ?, updated_at = ? where alm_setting_uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setBoolean(1, true)
+ .setLong(2, system.now())
+ .setString(3, row.getString(1));
+ return true;
+ });
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/package-info.java
new file mode 100644
index 00000000000..a671d6ae95d
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v83;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java
index 17f0012f50f..102d9c808bc 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java
@@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest {
assertThat(container.getPicoContainer().getComponentAdapters())
.hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER
// DbVersion classes
- + 4
+ + 5
// Others
+ 4);
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest.java
new file mode 100644
index 00000000000..a6e7bf232cc
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest.java
@@ -0,0 +1,68 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import java.sql.SQLException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static java.sql.Types.BOOLEAN;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddSummaryEnabledColumnToAlmSettingsTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddSummaryEnabledColumnToAlmSettingsTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddSummaryEnabledColumnToAlmSettings(db.database());
+
+ @Before
+ public void setup() {
+ insertProjectAlmSetting("1");
+ insertProjectAlmSetting("2");
+ insertProjectAlmSetting("3");
+ insertProjectAlmSetting("4");
+ insertProjectAlmSetting("5");
+ }
+
+ @Test
+ public void should_add_summary_comment_enabled_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("project_alm_settings", "summary_comment_enabled", BOOLEAN, null, true);
+
+ assertThat(db.countSql("select count(uuid) from project_alm_settings where summary_comment_enabled is null"))
+ .isEqualTo(5);
+ }
+
+ private void insertProjectAlmSetting(String uuid) {
+ db.executeInsert("PROJECT_ALM_SETTINGS",
+ "UUID", uuid,
+ "ALM_SETTING_UUID", uuid + "-name",
+ "PROJECT_UUID", uuid + "-description",
+ "UPDATED_AT", System2.INSTANCE.now(),
+ "CREATED_AT", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
new file mode 100644
index 00000000000..54f2350e6a1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83Test.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import org.junit.Test;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion83Test {
+
+ private DbVersion underTest = new DbVersion83();
+
+ @Test
+ public void migrationNumber_starts_at_3300() {
+ verifyMinimumMigrationNumber(underTest, 3300);
+ }
+
+ @Test
+ public void verify_migration_count() {
+ verifyMigrationCount(underTest, 2);
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java
new file mode 100644
index 00000000000..ddda3597887
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java
@@ -0,0 +1,140 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v83;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateSummaryCommentEnabledColumnForGitHubTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateSummaryCommentEnabledColumnForGitHubTest.class, "schema.sql");
+
+ private System2 system = System2.INSTANCE;
+
+ private DataChange underTest = new PopulateSummaryCommentEnabledColumnForGitHub(db.database(), system);
+
+ @Test
+ public void does_not_fail_if_alm_settings_are_empty() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(uuid) from project_alm_settings where summary_comment_enabled is null"))
+ .isEqualTo(0);
+
+ // re-entrant migration
+ underTest.execute();
+ }
+
+ @Test
+ public void does_not_set_comment_summary_enabled_flag_for_alms_other_than_github() throws SQLException {
+ insertAlmSetting("alm-bitbucket", "bitbucket");
+ insertAlmSetting("alm-azure", "azure");
+ insertAlmSetting("alm-gitlab", "gitlab");
+
+ insertProjectAlmSetting("project-alm-1", "alm-bitbucket");
+ insertProjectAlmSetting("project-alm-2", "alm-bitbucket");
+ insertProjectAlmSetting("project-alm-3", "alm-azure");
+ insertProjectAlmSetting("project-alm-4", "alm-azure");
+ insertProjectAlmSetting("project-alm-5", "alm-azure");
+ insertProjectAlmSetting("project-alm-6", "alm-gitlab");
+
+ underTest.execute();
+
+ verifySummaryColumnForProjectAlmSettings(null, "project-alm-1", "project-alm-2", "project-alm-3",
+ "project-alm-4", "project-alm-5", "project-alm-6");
+ }
+
+ @Test
+ public void set_comment_summary_enabled_flag_to_true_for_github_alm_only() throws SQLException {
+ insertAlmSetting("alm-github", "github");
+ insertAlmSetting("alm-azure", "azure");
+ insertAlmSetting("alm-gitlab", "gitlab");
+
+ insertProjectAlmSetting("project-alm-1", "alm-bitbucket");
+ insertProjectAlmSetting("project-alm-2", "alm-bitbucket");
+ insertProjectAlmSetting("project-alm-3", "alm-github");
+ insertProjectAlmSetting("project-alm-4", "alm-github");
+ insertProjectAlmSetting("project-alm-5", "alm-github");
+ insertProjectAlmSetting("project-alm-6", "alm-github");
+ insertProjectAlmSetting("project-alm-7", "alm-gitlab");
+
+ underTest.execute();
+
+ verifySummaryColumnForProjectAlmSettings(null, "project-alm-1", "project-alm-2", "project-alm-7");
+ verifySummaryColumnForProjectAlmSettings(true, "project-alm-3", "project-alm-4", "project-alm-5", "project-alm-6");
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ insertAlmSetting("alm-github", "github");
+ insertAlmSetting("alm-azure", "azure");
+ insertAlmSetting("alm-gitlab", "gitlab");
+
+ insertProjectAlmSetting("project-alm-1", "alm-bitbucket");
+ insertProjectAlmSetting("project-alm-2", "alm-github");
+
+ underTest.execute();
+ // re-entrant
+ underTest.execute();
+
+ verifySummaryColumnForProjectAlmSettings(null, "project-alm-1");
+ verifySummaryColumnForProjectAlmSettings(true, "project-alm-2");
+ }
+
+ private void verifySummaryColumnForProjectAlmSettings(@Nullable Boolean expectedSummarColumnValue, String... projectUuids) {
+ assertThat(db.select("select uuid, summary_comment_enabled from project_alm_settings")
+ .stream()
+ .filter(rowColumns -> Objects.equals(expectedSummarColumnValue, getBooleanValue(rowColumns.get("SUMMARY_COMMENT_ENABLED"))))
+ .map(row -> row.get("UUID"))
+ .collect(Collectors.toList()))
+ .containsExactly(projectUuids);
+ }
+
+ private Boolean getBooleanValue(@Nullable Object value) {
+ return value == null ? null : Boolean.parseBoolean(value.toString());
+ }
+
+ private void insertProjectAlmSetting(String uuid, String almSettingsUuid) {
+ db.executeInsert("PROJECT_ALM_SETTINGS",
+ "UUID", uuid,
+ "ALM_SETTING_UUID", almSettingsUuid,
+ "PROJECT_UUID", uuid + "-description",
+ "UPDATED_AT", system.now(),
+ "CREATED_AT", system.now());
+ }
+
+ private void insertAlmSetting(String uuid, String almId) {
+ db.executeInsert("ALM_SETTINGS",
+ "UUID", uuid,
+ "ALM_ID", almId,
+ "KEE", uuid + "-key",
+ "UPDATED_AT", system.now(),
+ "CREATED_AT", system.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest/schema.sql
new file mode 100644
index 00000000000..ead60d1b1e3
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddSummaryEnabledColumnToAlmSettingsTest/schema.sql
@@ -0,0 +1,13 @@
+CREATE TABLE "PROJECT_ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "ALM_REPO" VARCHAR(256),
+ "ALM_SLUG" VARCHAR(256),
+ "UPDATED_AT" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+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");
+CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest/schema.sql
new file mode 100644
index 00000000000..320a964ba06
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest/schema.sql
@@ -0,0 +1,28 @@
+CREATE TABLE "ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_ID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(200) NOT NULL,
+ "URL" VARCHAR(2000),
+ "APP_ID" VARCHAR(80),
+ "PRIVATE_KEY" VARCHAR(2000),
+ "PAT" VARCHAR(2000),
+ "UPDATED_AT" BIGINT NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "ALM_SETTINGS" ADD CONSTRAINT "PK_ALM_SETTINGS" PRIMARY KEY("UUID");
+CREATE UNIQUE INDEX "UNIQ_ALM_SETTINGS" ON "ALM_SETTINGS"("KEE");
+
+CREATE TABLE "PROJECT_ALM_SETTINGS"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_SETTING_UUID" VARCHAR(40) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "ALM_REPO" VARCHAR(256),
+ "ALM_SLUG" VARCHAR(256),
+ "UPDATED_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");
+CREATE INDEX "PROJECT_ALM_SETTINGS_ALM" ON "PROJECT_ALM_SETTINGS"("ALM_SETTING_UUID");
+CREATE INDEX "PROJECT_ALM_SETTINGS_SLUG" ON "PROJECT_ALM_SETTINGS"("ALM_SLUG");