aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Milisavljevic <dejan.milisavljevic@sonarsource.com>2024-12-20 10:05:29 +0100
committersonartech <sonartech@sonarsource.com>2024-12-20 20:03:11 +0000
commit833658d0fab511d30ed2ec0016ba5c8aa8ddb475 (patch)
treed2818585b9359c1fb30040a9829bf79755b5ae6b
parent12fcdffaa196e04eb43fdb103ced58c0e5f33b68 (diff)
downloadsonarqube-833658d0fab511d30ed2ec0016ba5c8aa8ddb475.tar.gz
sonarqube-833658d0fab511d30ed2ec0016ba5c8aa8ddb475.zip
SONAR-23978 Detect AI Code
-rw-r--r--server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java (renamed from server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java)0
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java1
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java22
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java10
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml9
7 files changed, 48 insertions, 0 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java
index a8992fff0c3..a8992fff0c3 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryRule.java
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
index 0e5df66f68f..db9189816da 100644
--- a/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
@@ -118,6 +118,7 @@ public final class SqTables {
"snapshots",
"telemetry_metrics_sent",
"users",
+ "user_ai_tool_usages",
"user_dismissed_messages",
"user_roles",
"user_tokens",
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
index b44d0d98d08..389ca6e9f3c 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/project/ProjectDaoIT.java
@@ -295,6 +295,23 @@ class ProjectDaoIT {
}
@Test
+ void update_detectAiCode() {
+ ProjectDto dto1 = createProject("o1", "p1");
+
+ projectDao.insert(db.getSession(), dto1);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(List.of("uuid_o1_p1")));
+ assertThat(projectsByUuids).hasSize(1);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false, false, false);
+
+ projectDao.updateDetectedAiCode(db.getSession(), dto1.getUuid(), true);
+
+ projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(List.of("uuid_o1_p1")));
+ assertThat(projectsByUuids).hasSize(1);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false, false, true);
+ }
+
+ @Test
void update_aiCodeFixEnabledPerProject() {
ProjectDto dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true);
ProjectDto dto2 = createProject("o1", "p2");
@@ -525,6 +542,11 @@ class ProjectDaoIT {
.containsExactly(name, kee, kee, uuid, desc, tags, isPrivate, containsAiCode);
}
+ private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate, boolean containsAiCode, boolean detectedAiCode) {
+ assertThat(dto).extracting("name", "kee", "key", "uuid", "description", "tagsString", "private", "containsAiCode", "detectedAiCode")
+ .containsExactly(name, kee, kee, uuid, desc, tags, isPrivate, containsAiCode, detectedAiCode);
+ }
+
private void assertProjectAiCodeFixEnablement(ProjectDto dto, String uuid, boolean isAiCodeFixEnabled) {
assertThat(dto).extracting("uuid", "aiCodeFixEnabled").containsExactly(uuid, isAiCodeFixEnabled);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
index 78544955364..921e7e3a191 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
@@ -123,6 +123,10 @@ public class ProjectDao implements Dao {
mapper(session).updateContainsAiCode(uuid, containsAiCode, system2.now());
}
+ public void updateDetectedAiCode(DbSession session, String uuid, boolean detectedAiCode) {
+ mapper(session).updateDetectedAiCode(uuid, detectedAiCode, system2.now());
+ }
+
public void updateAiCodeFixEnablementForAllProjects(DbSession dbSession, boolean featureEnablement) {
mapper(dbSession).updateAiCodeFixEnablementForAllProjects(featureEnablement, system2.now());
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
index 3a3c7040bcc..65096789f60 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDto.java
@@ -34,6 +34,7 @@ public class ProjectDto extends EntityDto {
private CreationMethod creationMethod;
private boolean containsAiCode;
private boolean aiCodeFixEnabled = false;
+ private boolean detectedAiCode;
private long createdAt;
private long updatedAt;
@@ -135,6 +136,15 @@ public class ProjectDto extends EntityDto {
return this;
}
+ public boolean getDetectedAiCode() {
+ return detectedAiCode;
+ }
+
+ public ProjectDto setDetectedAiCode(boolean detectedAiCode) {
+ this.detectedAiCode = detectedAiCode;
+ return this;
+ }
+
public boolean getAiCodeFixEnabled() {
return aiCodeFixEnabled;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
index d0047c9a2cc..f798ac1de96 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectMapper.java
@@ -60,6 +60,8 @@ public interface ProjectMapper {
void updateContainsAiCode(@Param("uuid") String uuid, @Param("containsAiCode") boolean containsAiCode, @Param("updatedAt") long updatedAt);
+ void updateDetectedAiCode(@Param("uuid") String uuid, @Param("detectedAiCode") boolean containsAiCode, @Param("updatedAt") long updatedAt);
+
void updateAiCodeFixEnablementForAllProjects(@Param("aiCodeFixEnabled") boolean aiCodeFixEnabled, @Param("updatedAt") long updatedAt);
List<ProjectDto> selectAllApplications();
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
index d8818c409d5..108d01369cc 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/project/ProjectMapper.xml
@@ -12,6 +12,7 @@
p.private as isPrivate,
p.creation_method as creationMethod,
p.contains_ai_code as containsAiCode,
+ p.detected_ai_code as detectedAiCode,
p.ai_code_fix_enabled as aiCodeFixEnabled,
p.created_at as createdAt,
p.updated_at as updatedAt
@@ -193,6 +194,14 @@
uuid = #{uuid,jdbcType=VARCHAR}
</update>
+ <update id="updateDetectedAiCode">
+ update projects set
+ detected_ai_code = #{detectedAiCode,jdbcType=BOOLEAN},
+ updated_at = #{updatedAt,jdbcType=BIGINT}
+ where
+ uuid = #{uuid,jdbcType=VARCHAR}
+ </update>
+
<update id="updateAiCodeFixEnablementForAllProjects">
update projects set
ai_code_fix_enabled = #{aiCodeFixEnabled,jdbcType=BOOLEAN},