Skip to content

Commit

Permalink
SONAR-23978 Detect AI Code
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan-milisavljevic-sonarsource authored and sonartech committed Dec 20, 2024
1 parent 12fcdff commit 833658d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public final class SqTables {
"snapshots",
"telemetry_metrics_sent",
"users",
"user_ai_tool_usages",
"user_dismissed_messages",
"user_roles",
"user_tokens",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ void update_containsAiCode() {
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false, true);
}

@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);
Expand Down Expand Up @@ -525,6 +542,11 @@ private void assertProject(ProjectDto dto, String name, String kee, String uuid,
.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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public void updateContainsAiCode(DbSession session, String uuid, boolean contain
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -135,6 +136,15 @@ public ProjectDto setContainsAiCode(boolean containsAiCode) {
return this;
}

public boolean getDetectedAiCode() {
return detectedAiCode;
}

public ProjectDto setDetectedAiCode(boolean detectedAiCode) {
this.detectedAiCode = detectedAiCode;
return this;
}

public boolean getAiCodeFixEnabled() {
return aiCodeFixEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 833658d

Please sign in to comment.