aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/GithubPermissionsMappingDaoIT.java72
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java7
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java40
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java23
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java30
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/provisioning/GithubPermissionsMappingMapper.xml31
8 files changed, 209 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/GithubPermissionsMappingDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/GithubPermissionsMappingDaoIT.java
new file mode 100644
index 00000000000..0eb588de39d
--- /dev/null
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/provisioning/GithubPermissionsMappingDaoIT.java
@@ -0,0 +1,72 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.db.provisioning;
+
+import java.util.Set;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GithubPermissionsMappingDaoIT {
+
+ private static final String MAPPING_UUID = "uuid";
+
+ @Rule
+ public final DbTester db = DbTester.create();
+
+ private final DbSession dbSession = db.getSession();
+
+ private final GithubPermissionsMappingDao underTest = db.getDbClient().githubPermissionsMappingDao();
+
+ @Test
+ public void insert_savesGithubPermissionsMappingDto() {
+ GithubPermissionsMappingDto githubPermissionsMappingDto = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
+
+ underTest.insert(dbSession, githubPermissionsMappingDto);
+
+ Set<GithubPermissionsMappingDto> savedGithubPermissionsMappings = underTest.findAll(dbSession);
+ assertThat(savedGithubPermissionsMappings).hasSize(1);
+ GithubPermissionsMappingDto savedMapping = savedGithubPermissionsMappings.iterator().next();
+ assertThat(savedMapping.uuid()).isEqualTo(githubPermissionsMappingDto.uuid());
+ assertThat(savedMapping.githubRole()).isEqualTo(githubPermissionsMappingDto.githubRole());
+ assertThat(savedMapping.sonarqubePermission()).isEqualTo(githubPermissionsMappingDto.sonarqubePermission());
+ }
+
+ @Test
+ public void findAll_shouldReturnAllGithubOrganizationGroup() {
+ GithubPermissionsMappingDto mapping1 = new GithubPermissionsMappingDto(MAPPING_UUID, "GH_role", "SQ_role");
+ GithubPermissionsMappingDto mapping2 = new GithubPermissionsMappingDto(MAPPING_UUID + "2", "GH_role2", "SQ_role");
+
+ underTest.insert(dbSession, mapping1);
+ underTest.insert(dbSession, mapping2);
+
+ Set<GithubPermissionsMappingDto> all = underTest.findAll(dbSession);
+
+ assertThat(all).hasSize(2)
+ .containsExactlyInAnyOrder(
+ mapping1,
+ mapping2
+ );
+ }
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
index 9ef51dcb632..e67eee6703d 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoModule.java
@@ -64,6 +64,7 @@ import org.sonar.db.property.InternalComponentPropertiesDao;
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.provisioning.GithubOrganizationGroupDao;
+import org.sonar.db.provisioning.GithubPermissionsMappingDao;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
@@ -128,6 +129,7 @@ public class DaoModule extends Module {
EventDao.class,
EventComponentChangeDao.class,
GithubOrganizationGroupDao.class,
+ GithubPermissionsMappingDao.class,
ExternalGroupDao.class,
FileSourceDao.class,
GroupDao.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
index 13d32c315d2..9949da0a223 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DbClient.java
@@ -64,6 +64,7 @@ import org.sonar.db.property.InternalComponentPropertiesDao;
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.provisioning.GithubOrganizationGroupDao;
+import org.sonar.db.provisioning.GithubPermissionsMappingDao;
import org.sonar.db.purge.PurgeDao;
import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
@@ -187,6 +188,7 @@ public class DbClient {
private final ReportScheduleDao reportScheduleDao;
private final ReportSubscriptionDao reportSubscriptionDao;
private final GithubOrganizationGroupDao githubOrganizationGroupDao;
+ private final GithubPermissionsMappingDao githubPermissionsMappingDao;
public DbClient(Database database, MyBatis myBatis, DBSessions dbSessions, Dao... daos) {
this.database = database;
@@ -244,6 +246,7 @@ public class DbClient {
metricDao = getDao(map, MetricDao.class);
groupDao = getDao(map, GroupDao.class);
githubOrganizationGroupDao = getDao(map, GithubOrganizationGroupDao.class);
+ githubPermissionsMappingDao = getDao(map, GithubPermissionsMappingDao.class);
externalGroupDao = getDao(map, ExternalGroupDao.class);
ruleDao = getDao(map, RuleDao.class);
ruleRepositoryDao = getDao(map, RuleRepositoryDao.class);
@@ -490,6 +493,10 @@ public class DbClient {
return githubOrganizationGroupDao;
}
+ public GithubPermissionsMappingDao githubPermissionsMappingDao() {
+ return githubPermissionsMappingDao;
+ }
+
public ExternalGroupDao externalGroupDao() {
return externalGroupDao;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
index 98b404ea849..2566492e862 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
@@ -119,6 +119,8 @@ import org.sonar.db.property.PropertiesMapper;
import org.sonar.db.property.ScrapPropertyDto;
import org.sonar.db.provisioning.GithubOrganizationGroupDto;
import org.sonar.db.provisioning.GithubOrganizationGroupMapper;
+import org.sonar.db.provisioning.GithubPermissionsMappingDto;
+import org.sonar.db.provisioning.GithubPermissionsMappingMapper;
import org.sonar.db.purge.PurgeMapper;
import org.sonar.db.purge.PurgeableAnalysisDto;
import org.sonar.db.pushevent.PushEventDto;
@@ -207,6 +209,7 @@ public class MyBatis {
confBuilder.loadAlias("Event", EventDto.class);
confBuilder.loadAlias("ExternalGroup", ExternalGroupDto.class);
confBuilder.loadAlias("GithubOrganizationGroup", GithubOrganizationGroupDto.class);
+ confBuilder.loadAlias("GithubPermissionsMapping", GithubPermissionsMappingDto.class);
confBuilder.loadAlias("FilePathWithHash", FilePathWithHashDto.class);
confBuilder.loadAlias("KeyWithUuid", KeyWithUuidDto.class);
confBuilder.loadAlias("Group", GroupDto.class);
@@ -285,6 +288,7 @@ public class MyBatis {
EventMapper.class,
EventComponentChangeMapper.class,
GithubOrganizationGroupMapper.class,
+ GithubPermissionsMappingMapper.class,
ExternalGroupMapper.class,
FileSourceMapper.class,
GroupMapper.class,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java
new file mode 100644
index 00000000000..fad64ad92c1
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDao.java
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.db.provisioning;
+
+import java.util.Set;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class GithubPermissionsMappingDao implements Dao {
+
+ public Set<GithubPermissionsMappingDto> findAll(DbSession dbSession) {
+ return mapper(dbSession).selectAll();
+ }
+
+ public void insert(DbSession dbSession, GithubPermissionsMappingDto githubPermissionsMappingDto) {
+ mapper(dbSession).insert(githubPermissionsMappingDto);
+ }
+
+ private static GithubPermissionsMappingMapper mapper(DbSession session) {
+ return session.getMapper(GithubPermissionsMappingMapper.class);
+ }
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java
new file mode 100644
index 00000000000..cf99b5ceeb5
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingDto.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.db.provisioning;
+
+public record GithubPermissionsMappingDto(String uuid, String githubRole, String sonarqubePermission) {
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java
new file mode 100644
index 00000000000..c59a911a335
--- /dev/null
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/provisioning/GithubPermissionsMappingMapper.java
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.db.provisioning;
+
+import java.util.Set;
+
+public interface GithubPermissionsMappingMapper {
+
+ Set<GithubPermissionsMappingDto> selectAll();
+
+ void insert(GithubPermissionsMappingDto githubPermissionsMappingDto);
+
+}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/provisioning/GithubPermissionsMappingMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/provisioning/GithubPermissionsMappingMapper.xml
new file mode 100644
index 00000000000..7f739bc60a5
--- /dev/null
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/provisioning/GithubPermissionsMappingMapper.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.db.provisioning.GithubPermissionsMappingMapper">
+
+ <sql id="githubPermissionsMappingColumns">
+ gpm.uuid as uuid,
+ gpm.github_role as githubRole,
+ gpm.sonarqube_permission as sonarqubePermission
+ </sql>
+
+ <insert id="insert" useGeneratedKeys="false" parameterType="GithubPermissionsMapping">
+ insert into github_perms_mapping (
+ uuid,
+ github_role,
+ sonarqube_permission
+ ) values (
+ #{uuid,jdbcType=VARCHAR},
+ #{githubRole,jdbcType=VARCHAR},
+ #{sonarqubePermission,jdbcType=VARCHAR}
+ )
+ </insert>
+
+ <select id="selectAll" resultType="GithubPermissionsMapping">
+ SELECT
+ <include refid="githubPermissionsMappingColumns"/>
+ FROM github_perms_mapping gpm
+ </select>
+
+</mapper>