aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2024-12-19 16:11:36 +0100
committersonartech <sonartech@sonarsource.com>2024-12-20 20:03:11 +0000
commit12fcdffaa196e04eb43fdb103ced58c0e5f33b68 (patch)
treea730a0de8ab671dfa2a0bf06f65fb31ac49a1b0d
parenteb6c821da27dcb4af7545e5605cdd360f81f22f7 (diff)
downloadsonarqube-12fcdffaa196e04eb43fdb103ced58c0e5f33b68.tar.gz
sonarqube-12fcdffaa196e04eb43fdb103ced58c0e5f33b68.zip
SONAR-23984 Add Scheduler to fetch information about Copilot usage
-rw-r--r--server/sonar-auth-github/src/main/java/org/sonar/auth/github/GithubBinding.java24
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java66
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java5
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml11
5 files changed, 110 insertions, 5 deletions
diff --git a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GithubBinding.java b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GithubBinding.java
index 3a1d7390b2c..70faf9c5562 100644
--- a/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GithubBinding.java
+++ b/server/sonar-auth-github/src/main/java/org/sonar/auth/github/GithubBinding.java
@@ -32,7 +32,8 @@ public class GithubBinding {
// nothing to do
}
- public record GsonOrganizationFull(@SerializedName("login") String login, @SerializedName("default_repository_permission") String defaultRepositoryPermissions){}
+ public record GsonOrganizationFull(@SerializedName("login") String login, @SerializedName("default_repository_permission") String defaultRepositoryPermissions) {
+ }
public static class GsonApp {
@@ -168,12 +169,13 @@ public class GithubBinding {
String metadata;
@SerializedName("administration")
String repoAdministration;
-
@SerializedName("organization_administration")
String orgAdministration;
+ @SerializedName("organization_copilot_seat_management")
+ String orgCopilotSeatManagement;
public Permissions(@Nullable String checks, @Nullable String members, @Nullable String emails, @Nullable String contents, @Nullable String metadata,
- @Nullable String repoAdministration, @Nullable String orgAdministration) {
+ @Nullable String repoAdministration, @Nullable String orgAdministration, @Nullable String orgCopilotSeatManagement) {
this.checks = checks;
this.members = members;
this.emails = emails;
@@ -181,6 +183,7 @@ public class GithubBinding {
this.metadata = metadata;
this.repoAdministration = repoAdministration;
this.orgAdministration = orgAdministration;
+ this.orgCopilotSeatManagement = orgCopilotSeatManagement;
}
public Permissions() {
@@ -228,6 +231,11 @@ public class GithubBinding {
return orgAdministration;
}
+ @CheckForNull
+ public String getOrgCopilotSeatManagement() {
+ return orgCopilotSeatManagement;
+ }
+
public static class Builder {
private String checks;
private String members;
@@ -235,8 +243,8 @@ public class GithubBinding {
private String contents;
private String metadata;
private String repoAdministration;
-
private String orgAdministration;
+ private String orgCopilotSeatManagement;
private Builder() {
// Use static factory method
@@ -277,8 +285,13 @@ public class GithubBinding {
return this;
}
+ public Builder setOrgCopilotSeatManagement(String orgCopilotSeatManagement) {
+ this.orgCopilotSeatManagement = orgCopilotSeatManagement;
+ return this;
+ }
+
public GithubBinding.Permissions build() {
- return new GithubBinding.Permissions(checks, members, emails, contents, metadata, repoAdministration, orgAdministration);
+ return new GithubBinding.Permissions(checks, members, emails, contents, metadata, repoAdministration, orgAdministration, orgCopilotSeatManagement);
}
}
}
@@ -294,6 +307,7 @@ public class GithubBinding {
// recommended:
// http://stackoverflow.com/a/18645370/229031
}
+
public int getTotalCount() {
return totalCount;
}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java
index 7958b621ed8..3094c182065 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/user/ai/UserAiToolUsageDaoIT.java
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;
import static org.assertj.core.api.AssertionsForClassTypes.tuple;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
@@ -79,4 +80,69 @@ class UserAiToolUsageDaoIT {
.extracting(UserAiToolUsageDto::getUuid, UserAiToolUsageDto::getUserUuid, UserAiToolUsageDto::getActivatedAt, UserAiToolUsageDto::getLastActivityAt)
.containsExactly(tuple("uuid", "userUuid", 1L, null));
}
+
+ @Test
+ void update_shouldUpdateExpectedEntry() {
+ UserAiToolUsageDto dto = new UserAiToolUsageDto()
+ .setUuid("uuid")
+ .setUserUuid("userUuid")
+ .setActivatedAt(1L)
+ .setLastActivityAt(2L);
+
+ UserAiToolUsageDto dto2 = new UserAiToolUsageDto()
+ .setUuid("uuid2")
+ .setUserUuid("userUuid2")
+ .setActivatedAt(1L)
+ .setLastActivityAt(2L);
+
+ underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto2);
+
+ dto.setActivatedAt(12L);
+ dto.setLastActivityAt(22L);
+
+ underTest.update(dbSession, dto);
+
+ assertThat(underTest.selectAll(dbSession))
+ .extracting(UserAiToolUsageDto::getUuid, UserAiToolUsageDto::getUserUuid, UserAiToolUsageDto::getActivatedAt, UserAiToolUsageDto::getLastActivityAt)
+ .containsExactlyInAnyOrder(tuple("uuid", "userUuid", 12L, 22L), tuple("uuid2", "userUuid2", 1L, 2L));
+ }
+
+ @Test
+ void delete_shouldRemoveExpectedEntry() {
+ UserAiToolUsageDto dto = new UserAiToolUsageDto()
+ .setUuid("uuid")
+ .setUserUuid("userUuid")
+ .setActivatedAt(1L)
+ .setLastActivityAt(2L);
+
+ UserAiToolUsageDto dto2 = new UserAiToolUsageDto()
+ .setUuid("uuid2")
+ .setUserUuid("userUuid2")
+ .setActivatedAt(1L)
+ .setLastActivityAt(2L);
+
+ underTest.insert(dbSession, dto);
+ underTest.insert(dbSession, dto2);
+
+ underTest.delete(dbSession, dto);
+
+ assertThat(underTest.selectAll(dbSession))
+ .extracting(UserAiToolUsageDto::getUuid)
+ .containsExactlyInAnyOrder("uuid2");
+ }
+
+ @Test
+ void delete_whenTableIsEmpty_shouldNotFail() {
+ UserAiToolUsageDto dto = new UserAiToolUsageDto()
+ .setUuid("uuid")
+ .setUserUuid("userUuid")
+ .setActivatedAt(1L)
+ .setLastActivityAt(2L);
+
+ underTest.insert(dbSession, dto);
+
+ assertThatCode(() -> underTest.delete(dbSession, dto)).doesNotThrowAnyException();
+
+ }
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java
index e678b59da6b..d4b3555d192 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageDao.java
@@ -33,7 +33,16 @@ public class UserAiToolUsageDao implements Dao {
return mapper(dbSession).selectAll();
}
+ public void update(DbSession dbSession, UserAiToolUsageDto userAiToolUsageDto) {
+ mapper(dbSession).update(userAiToolUsageDto);
+ }
+
+ public void delete(DbSession dbSession, UserAiToolUsageDto userAiToolUsageDto) {
+ mapper(dbSession).delete(userAiToolUsageDto);
+ }
+
private static UserAiToolUsageMapper mapper(DbSession session) {
return session.getMapper(UserAiToolUsageMapper.class);
}
+
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java
index 6c3ac6c3043..eeb18821064 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/ai/UserAiToolUsageMapper.java
@@ -26,4 +26,9 @@ public interface UserAiToolUsageMapper {
void insert(UserAiToolUsageDto userAiToolUsageDto);
List<UserAiToolUsageDto> selectAll();
+
+ void update(UserAiToolUsageDto userAiToolUsageDto);
+
+ void delete(UserAiToolUsageDto userAiToolUsageDto);
+
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml
index 9967369403d..2007a7e7554 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/ai/UserAiToolUsageMapper.xml
@@ -32,4 +32,15 @@
)
</insert>
+ <delete id="delete" parameterType="org.sonar.db.user.ai.UserAiToolUsageDto">
+ DELETE FROM user_ai_tool_usages
+ WHERE uuid = #{uuid,jdbcType=VARCHAR}
+ </delete>
+
+ <update id="update" parameterType="org.sonar.db.user.ai.UserAiToolUsageDto">
+ UPDATE user_ai_tool_usages SET
+ activated_at=#{activatedAt,jdbcType=BIGINT},
+ last_activity_at=#{lastActivityAt,jdbcType=BIGINT}
+ WHERE uuid=#{uuid}
+ </update>
</mapper>