--- /dev/null
+/*
+ * 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
+ );
+ }
+
+}
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;
EventDao.class,
EventComponentChangeDao.class,
GithubOrganizationGroupDao.class,
+ GithubPermissionsMappingDao.class,
ExternalGroupDao.class,
FileSourceDao.class,
GroupDao.class,
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;
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;
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);
return githubOrganizationGroupDao;
}
+ public GithubPermissionsMappingDao githubPermissionsMappingDao() {
+ return githubPermissionsMappingDao;
+ }
+
public ExternalGroupDao externalGroupDao() {
return externalGroupDao;
}
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;
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);
EventMapper.class,
EventComponentChangeMapper.class,
GithubOrganizationGroupMapper.class,
+ GithubPermissionsMappingMapper.class,
ExternalGroupMapper.class,
FileSourceMapper.class,
GroupMapper.class,
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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) {
+}
--- /dev/null
+/*
+ * 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);
+
+}
--- /dev/null
+<?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>