From 95dbaf1f6d7470f82b740ad3fdecae7397115f10 Mon Sep 17 00:00:00 2001 From: Stefan Nemeth Date: Sun, 24 Nov 2024 19:13:52 +0100 Subject: [PATCH 01/10] Fix compsoe auth env --- compose.dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.dev.yaml b/compose.dev.yaml index 1c37239..acc6f00 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -25,7 +25,7 @@ services: ports: - "4222:4222" - "8222:8222" - command: ["/bin/sh", "-c", "sed 's|{{NATS_AUTH_TOKEN}}|'\"$NATS_AUTH_TOKEN\"'|g' /etc/nats/nats-server.conf.template > /etc/nats/nats-server.conf && exec nats-server --config /etc/nats/nats-server.conf"] + command: ["/bin/sh", "-c", "sed 's|{{NATS_AUTH_TOKEN}}|'\"$${NATS_AUTH_TOKEN}\"'|g' /etc/nats/nats-server.conf.template > /etc/nats/nats-server.conf && exec nats-server --config /etc/nats/nats-server.conf"] environment: - NATS_AUTH_TOKEN=5760e8ae09adfb2756f9f8cd5cb2caa704cd3f549eaa9298be843ceb165185d815b81f90c680fa7f626b7cd63abf6ac9 volumes: From 3321694f70daf7474e2bc19fd8bd83eec5209253 Mon Sep 17 00:00:00 2001 From: Stefan Nemeth Date: Sun, 24 Nov 2024 20:05:56 +0100 Subject: [PATCH 02/10] Restructure package by feature --- .../cit/aet/helios/OpenAPIConfiguration.java | 8 ------ .../github/BaseGitServiceEntity.java | 2 +- .../github/BaseGitServiceEntityConverter.java | 4 ++- .../{config => github}/GitHubConfig.java | 4 +-- .../github/GitHubMessageHandler.java | 2 +- .../github/GitHubMessageHandlerRegistry.java | 2 +- .../GitHubService.java | 5 +--- .../sync}/DataSyncStatus.java | 2 +- .../sync}/DataSyncStatusRepository.java | 2 +- .../sync}/GitHubDataSyncScheduler.java | 2 +- .../sync}/GitHubDataSyncService.java | 11 ++++---- .../repository/RepositoryRepository.java | 10 ------- .../aet/helios/gitrepo/GitRepoRepository.java | 10 +++++++ .../GitRepository.java} | 7 ++--- .../RepositoryInfoDTO.java | 4 +-- .../github/GitHubRepositoryConverter.java | 27 ++++++++++--------- .../github/GitHubRepositorySyncService.java | 22 +++++++-------- .../helios/{gitprovider => }/issue/Issue.java | 11 ++++---- .../issue/IssueRepository.java | 2 +- .../issue/github/GitHubIssueConverter.java | 9 ++++--- .../github/GitHubIssueMessageHandler.java | 4 +-- .../helios/{config => nats}/NatsConfig.java | 9 ++++--- .../NatsConsumerService.java | 13 +++++---- .../NatsNotificationPublisherService.java | 4 +-- .../pullrequest/PullRequest.java | 7 ++--- .../pullrequest/PullRequestBaseInfoDTO.java | 9 ++++--- .../pullrequest/PullRequestController.java | 3 +-- .../pullrequest/PullRequestInfoDTO.java | 10 ++++--- .../pullrequest/PullRequestRepository.java | 2 +- .../pullrequest/PullRequestService.java | 4 +-- .../github/GitHubPullRequestConverter.java | 11 ++++---- .../GitHubPullRequestMessageHandler.java | 7 ++--- .../github/GitHubPullRequestSyncService.java | 25 ++++++++--------- .../helios/{gitprovider => }/user/User.java | 5 ++-- .../{gitprovider => }/user/UserInfoDTO.java | 2 +- .../user/UserRepository.java | 2 +- .../user/github/GitHubUserConverter.java | 7 ++--- .../user/github/GitHubUserSyncService.java | 9 ++++--- .../common/github => util}/DateUtil.java | 2 +- .../aet/helios/HeliosApplicationTests.java | 1 - 40 files changed, 141 insertions(+), 141 deletions(-) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/common => }/github/BaseGitServiceEntity.java (86%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/common => }/github/BaseGitServiceEntityConverter.java (94%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{config => github}/GitHubConfig.java (97%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/common => }/github/GitHubMessageHandler.java (97%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/common => }/github/GitHubMessageHandlerRegistry.java (93%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => github}/GitHubService.java (95%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => github/sync}/DataSyncStatus.java (92%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => github/sync}/DataSyncStatusRepository.java (87%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => github/sync}/GitHubDataSyncScheduler.java (96%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => github/sync}/GitHubDataSyncService.java (86%) delete mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryRepository.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepoRepository.java rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/repository/Repository.java => gitrepo/GitRepository.java} (90%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/repository => gitrepo}/RepositoryInfoDTO.java (79%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/repository => gitrepo}/github/GitHubRepositoryConverter.java (67%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/repository => gitrepo}/github/GitHubRepositorySyncService.java (87%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/issue/Issue.java (86%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/issue/IssueRepository.java (73%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/issue/github/GitHubIssueConverter.java (83%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/issue/github/GitHubIssueMessageHandler.java (88%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{config => nats}/NatsConfig.java (90%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => nats}/NatsConsumerService.java (96%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{syncing => nats}/NatsNotificationPublisherService.java (97%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequest.java (91%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequestBaseInfoDTO.java (84%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequestController.java (93%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequestInfoDTO.java (88%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequestRepository.java (79%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/PullRequestService.java (85%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/github/GitHubPullRequestConverter.java (91%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/github/GitHubPullRequestMessageHandler.java (87%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/pullrequest/github/GitHubPullRequestSyncService.java (91%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/user/User.java (92%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/user/UserInfoDTO.java (92%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/user/UserRepository.java (73%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/user/github/GitHubUserConverter.java (94%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider => }/user/github/GitHubUserSyncService.java (92%) rename server/application-server/src/main/java/de/tum/cit/aet/helios/{gitprovider/common/github => util}/DateUtil.java (82%) diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/OpenAPIConfiguration.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/OpenAPIConfiguration.java index 76f6a07..aced866 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/OpenAPIConfiguration.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/OpenAPIConfiguration.java @@ -1,11 +1,4 @@ package de.tum.cit.aet.helios; -import java.util.Map; -import java.util.stream.Collectors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springdoc.core.customizers.OpenApiCustomizer; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.swagger.v3.oas.annotations.OpenAPIDefinition; @@ -13,7 +6,6 @@ import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.License; import io.swagger.v3.oas.annotations.servers.Server; -import io.swagger.v3.oas.models.media.Schema; @Configuration @OpenAPIDefinition( diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntity.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntity.java similarity index 86% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntity.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntity.java index b949b7e..3680994 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntity.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntity.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.common.github; +package de.tum.cit.aet.helios.github; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntityConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java similarity index 94% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntityConverter.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java index e382880..c4da0d1 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/BaseGitServiceEntityConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.common.github; +package de.tum.cit.aet.helios.github; import org.kohsuke.github.GHObject; import org.slf4j.Logger; @@ -7,6 +7,8 @@ import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; +import de.tum.cit.aet.helios.util.DateUtil; + import java.io.IOException; @ReadingConverter diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/config/GitHubConfig.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java similarity index 97% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/config/GitHubConfig.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java index 2d58040..c534234 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/config/GitHubConfig.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.config; +package de.tum.cit.aet.helios.github; import lombok.Getter; import okhttp3.Cache; @@ -9,7 +9,6 @@ import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,7 +41,6 @@ public class GitHubConfig { private final Environment environment; - @Autowired public GitHubConfig(Environment environment) { this.environment = environment; } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java similarity index 97% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandler.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java index 3255636..0ce4ab7 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.common.github; +package de.tum.cit.aet.helios.github; import java.io.IOException; import java.io.StringReader; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandlerRegistry.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandlerRegistry.java similarity index 93% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandlerRegistry.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandlerRegistry.java index 026950b..663bf2f 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/GitHubMessageHandlerRegistry.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandlerRegistry.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.common.github; +package de.tum.cit.aet.helios.github; import java.util.ArrayList; import java.util.HashMap; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/GitHubService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java similarity index 95% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/GitHubService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java index 5340cd3..de9c92c 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/GitHubService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java @@ -1,13 +1,11 @@ -package de.tum.cit.aet.helios.gitprovider; +package de.tum.cit.aet.helios.github; -import de.tum.cit.aet.helios.config.GitHubConfig; import org.kohsuke.github.GHOrganization; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHWorkflow; import org.kohsuke.github.GitHub; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.IOException; @@ -25,7 +23,6 @@ public class GitHubService { private GHOrganization gitHubOrganization; - @Autowired public GitHubService(GitHub github, GitHubConfig gitHubConfig) { this.github = github; this.gitHubConfig = gitHubConfig; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatus.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatus.java similarity index 92% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatus.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatus.java index 1968825..2156e74 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatus.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatus.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.github.sync; import jakarta.persistence.*; import lombok.Getter; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatusRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatusRepository.java similarity index 87% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatusRepository.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatusRepository.java index fa61a2e..e21a7a7 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/DataSyncStatusRepository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/DataSyncStatusRepository.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.github.sync; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncScheduler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java similarity index 96% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncScheduler.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java index e34451a..9250f7d 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncScheduler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.github.sync; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java similarity index 86% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java index 3b36ea6..e545d9c 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java @@ -1,9 +1,9 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.github.sync; -import de.tum.cit.aet.helios.gitprovider.pullrequest.github.GitHubPullRequestSyncService; -import de.tum.cit.aet.helios.gitprovider.repository.github.GitHubRepositorySyncService; -import de.tum.cit.aet.helios.gitprovider.user.github.GitHubUserSyncService; +import de.tum.cit.aet.helios.pullrequest.github.GitHubPullRequestSyncService; +import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; +import de.tum.cit.aet.helios.user.github.GitHubUserSyncService; import jakarta.transaction.Transactional; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +60,8 @@ public void syncData() { var startTime = OffsetDateTime.now(); var repositories = repositorySyncService.syncAllMonitoredRepositories(); - var pullRequests = pullRequestSyncService.syncPullRequestsOfAllRepositories(repositories, Optional.of(cutoffDate)); + + pullRequestSyncService.syncPullRequestsOfAllRepositories(repositories, Optional.of(cutoffDate)); userSyncService.syncAllExistingUsers(); var endTime = OffsetDateTime.now(); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryRepository.java deleted file mode 100644 index 850e9e0..0000000 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.tum.cit.aet.helios.gitprovider.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -@org.springframework.stereotype.Repository -public interface RepositoryRepository - extends JpaRepository { - - Repository findByNameWithOwner(String nameWithOwner); -} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepoRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepoRepository.java new file mode 100644 index 0000000..0fb7bd1 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepoRepository.java @@ -0,0 +1,10 @@ +package de.tum.cit.aet.helios.gitrepo; + +import org.springframework.data.jpa.repository.JpaRepository; + +@org.springframework.stereotype.Repository +public interface GitRepoRepository + extends JpaRepository { + + GitRepository findByNameWithOwner(String nameWithOwner); +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/Repository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepository.java similarity index 90% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/Repository.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepository.java index 3c49282..b928617 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/GitRepository.java @@ -1,6 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.repository; +package de.tum.cit.aet.helios.gitrepo; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntity; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,6 +7,8 @@ import lombok.ToString; import org.springframework.lang.NonNull; +import de.tum.cit.aet.helios.github.BaseGitServiceEntity; + import java.time.OffsetDateTime; @Entity @@ -16,7 +17,7 @@ @Setter @NoArgsConstructor @ToString(callSuper = true) -public class Repository extends BaseGitServiceEntity { +public class GitRepository extends BaseGitServiceEntity { @NonNull private String name; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/RepositoryInfoDTO.java similarity index 79% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryInfoDTO.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/RepositoryInfoDTO.java index 903bb76..0407163 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/RepositoryInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/RepositoryInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.repository; +package de.tum.cit.aet.helios.gitrepo; import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.lang.NonNull; @@ -11,7 +11,7 @@ public record RepositoryInfoDTO( String description, @NonNull String htmlUrl) { - public static RepositoryInfoDTO fromRepository(Repository repository) { + public static RepositoryInfoDTO fromRepository(GitRepository repository) { return new RepositoryInfoDTO( repository.getId(), repository.getName(), diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositoryConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java similarity index 67% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositoryConverter.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java index 1049958..925b4ac 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java @@ -1,8 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.repository.github; +package de.tum.cit.aet.helios.gitrepo.github; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntityConverter; -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.repository.Repository; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHRepository.Visibility; import org.slf4j.Logger; @@ -10,18 +7,22 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; +import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; +import de.tum.cit.aet.helios.gitrepo.GitRepository; +import de.tum.cit.aet.helios.util.DateUtil; + @Component -public class GitHubRepositoryConverter extends BaseGitServiceEntityConverter { +public class GitHubRepositoryConverter extends BaseGitServiceEntityConverter { private static final Logger logger = LoggerFactory.getLogger(GitHubRepositoryConverter.class); @Override - public Repository convert(@NonNull GHRepository source) { - return update(source, new Repository()); + public GitRepository convert(@NonNull GHRepository source) { + return update(source, new GitRepository()); } @Override - public Repository update(@NonNull GHRepository source, @NonNull Repository repository) { + public GitRepository update(@NonNull GHRepository source, @NonNull GitRepository repository) { convertBaseFields(source, repository); repository.setName(source.getName()); repository.setNameWithOwner(source.getFullName()); @@ -42,17 +43,17 @@ public Repository update(@NonNull GHRepository source, @NonNull Repository repos return repository; } - private Repository.Visibility convertVisibility(Visibility visibility) { + private GitRepository.Visibility convertVisibility(Visibility visibility) { switch (visibility) { case PRIVATE: - return Repository.Visibility.PRIVATE; + return GitRepository.Visibility.PRIVATE; case PUBLIC: - return Repository.Visibility.PUBLIC; + return GitRepository.Visibility.PUBLIC; case INTERNAL: - return Repository.Visibility.INTERNAL; + return GitRepository.Visibility.INTERNAL; default: logger.error("Unknown repository visibility: {}", visibility); - return Repository.Visibility.UNKNOWN; + return GitRepository.Visibility.UNKNOWN; } } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositorySyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java similarity index 87% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositorySyncService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java index c4bebdb..107f1bb 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/repository/github/GitHubRepositorySyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java @@ -1,9 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.repository.github; +package de.tum.cit.aet.helios.gitrepo.github; - -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.repository.Repository; -import de.tum.cit.aet.helios.gitprovider.repository.RepositoryRepository; import jakarta.transaction.Transactional; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; @@ -12,6 +8,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import de.tum.cit.aet.helios.gitrepo.GitRepoRepository; +import de.tum.cit.aet.helios.gitrepo.GitRepository; +import de.tum.cit.aet.helios.util.DateUtil; + import java.io.IOException; import java.util.List; import java.util.Optional; @@ -25,15 +25,15 @@ public class GitHubRepositorySyncService { private String[] repositoriesToMonitor; private final GitHub github; - private final RepositoryRepository repositoryRepository; + private final GitRepoRepository gitRepoRepository; private final GitHubRepositoryConverter repositoryConverter; public GitHubRepositorySyncService( GitHub github, - RepositoryRepository repositoryRepository, + GitRepoRepository gitRepoRepository, GitHubRepositoryConverter repositoryConverter) { this.github = github; - this.repositoryRepository = repositoryRepository; + this.gitRepoRepository = gitRepoRepository; this.repositoryConverter = repositoryConverter; } @@ -104,8 +104,8 @@ public Optional syncRepository(String nameWithOwner) { * error occurred during update. */ @Transactional - public Repository processRepository(GHRepository ghRepository) { - var result = repositoryRepository.findById(ghRepository.getId()) + public GitRepository processRepository(GHRepository ghRepository) { + var result = gitRepoRepository.findById(ghRepository.getId()) .map(repository -> { try { if (repository.getUpdatedAt() == null || repository.getUpdatedAt() @@ -123,6 +123,6 @@ public Repository processRepository(GHRepository ghRepository) { return null; } - return repositoryRepository.save(result); + return gitRepoRepository.save(result); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/Issue.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/Issue.java similarity index 86% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/Issue.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/issue/Issue.java index 6b7a8f5..e332b2d 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/Issue.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/Issue.java @@ -1,8 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.issue; +package de.tum.cit.aet.helios.issue; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntity; -import de.tum.cit.aet.helios.gitprovider.repository.Repository; -import de.tum.cit.aet.helios.gitprovider.user.User; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,6 +7,10 @@ import lombok.ToString; import org.springframework.lang.NonNull; +import de.tum.cit.aet.helios.github.BaseGitServiceEntity; +import de.tum.cit.aet.helios.gitrepo.GitRepository; +import de.tum.cit.aet.helios.user.User; + import java.time.OffsetDateTime; import java.util.HashSet; import java.util.Set; @@ -58,7 +59,7 @@ public class Issue extends BaseGitServiceEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "repository_id") - private Repository repository; + private GitRepository repository; public enum State { OPEN, CLOSED diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/IssueRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/IssueRepository.java similarity index 73% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/IssueRepository.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/issue/IssueRepository.java index 70ab8a3..6f2e395 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/IssueRepository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/IssueRepository.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.issue; +package de.tum.cit.aet.helios.issue; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueConverter.java similarity index 83% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueConverter.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueConverter.java index 325d606..8a4f2e1 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueConverter.java @@ -1,14 +1,15 @@ -package de.tum.cit.aet.helios.gitprovider.issue.github; +package de.tum.cit.aet.helios.issue.github; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntityConverter; -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.issue.Issue; import org.kohsuke.github.GHIssue; import org.kohsuke.github.GHIssueState; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; +import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; +import de.tum.cit.aet.helios.issue.Issue; +import de.tum.cit.aet.helios.util.DateUtil; + @Component public class GitHubIssueConverter extends BaseGitServiceEntityConverter { diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java similarity index 88% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueMessageHandler.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java index 029948c..460a15d 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/issue/github/GitHubIssueMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.issue.github; +package de.tum.cit.aet.helios.issue.github; import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventPayload; @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; -import de.tum.cit.aet.helios.gitprovider.common.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.github.GitHubMessageHandler; @Component public class GitHubIssueMessageHandler extends GitHubMessageHandler { diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/config/NatsConfig.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java similarity index 90% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/config/NatsConfig.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java index 29eb86a..06dbdf9 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/config/NatsConfig.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java @@ -1,8 +1,7 @@ -package de.tum.cit.aet.helios.config; +package de.tum.cit.aet.helios.nats; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,7 +27,6 @@ public class NatsConfig { private final Environment environment; - @Autowired public NatsConfig(Environment env) { this.environment = env; } @@ -45,7 +43,10 @@ public Connection natsConnection() throws Exception { return null; } - Options options = Options.builder().server(natsServer).token(natsAuthToken).build(); + Options options = Options.builder().server(natsServer).token( + natsAuthToken.toCharArray() + ).build(); + return Nats.connect(options); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsConsumerService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java similarity index 96% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsConsumerService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java index 8f0b3b3..1ef4b66 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsConsumerService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.nats; import java.io.IOException; import java.util.Arrays; @@ -16,9 +16,12 @@ import io.nats.client.api.ConsumerConfiguration; import io.nats.client.api.DeliverPolicy; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; + +import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.github.GitHubMessageHandlerRegistry; + import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; import org.springframework.core.annotation.Order; @@ -27,9 +30,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import de.tum.cit.aet.helios.gitprovider.common.github.GitHubMessageHandler; -import de.tum.cit.aet.helios.gitprovider.common.github.GitHubMessageHandlerRegistry; - @Order(value = 1) @Service public class NatsConsumerService { @@ -63,7 +63,6 @@ public class NatsConsumerService { private final GitHubMessageHandlerRegistry handlerRegistry; - @Autowired public NatsConsumerService(Environment environment, GitHubMessageHandlerRegistry handlerRegistry) { this.environment = environment; this.handlerRegistry = handlerRegistry; @@ -107,7 +106,7 @@ private void validateConfigurations() { private Options buildNatsOptions() { return Options.builder() .server(natsServer) - .token(natsAuthToken) + .token(natsAuthToken.toCharArray()) .connectionListener((conn, type) -> logger.info("Connection event - Server: {}, {}", conn.getServerInfo().getPort(), type)) .maxReconnects(-1) diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsNotificationPublisherService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java similarity index 97% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsNotificationPublisherService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java index 09aa08c..fa3ff49 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/syncing/NatsNotificationPublisherService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.syncing; +package de.tum.cit.aet.helios.nats; import io.nats.client.Connection; import io.nats.client.JetStream; @@ -66,7 +66,7 @@ private void validateConfigurations() { private Options buildNatsOptions() { return Options.builder() .server(natsServer) - .token(natsAuthToken) + .token(natsAuthToken.toCharArray()) .connectionListener((conn, type) -> logger.info("Connection event - Server: {}, {}", conn.getServerInfo().getPort(), type)) .maxReconnects(-1) diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequest.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java similarity index 91% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequest.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java index 58c4c8d..3fbf13b 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequest.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java @@ -1,7 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; -import de.tum.cit.aet.helios.gitprovider.issue.Issue; -import de.tum.cit.aet.helios.gitprovider.user.User; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,6 +10,9 @@ import java.util.HashSet; import java.util.Set; +import de.tum.cit.aet.helios.issue.Issue; +import de.tum.cit.aet.helios.user.User; + @Entity @DiscriminatorValue(value = "PULL_REQUEST") @Getter diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestBaseInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestBaseInfoDTO.java similarity index 84% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestBaseInfoDTO.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestBaseInfoDTO.java index 7c5c969..3de99aa 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestBaseInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestBaseInfoDTO.java @@ -1,10 +1,11 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.cit.aet.helios.gitprovider.issue.Issue; -import de.tum.cit.aet.helios.gitprovider.issue.Issue.State; -import de.tum.cit.aet.helios.gitprovider.repository.RepositoryInfoDTO; +import de.tum.cit.aet.helios.gitrepo.RepositoryInfoDTO; +import de.tum.cit.aet.helios.issue.Issue; +import de.tum.cit.aet.helios.issue.Issue.State; + import org.springframework.lang.NonNull; @JsonInclude(JsonInclude.Include.NON_EMPTY) diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestController.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestController.java similarity index 93% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestController.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestController.java index 6f99606..9c3a0a5 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestController.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestController.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.PathVariable; import java.util.List; -import java.util.Optional; @RestController @RequestMapping("/api/pullrequests") diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestInfoDTO.java similarity index 88% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestInfoDTO.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestInfoDTO.java index 7e461ea..8942573 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestInfoDTO.java @@ -1,9 +1,11 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.cit.aet.helios.gitprovider.issue.Issue.State; -import de.tum.cit.aet.helios.gitprovider.repository.RepositoryInfoDTO; -import de.tum.cit.aet.helios.gitprovider.user.UserInfoDTO; + +import de.tum.cit.aet.helios.gitrepo.RepositoryInfoDTO; +import de.tum.cit.aet.helios.issue.Issue.State; +import de.tum.cit.aet.helios.user.UserInfoDTO; + import org.springframework.lang.NonNull; import java.time.OffsetDateTime; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestRepository.java similarity index 79% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestRepository.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestRepository.java index 5e9f832..d58a1e8 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestRepository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestRepository.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestService.java similarity index 85% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestService.java index 9207dfc..1d397d1 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/PullRequestService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequestService.java @@ -1,6 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest; +package de.tum.cit.aet.helios.pullrequest; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -12,7 +11,6 @@ public class PullRequestService { private final PullRequestRepository pullRequestRepository; - @Autowired public PullRequestService(PullRequestRepository pullRequestRepository) { this.pullRequestRepository = pullRequestRepository; } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java similarity index 91% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestConverter.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java index 57565a9..62b1c0d 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java @@ -1,15 +1,16 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest.github; +package de.tum.cit.aet.helios.pullrequest.github; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntityConverter; -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.issue.github.GitHubIssueConverter; -import de.tum.cit.aet.helios.gitprovider.pullrequest.PullRequest; import org.kohsuke.github.GHPullRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; +import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; +import de.tum.cit.aet.helios.issue.github.GitHubIssueConverter; +import de.tum.cit.aet.helios.pullrequest.PullRequest; +import de.tum.cit.aet.helios.util.DateUtil; + import java.io.IOException; @Component diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java similarity index 87% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestMessageHandler.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java index 24b55c5..9a48cc4 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java @@ -1,13 +1,14 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest.github; +package de.tum.cit.aet.helios.pullrequest.github; -import de.tum.cit.aet.helios.gitprovider.common.github.GitHubMessageHandler; -import de.tum.cit.aet.helios.gitprovider.repository.github.GitHubRepositorySyncService; import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventPayload; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; + @Component public class GitHubPullRequestMessageHandler extends GitHubMessageHandler { diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java similarity index 91% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestSyncService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java index e331d1e..280aec8 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/pullrequest/github/GitHubPullRequestSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java @@ -1,13 +1,6 @@ -package de.tum.cit.aet.helios.gitprovider.pullrequest.github; +package de.tum.cit.aet.helios.pullrequest.github; -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.pullrequest.PullRequest; -import de.tum.cit.aet.helios.gitprovider.pullrequest.PullRequestRepository; -import de.tum.cit.aet.helios.gitprovider.repository.RepositoryRepository; -import de.tum.cit.aet.helios.gitprovider.user.UserRepository; -import de.tum.cit.aet.helios.gitprovider.user.User; -import de.tum.cit.aet.helios.gitprovider.user.github.GitHubUserConverter; import jakarta.transaction.Transactional; import org.kohsuke.github.GHDirection; import org.kohsuke.github.GHIssueState; @@ -18,6 +11,14 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import de.tum.cit.aet.helios.gitrepo.GitRepoRepository; +import de.tum.cit.aet.helios.pullrequest.PullRequest; +import de.tum.cit.aet.helios.pullrequest.PullRequestRepository; +import de.tum.cit.aet.helios.user.User; +import de.tum.cit.aet.helios.user.UserRepository; +import de.tum.cit.aet.helios.user.github.GitHubUserConverter; +import de.tum.cit.aet.helios.util.DateUtil; + import java.io.IOException; import java.time.OffsetDateTime; import java.util.*; @@ -28,19 +29,19 @@ public class GitHubPullRequestSyncService { private static final Logger logger = LoggerFactory.getLogger(GitHubPullRequestSyncService.class); private final PullRequestRepository pullRequestRepository; - private final RepositoryRepository repositoryRepository; + private final GitRepoRepository gitRepoRepository; private final UserRepository userRepository; private final GitHubPullRequestConverter pullRequestConverter; private final GitHubUserConverter userConverter; public GitHubPullRequestSyncService( PullRequestRepository pullRequestRepository, - RepositoryRepository repositoryRepository, + GitRepoRepository gitRepoRepository, UserRepository userRepository, GitHubPullRequestConverter pullRequestConverter, GitHubUserConverter userConverter) { this.pullRequestRepository = pullRequestRepository; - this.repositoryRepository = repositoryRepository; + this.gitRepoRepository = gitRepoRepository; this.userRepository = userRepository; this.pullRequestConverter = pullRequestConverter; this.userConverter = userConverter; @@ -144,7 +145,7 @@ public PullRequest processPullRequest(GHPullRequest ghPullRequest) { // Extract name with owner from the repository URL // Example: https://api.github.com/repos/ls1intum/Artemis/pulls/9463 var nameWithOwner = ghPullRequest.getUrl().toString().split("/repos/")[1].split("/pulls")[0]; - var repository = repositoryRepository.findByNameWithOwner(nameWithOwner); + var repository = gitRepoRepository.findByNameWithOwner(nameWithOwner); if (repository != null) { result.setRepository(repository); } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/User.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/User.java similarity index 92% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/User.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/user/User.java index 746abce..b8c5069 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/User.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/User.java @@ -1,7 +1,6 @@ -package de.tum.cit.aet.helios.gitprovider.user; +package de.tum.cit.aet.helios.user; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntity; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,6 +8,8 @@ import lombok.ToString; import org.springframework.lang.NonNull; +import de.tum.cit.aet.helios.github.BaseGitServiceEntity; + @Entity @Table(name = "user", schema = "public") diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserInfoDTO.java similarity index 92% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserInfoDTO.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserInfoDTO.java index 0d6aacd..23008ea 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.user; +package de.tum.cit.aet.helios.user; import com.fasterxml.jackson.annotation.JsonInclude; import org.springframework.lang.NonNull; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserRepository.java similarity index 73% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserRepository.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserRepository.java index 3320c5f..a4a3aa5 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/UserRepository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/UserRepository.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.user; +package de.tum.cit.aet.helios.user; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java similarity index 94% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserConverter.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java index 1a54215..120e429 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java @@ -1,14 +1,15 @@ -package de.tum.cit.aet.helios.gitprovider.user.github; +package de.tum.cit.aet.helios.user.github; -import de.tum.cit.aet.helios.gitprovider.common.github.BaseGitServiceEntityConverter; -import de.tum.cit.aet.helios.gitprovider.user.User; import org.kohsuke.github.GHUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; +import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; +import de.tum.cit.aet.helios.user.User; + import java.io.IOException; @Component diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java similarity index 92% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserSyncService.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java index 44f411e..a046214 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/user/github/GitHubUserSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java @@ -1,8 +1,5 @@ -package de.tum.cit.aet.helios.gitprovider.user.github; +package de.tum.cit.aet.helios.user.github; -import de.tum.cit.aet.helios.gitprovider.common.github.DateUtil; -import de.tum.cit.aet.helios.gitprovider.user.User; -import de.tum.cit.aet.helios.gitprovider.user.UserRepository; import jakarta.transaction.Transactional; import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; @@ -10,6 +7,10 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import de.tum.cit.aet.helios.user.User; +import de.tum.cit.aet.helios.user.UserRepository; +import de.tum.cit.aet.helios.util.DateUtil; + import java.io.IOException; @Service diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/DateUtil.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/util/DateUtil.java similarity index 82% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/DateUtil.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/util/DateUtil.java index 701177b..aa0a574 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitprovider/common/github/DateUtil.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/util/DateUtil.java @@ -1,4 +1,4 @@ -package de.tum.cit.aet.helios.gitprovider.common.github; +package de.tum.cit.aet.helios.util; import java.time.OffsetDateTime; import java.time.ZoneOffset; diff --git a/server/application-server/src/test/java/de/tum/cit/aet/helios/HeliosApplicationTests.java b/server/application-server/src/test/java/de/tum/cit/aet/helios/HeliosApplicationTests.java index 7eba40b..7f89588 100644 --- a/server/application-server/src/test/java/de/tum/cit/aet/helios/HeliosApplicationTests.java +++ b/server/application-server/src/test/java/de/tum/cit/aet/helios/HeliosApplicationTests.java @@ -1,6 +1,5 @@ package de.tum.cit.aet.helios; -import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest From e43571bf5283e7987b44324eb45115ae5c7bcf6f Mon Sep 17 00:00:00 2001 From: Stefan Nemeth Date: Sun, 24 Nov 2024 21:47:45 +0100 Subject: [PATCH 03/10] Add workflow run sync + webhook handling --- .../github/sync/GitHubDataSyncService.java | 17 +- .../aet/helios/pullrequest/PullRequest.java | 4 + .../cit/aet/helios/workflow/WorkflowRun.java | 141 ++++++++++++++++ .../workflow/WorkflowRunRepository.java | 9 ++ .../github/GitHubWorkflowRunConverter.java | 124 ++++++++++++++ .../github/GitHubWorkflowSyncService.java | 153 ++++++++++++++++++ 6 files changed, 441 insertions(+), 7 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRun.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRunRepository.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunConverter.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowSyncService.java diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java index e545d9c..ecd2972 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java @@ -4,9 +4,10 @@ import de.tum.cit.aet.helios.pullrequest.github.GitHubPullRequestSyncService; import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; import de.tum.cit.aet.helios.user.github.GitHubUserSyncService; +import de.tum.cit.aet.helios.workflow.github.GitHubWorkflowSyncService; import jakarta.transaction.Transactional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.log4j.Log4j2; + import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -14,10 +15,8 @@ import java.util.Optional; @Service +@Log4j2 public class GitHubDataSyncService { - - private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncService.class); - @Value("${monitoring.timeframe}") private int timeframe; @@ -28,15 +27,18 @@ public class GitHubDataSyncService { private final GitHubUserSyncService userSyncService; private final GitHubRepositorySyncService repositorySyncService; private final GitHubPullRequestSyncService pullRequestSyncService; + private final GitHubWorkflowSyncService workflowSyncService; public GitHubDataSyncService( DataSyncStatusRepository dataSyncStatusRepository, GitHubUserSyncService userSyncService, GitHubRepositorySyncService repositorySyncService, - GitHubPullRequestSyncService pullRequestSyncService) { + GitHubPullRequestSyncService pullRequestSyncService, + GitHubWorkflowSyncService workflowSyncService) { this.dataSyncStatusRepository = dataSyncStatusRepository; this.userSyncService = userSyncService; this.repositorySyncService = repositorySyncService; this.pullRequestSyncService = pullRequestSyncService; + this.workflowSyncService = workflowSyncService; } @Transactional @@ -52,7 +54,7 @@ public void syncData() { var cooldownTime = OffsetDateTime.now().minusMinutes(runOnStartupCooldownInMinutes); if (lastSync.isPresent() && lastSync.get().getStartTime().isAfter(cooldownTime)) { - logger.info("Skipping sync, last sync was less than {} minutes ago", runOnStartupCooldownInMinutes); + log.info("Skipping sync, last sync was less than {} minutes ago", runOnStartupCooldownInMinutes); return; } @@ -63,6 +65,7 @@ public void syncData() { pullRequestSyncService.syncPullRequestsOfAllRepositories(repositories, Optional.of(cutoffDate)); userSyncService.syncAllExistingUsers(); + workflowSyncService.syncRunsOfAllRepositories(repositories, Optional.of(cutoffDate)); var endTime = OffsetDateTime.now(); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java index 3fbf13b..d20cbbb 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/PullRequest.java @@ -12,6 +12,7 @@ import de.tum.cit.aet.helios.issue.Issue; import de.tum.cit.aet.helios.user.User; +import de.tum.cit.aet.helios.workflow.WorkflowRun; @Entity @DiscriminatorValue(value = "PULL_REQUEST") @@ -63,6 +64,9 @@ public boolean isPullRequest() { return true; } + @ManyToMany + private Set workflowRuns; + // Missing properties: // - PullRequestReview // - PullRequestReviewComment diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRun.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRun.java new file mode 100644 index 0000000..8fbae93 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRun.java @@ -0,0 +1,141 @@ +package de.tum.cit.aet.helios.workflow; + +import java.time.OffsetDateTime; +import java.util.Optional; +import java.util.Set; + +import de.tum.cit.aet.helios.github.BaseGitServiceEntity; +import de.tum.cit.aet.helios.gitrepo.GitRepository; +import de.tum.cit.aet.helios.pullrequest.PullRequest; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.*; + +@Entity +@Table(name = "workflow_run") +@Getter +@Setter +@NoArgsConstructor +@ToString(callSuper = true) +public class WorkflowRun extends BaseGitServiceEntity { + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "repository_id") + private GitRepository repository; + + @ManyToMany + private Set pullRequests; + + private String name; + + private String displayTitle; + + private long runNumber; + + private long workflowId; + + private long runAttempt; + + private OffsetDateTime runStartedAt; + + private String htmlUrl; + + private String jobsUrl; + + private String logsUrl; + + private String checkSuiteUrl; + + private String artifactsUrl; + + private String cancelUrl; + + private String rerunUrl; + + private String workflowUrl; + + private String headBranch; + + private String headSha; + + @NonNull + @Enumerated(EnumType.STRING) + private Status status; + + @Enumerated(EnumType.STRING) + private Conclusion conclusion; + + public Optional getConclusion() { + return Optional.ofNullable(conclusion); + } + + public void setConclusion(Optional conclusion) { + this.conclusion = conclusion.orElse(null); + } + + public enum Status { + /** The queued. */ + QUEUED, + /** The in progress. */ + IN_PROGRESS, + /** The completed. */ + COMPLETED, + /** The action required. */ + ACTION_REQUIRED, + /** The cancelled. */ + CANCELLED, + /** The failure. */ + FAILURE, + /** The neutral. */ + NEUTRAL, + /** The skipped. */ + SKIPPED, + /** The stale. */ + STALE, + /** The success. */ + SUCCESS, + /** The timed out. */ + TIMED_OUT, + /** The requested. */ + REQUESTED, + /** The waiting. */ + WAITING, + /** The pending. */ + PENDING, + /** The unknown. */ + UNKNOWN; + } + + public enum Conclusion { + /** The action required. */ + ACTION_REQUIRED, + /** The cancelled. */ + CANCELLED, + /** The failure. */ + FAILURE, + /** The neutral. */ + NEUTRAL, + /** The success. */ + SUCCESS, + /** The skipped. */ + SKIPPED, + /** The stale. */ + STALE, + /** The timed out. */ + TIMED_OUT, + /** Start up fail */ + STARTUP_FAILURE, + /** The unknown. */ + UNKNOWN; + } + + // Missing: + // - event + +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRunRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRunRepository.java new file mode 100644 index 0000000..8698524 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/WorkflowRunRepository.java @@ -0,0 +1,9 @@ +package de.tum.cit.aet.helios.workflow; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface WorkflowRunRepository extends JpaRepository { + +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunConverter.java new file mode 100644 index 0000000..36f0460 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunConverter.java @@ -0,0 +1,124 @@ +package de.tum.cit.aet.helios.workflow.github; + +import java.io.IOException; +import java.util.Optional; + +import org.kohsuke.github.GHWorkflowRun; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; +import de.tum.cit.aet.helios.util.DateUtil; +import de.tum.cit.aet.helios.workflow.WorkflowRun; +import lombok.extern.log4j.Log4j2; + +@Log4j2 +@Component +public class GitHubWorkflowRunConverter extends BaseGitServiceEntityConverter { + + @Override + public WorkflowRun convert(@NonNull GHWorkflowRun source) { + return update(source, new WorkflowRun()); + } + + @Override + public WorkflowRun update(@NonNull GHWorkflowRun source, @NonNull WorkflowRun workflowRun) { + convertBaseFields(source, workflowRun); + workflowRun.setName(source.getName()); + workflowRun.setDisplayTitle(source.getDisplayTitle()); + workflowRun.setRunNumber(source.getRunNumber()); + workflowRun.setWorkflowId(source.getWorkflowId()); + workflowRun.setRunAttempt(source.getRunAttempt()); + try { + workflowRun.setRunStartedAt(DateUtil.convertToOffsetDateTime(source.getRunStartedAt())); + } catch (IOException e) { + log.error("Failed to convert runStartedAt field for source {}: {}", source.getId(), e.getMessage()); + } + try { + workflowRun.setHtmlUrl(source.getHtmlUrl().toString()); + } catch (IOException e) { + log.error("Failed to convert htmlUrl field for source {}: {}", source.getId(), e.getMessage()); + } + try { + workflowRun.setHtmlUrl(source.getHtmlUrl().toString()); + } catch (IOException e) { + log.error("Failed to convert htmlUrl field for source {}: {}", source.getId(), e.getMessage()); + } + workflowRun.setJobsUrl(source.getJobsUrl().toString()); + workflowRun.setLogsUrl(source.getLogsUrl().toString()); + workflowRun.setCheckSuiteUrl(source.getCheckSuiteUrl().toString()); + workflowRun.setArtifactsUrl(source.getArtifactsUrl().toString()); + workflowRun.setCancelUrl(source.getCancelUrl().toString()); + workflowRun.setRerunUrl(source.getRerunUrl().toString()); + workflowRun.setWorkflowUrl(source.getWorkflowUrl().toString()); + workflowRun.setHeadBranch(source.getHeadBranch().toString()); + workflowRun.setHeadSha(source.getHeadSha()); + workflowRun.setStatus(convertStatus(source.getStatus())); + workflowRun.setConclusion(Optional.ofNullable(source.getConclusion()).map(this::convertConclusion)); + + return workflowRun; + } + + private WorkflowRun.Status convertStatus(GHWorkflowRun.Status status) { + switch (status) { + case ACTION_REQUIRED: + return WorkflowRun.Status.ACTION_REQUIRED; + case COMPLETED: + return WorkflowRun.Status.COMPLETED; + case IN_PROGRESS: + return WorkflowRun.Status.IN_PROGRESS; + case QUEUED: + return WorkflowRun.Status.QUEUED; + case REQUESTED: + return WorkflowRun.Status.REQUESTED; + case CANCELLED: + return WorkflowRun.Status.CANCELLED; + case FAILURE: + return WorkflowRun.Status.FAILURE; + case NEUTRAL: + return WorkflowRun.Status.NEUTRAL; + case PENDING: + return WorkflowRun.Status.PENDING; + case SKIPPED: + return WorkflowRun.Status.SKIPPED; + case STALE: + return WorkflowRun.Status.STALE; + case SUCCESS: + return WorkflowRun.Status.SUCCESS; + case TIMED_OUT: + return WorkflowRun.Status.TIMED_OUT; + case WAITING: + return WorkflowRun.Status.WAITING; + default: + case UNKNOWN: + return WorkflowRun.Status.UNKNOWN; + } + } + + private WorkflowRun.Conclusion convertConclusion(GHWorkflowRun.Conclusion conclusion) { + switch (conclusion) { + case ACTION_REQUIRED: + return WorkflowRun.Conclusion.ACTION_REQUIRED; + case CANCELLED: + return WorkflowRun.Conclusion.CANCELLED; + case FAILURE: + return WorkflowRun.Conclusion.FAILURE; + case NEUTRAL: + return WorkflowRun.Conclusion.NEUTRAL; + case SKIPPED: + return WorkflowRun.Conclusion.SKIPPED; + case STALE: + return WorkflowRun.Conclusion.STALE; + case STARTUP_FAILURE: + return WorkflowRun.Conclusion.STARTUP_FAILURE; + case SUCCESS: + return WorkflowRun.Conclusion.SUCCESS; + case TIMED_OUT: + return WorkflowRun.Conclusion.TIMED_OUT; + default: + case UNKNOWN: + return WorkflowRun.Conclusion.UNKNOWN; + } + } + +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowSyncService.java new file mode 100644 index 0000000..3e68b3b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowSyncService.java @@ -0,0 +1,153 @@ +package de.tum.cit.aet.helios.workflow.github; + +import java.io.IOException; +import java.sql.Date; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.kohsuke.github.GHRepository; +import org.kohsuke.github.GHWorkflowRun; +import org.springframework.stereotype.Service; + +import de.tum.cit.aet.helios.gitrepo.GitRepoRepository; +import de.tum.cit.aet.helios.pullrequest.PullRequest; +import de.tum.cit.aet.helios.pullrequest.PullRequestRepository; +import de.tum.cit.aet.helios.util.DateUtil; +import de.tum.cit.aet.helios.workflow.WorkflowRun; +import de.tum.cit.aet.helios.workflow.WorkflowRunRepository; +import jakarta.transaction.Transactional; +import lombok.extern.log4j.Log4j2; + +@Log4j2 +@Service +public class GitHubWorkflowSyncService { + private final WorkflowRunRepository workflowRunRepository; + private final GitHubWorkflowRunConverter workflowRunConverter; + private final GitRepoRepository gitRepoRepository; + private final PullRequestRepository pullRequestRepository; + + public GitHubWorkflowSyncService( + WorkflowRunRepository workflowRunRepository, + GitHubWorkflowRunConverter workflowRunConverter, + GitRepoRepository gitRepoRepository, + PullRequestRepository pullRequestRepository) { + this.workflowRunRepository = workflowRunRepository; + this.workflowRunConverter = workflowRunConverter; + this.gitRepoRepository = gitRepoRepository; + this.pullRequestRepository = pullRequestRepository; + } + + /** + * Synchronizes all worfklwo runs from the specified GitHub repositories. + * + * @param repositories the list of GitHub repositories to sync workflow runs + * from + * @param since an optional date to filter pull requests by their last + * update + * @return a list of GitHub workflow runs that were successfully fetched and + * processed + */ + public List syncRunsOfAllRepositories(List repositories, + Optional since) { + return repositories.stream() + .map(repository -> syncRunsOfRepository(repository, since)) + .flatMap(List::stream) + .toList(); + } + + /** + * Synchronizes all workflow runs from a specific GitHub repository. + * + * @param repository the GitHub repository to sync workflow runs from + * @param since an optional date to filter workflow runs by their last + * update + * @return a list of GitHub workflow runs requests that were successfully fetched and + * processed + */ + public List syncRunsOfRepository(GHRepository repository, Optional since) { + var iterator = repository.queryWorkflowRuns() + .list() + .withPageSize(100) + .iterator(); + + var sinceDate = since.map(date -> Date.from(date.toInstant())); + + var workflowRuns = new ArrayList(); + + while (iterator.hasNext()) { + var ghPullRequests = iterator.nextPage(); + var keepPullRequests = ghPullRequests.stream() + .filter(pullRequest -> { + try { + return sinceDate.isEmpty() || pullRequest.getUpdatedAt().after(sinceDate.get()); + } catch (IOException e) { + log.error("Failed to filter workflow run {}: {}", pullRequest.getId(), e.getMessage()); + return false; + } + }) + .toList(); + + workflowRuns.addAll(keepPullRequests); + if (keepPullRequests.size() != ghPullRequests.size()) { + break; + } + } + + workflowRuns.forEach(this::processRun); + + return workflowRuns; + } + + @Transactional + public WorkflowRun processRun(GHWorkflowRun ghWorkflowRun) { + var result = workflowRunRepository.findById(ghWorkflowRun.getId()) + .map(workflowRun -> { + try { + if (workflowRun.getUpdatedAt() == null || workflowRun.getUpdatedAt() + .isBefore(DateUtil.convertToOffsetDateTime(ghWorkflowRun.getUpdatedAt()))) { + return workflowRunConverter.update(ghWorkflowRun, workflowRun); + } + return workflowRun; + } catch (IOException e) { + log.error("Failed to update worfklow run {}: {}", ghWorkflowRun.getId(), e.getMessage()); + return null; + } + }).orElseGet(() -> workflowRunConverter.convert(ghWorkflowRun)); + + if (result == null) { + return null; + } + + // Link with existing repository if not already linked + if (result.getRepository() == null) { + var nameWithOwner = ghWorkflowRun.getRepository().getFullName(); + var repository = gitRepoRepository.findByNameWithOwner(nameWithOwner); + + if (repository != null) { + result.setRepository(repository); + } + } + + try { + Set pullRequests = new HashSet<>(); + + ghWorkflowRun.getPullRequests().forEach(pullRequest -> { + var pr = pullRequestRepository.findById(pullRequest.getId()); + + if (!pr.isEmpty()) { + pullRequests.add(pr.get()); + } + }); + + result.setPullRequests(pullRequests); + } catch (IOException e) { + log.error("Failed to process pull requests for workflow run {}: {}", ghWorkflowRun.getId(), e.getMessage()); + } + + return workflowRunRepository.save(result); + } +} From 93c0dd674aad982d9e402f05630d4d25fb75c103 Mon Sep 17 00:00:00 2001 From: Stefan Nemeth Date: Sun, 24 Nov 2024 21:48:14 +0100 Subject: [PATCH 04/10] Use lombok log4j2 annotation --- .../github/BaseGitServiceEntityConverter.java | 10 ++-- .../cit/aet/helios/github/GitHubConfig.java | 25 ++++---- .../helios/github/GitHubMessageHandler.java | 14 ++--- .../cit/aet/helios/github/GitHubService.java | 10 ++-- .../github/sync/GitHubDataSyncScheduler.java | 15 +++-- .../github/GitHubRepositoryConverter.java | 9 +-- .../github/GitHubRepositorySyncService.java | 11 ++-- .../github/GitHubIssueMessageHandler.java | 8 +-- .../tum/cit/aet/helios/nats/NatsConfig.java | 10 ++-- .../aet/helios/nats/NatsConsumerService.java | 29 +++++----- .../NatsNotificationPublisherService.java | 20 +++---- .../github/GitHubPullRequestConverter.java | 26 ++++----- .../GitHubPullRequestMessageHandler.java | 8 +-- .../github/GitHubPullRequestSyncService.java | 17 +++--- .../user/github/GitHubUserConverter.java | 22 ++++--- .../user/github/GitHubUserSyncService.java | 11 ++-- .../GitHubWorkflowRunMessageHandler.java | 58 +++++++++++++++++++ 17 files changed, 165 insertions(+), 138 deletions(-) create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java index c4da0d1..dd46d0f 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/BaseGitServiceEntityConverter.java @@ -1,22 +1,20 @@ package de.tum.cit.aet.helios.github; import org.kohsuke.github.GHObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.lang.NonNull; import de.tum.cit.aet.helios.util.DateUtil; +import lombok.extern.log4j.Log4j2; import java.io.IOException; @ReadingConverter +@Log4j2 public abstract class BaseGitServiceEntityConverter implements Converter { - private static final Logger logger = LoggerFactory.getLogger(BaseGitServiceEntityConverter.class); - abstract public T update(@NonNull S source, @NonNull T target); protected void convertBaseFields(S source, T target) { @@ -30,14 +28,14 @@ protected void convertBaseFields(S source, T target) { try { target.setCreatedAt(DateUtil.convertToOffsetDateTime(source.getCreatedAt())); } catch (IOException e) { - logger.error("Failed to convert createdAt field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert createdAt field for source {}: {}", source.getId(), e.getMessage()); target.setCreatedAt(null); } try { target.setUpdatedAt(DateUtil.convertToOffsetDateTime(source.getUpdatedAt())); } catch (IOException e) { - logger.error("Failed to convert updatedAt field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert updatedAt field for source {}: {}", source.getId(), e.getMessage()); target.setUpdatedAt(null); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java index c534234..db28114 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubConfig.java @@ -1,14 +1,13 @@ package de.tum.cit.aet.helios.github; import lombok.Getter; +import lombok.extern.log4j.Log4j2; import okhttp3.Cache; import okhttp3.OkHttpClient; import okhttp3.logging.HttpLoggingInterceptor; import org.kohsuke.github.GitHub; import org.kohsuke.github.GitHubBuilder; import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -19,10 +18,8 @@ import java.util.concurrent.TimeUnit; @Configuration +@Log4j2 public class GitHubConfig { - - private static final Logger logger = LoggerFactory.getLogger(GitHubConfig.class); - @Getter @Value("${github.organizationName}") private String organizationName; @@ -48,17 +45,17 @@ public GitHubConfig(Environment environment) { @Bean public GitHub createGitHubClientWithCache() { if (ghAuthToken == null || ghAuthToken.isEmpty()) { - logger.error("GitHub auth token is not provided! GitHub client will be disabled."); + log.error("GitHub auth token is not provided! GitHub client will be disabled."); return GitHub.offline(); } // Set up a logging interceptor for debugging HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); if (environment.matchesProfiles("debug")) { - logger.warn("The requests to GitHub will be logged with the full body. This exposes sensitive data such as OAuth tokens. Use only for debugging!"); + log.warn("The requests to GitHub will be logged with the full body. This exposes sensitive data such as OAuth tokens. Use only for debugging!"); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } else { - logger.info("The requests to GitHub will be logged with the basic information."); + log.info("The requests to GitHub will be logged with the basic information."); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); } @@ -68,9 +65,9 @@ public GitHub createGitHubClientWithCache() { File cacheDir = new File("./build/github-cache"); Cache cache = new Cache(cacheDir, cacheSize * 1024L * 1024L); builder.cache(cache); - logger.info("Cache is enabled with TTL {} seconds and size {} MB", cacheTtl, cacheSize); + log.info("Cache is enabled with TTL {} seconds and size {} MB", cacheTtl, cacheSize); } else { - logger.info("Cache is disabled"); + log.info("Cache is disabled"); } // Configure OkHttpClient with the cache and logging @@ -88,16 +85,16 @@ public GitHub createGitHubClientWithCache() { .withOAuthToken(ghAuthToken) .build(); if (!github.isCredentialValid()) { - logger.error("Invalid GitHub credentials!"); + log.error("Invalid GitHub credentials!"); throw new IllegalStateException("Invalid GitHub credentials"); } - logger.info("GitHub client initialized successfully"); + log.info("GitHub client initialized successfully"); return github; } catch (IOException e) { - logger.error("Failed to initialize GitHub client: {}", e.getMessage()); + log.error("Failed to initialize GitHub client: {}", e.getMessage()); throw new RuntimeException("GitHub client initialization failed", e); } catch (Exception e) { - logger.error("An unexpected error occurred during GitHub client initialization: {}", e.getMessage()); + log.error("An unexpected error occurred during GitHub client initialization: {}", e.getMessage()); throw new RuntimeException("Unexpected error during GitHub client initialization", e); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java index 0ce4ab7..2f8f5f5 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubMessageHandler.java @@ -7,18 +7,16 @@ import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventPayload; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import io.nats.client.Message; import io.nats.client.MessageHandler; +import lombok.extern.log4j.Log4j2; + import org.springframework.stereotype.Component; @Component +@Log4j2 public abstract class GitHubMessageHandler implements MessageHandler { - - private static final Logger logger = LoggerFactory.getLogger(GitHubMessageHandler.class); - private final Class payloadType; protected GitHubMessageHandler(Class payloadType) { @@ -30,7 +28,7 @@ public void onMessage(Message msg) { String eventType = getHandlerEvent().name().toLowerCase(); String subject = msg.getSubject(); if (!subject.endsWith(eventType)) { - logger.error("Received message on unexpected subject: {}, expected to end with {}", subject, eventType); + log.error("Received message on unexpected subject: {}, expected to end with {}", subject, eventType); return; } @@ -40,9 +38,9 @@ public void onMessage(Message msg) { T eventPayload = GitHub.offline().parseEventPayload(reader, payloadType); handleEvent(eventPayload); } catch (IOException e) { - logger.error("Failed to parse payload for subject {}: {}", subject, e.getMessage(), e); + log.error("Failed to parse payload for subject {}: {}", subject, e.getMessage(), e); } catch (Exception e) { - logger.error("Unexpected error while handling message for subject {}: {}", subject, e.getMessage(), e); + log.error("Unexpected error while handling message for subject {}: {}", subject, e.getMessage(), e); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java index de9c92c..81dff0e 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/GitHubService.java @@ -4,19 +4,17 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHWorkflow; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import lombok.extern.log4j.Log4j2; + import java.io.IOException; import java.util.List; import java.util.Map; @Service +@Log4j2 public class GitHubService { - - private static final Logger logger = LoggerFactory.getLogger(GitHubService.class); - private final GitHub github; private final GitHubConfig gitHubConfig; @@ -38,7 +36,7 @@ public GHOrganization getOrganizationClient() throws IOException { if (gitHubOrganization == null) { final String organizationName = gitHubConfig.getOrganizationName(); if (organizationName == null || organizationName.isEmpty()) { - logger.error("No organization name provided in the configuration. GitHub organization client will not be initialized."); + log.error("No organization name provided in the configuration. GitHub organization client will not be initialized."); throw new RuntimeException("No organization name provided in the configuration."); } gitHubOrganization = github.getOrganization(organizationName); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java index 9250f7d..8e41469 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncScheduler.java @@ -1,7 +1,5 @@ package de.tum.cit.aet.helios.github.sync; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.event.EventListener; @@ -9,11 +7,12 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import lombok.extern.log4j.Log4j2; + @Order(value = 2) @Component +@Log4j2 public class GitHubDataSyncScheduler { - - private static final Logger logger = LoggerFactory.getLogger(GitHubDataSyncScheduler.class); private final GitHubDataSyncService dataSyncService; @Value("${monitoring.runOnStartup:true}") @@ -26,16 +25,16 @@ public GitHubDataSyncScheduler(GitHubDataSyncService dataSyncService) { @EventListener(ApplicationReadyEvent.class) public void run() { if (runOnStartup) { - logger.info("Starting initial GitHub data sync..."); + log.info("Starting initial GitHub data sync..."); dataSyncService.syncData(); - logger.info("Initial GitHub data sync completed."); + log.info("Initial GitHub data sync completed."); } } @Scheduled(cron = "${monitoring.repository-sync-cron}") public void syncDataCron() { - logger.info("Starting scheduled GitHub data sync..."); + log.info("Starting scheduled GitHub data sync..."); dataSyncService.syncData(); - logger.info("Scheduled GitHub data sync completed."); + log.info("Scheduled GitHub data sync completed."); } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java index 925b4ac..dbeff91 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositoryConverter.java @@ -2,20 +2,17 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHRepository.Visibility; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; import de.tum.cit.aet.helios.gitrepo.GitRepository; import de.tum.cit.aet.helios.util.DateUtil; +import lombok.extern.log4j.Log4j2; @Component +@Log4j2 public class GitHubRepositoryConverter extends BaseGitServiceEntityConverter { - - private static final Logger logger = LoggerFactory.getLogger(GitHubRepositoryConverter.class); - @Override public GitRepository convert(@NonNull GHRepository source) { return update(source, new GitRepository()); @@ -52,7 +49,7 @@ private GitRepository.Visibility convertVisibility(Visibility visibility) { case INTERNAL: return GitRepository.Visibility.INTERNAL; default: - logger.error("Unknown repository visibility: {}", visibility); + log.error("Unknown repository visibility: {}", visibility); return GitRepository.Visibility.UNKNOWN; } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java index 107f1bb..cae5fbb 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/gitrepo/github/GitHubRepositorySyncService.java @@ -1,10 +1,10 @@ package de.tum.cit.aet.helios.gitrepo.github; import jakarta.transaction.Transactional; +import lombok.extern.log4j.Log4j2; + import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -17,10 +17,9 @@ import java.util.Optional; @Service +@Log4j2 public class GitHubRepositorySyncService { - private static final Logger logger = LoggerFactory.getLogger(GitHubRepositorySyncService.class); - @Value("${monitoring.repositories}") private String[] repositoriesToMonitor; @@ -90,7 +89,7 @@ public Optional syncRepository(String nameWithOwner) { processRepository(repository); return Optional.of(repository); } catch (IOException e) { - logger.error("Failed to fetch repository {}: {}", nameWithOwner, e.getMessage()); + log.error("Failed to fetch repository {}: {}", nameWithOwner, e.getMessage()); return Optional.empty(); } } @@ -114,7 +113,7 @@ public GitRepository processRepository(GHRepository ghRepository) { } return repository; } catch (IOException e) { - logger.error("Failed to update repository {}: {}", ghRepository.getId(), e.getMessage()); + log.error("Failed to update repository {}: {}", ghRepository.getId(), e.getMessage()); return null; } }).orElseGet(() -> repositoryConverter.convert(ghRepository)); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java index 460a15d..cc8d6df 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/issue/github/GitHubIssueMessageHandler.java @@ -2,17 +2,15 @@ import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventPayload; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import lombok.extern.log4j.Log4j2; @Component +@Log4j2 public class GitHubIssueMessageHandler extends GitHubMessageHandler { - private static final Logger logger = LoggerFactory.getLogger(GitHubIssueMessageHandler.class); - private GitHubIssueMessageHandler() { super(GHEventPayload.Issue.class); } @@ -22,7 +20,7 @@ protected void handleEvent(GHEventPayload.Issue eventPayload) { var action = eventPayload.getAction(); var repository = eventPayload.getRepository(); var issue = eventPayload.getIssue(); - logger.info("Received issue event for repository: {}, issue: {}, action: {}", + log.info("Received issue event for repository: {}, issue: {}, action: {}", repository.getFullName(), issue.getNumber(), action); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java index 06dbdf9..2124646 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConfig.java @@ -1,7 +1,5 @@ package de.tum.cit.aet.helios.nats; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,12 +8,12 @@ import io.nats.client.Connection; import io.nats.client.Nats; import io.nats.client.Options; +import lombok.extern.log4j.Log4j2; @Configuration +@Log4j2 public class NatsConfig { - private static final Logger logger = LoggerFactory.getLogger(NatsConfig.class); - @Value("${nats.enabled}") private boolean isNatsEnabled; @@ -34,12 +32,12 @@ public NatsConfig(Environment env) { @Bean public Connection natsConnection() throws Exception { if (environment.matchesProfiles("openapi")) { - logger.info("NOpenAPI profile detected. Skipping NATS connection."); + log.info("No OpenAPI profile detected. Skipping NATS connection."); return null; } if (!isNatsEnabled) { - logger.info("NATS is disabled. Skipping NATS connection."); + log.info("NATS is disabled. Skipping NATS connection."); return null; } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java index 1ef4b66..f5a51d5 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsConsumerService.java @@ -15,6 +15,7 @@ import io.nats.client.StreamContext; import io.nats.client.api.ConsumerConfiguration; import io.nats.client.api.DeliverPolicy; +import lombok.extern.log4j.Log4j2; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; @@ -26,16 +27,12 @@ import org.springframework.context.event.EventListener; import org.springframework.core.annotation.Order; import org.kohsuke.github.GHEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @Order(value = 1) @Service +@Log4j2 public class NatsConsumerService { - - private static final Logger logger = LoggerFactory.getLogger(NatsConsumerService.class); - private static final int INITIAL_RECONNECT_DELAY_SECONDS = 2; @Value("${nats.enabled}") @@ -71,12 +68,12 @@ public NatsConsumerService(Environment environment, GitHubMessageHandlerRegistry @EventListener(ApplicationReadyEvent.class) public void init() { if (environment.matchesProfiles("openapi")) { - logger.info("OpenAPI profile detected. Skipping NATS initialization."); + log.info("OpenAPI profile detected. Skipping NATS initialization."); return; } if (!isNatsEnabled) { - logger.info("NATS is disabled. Skipping NATS initialization."); + log.info("NATS is disabled. Skipping NATS initialization."); return; } @@ -89,7 +86,7 @@ public void init() { setupConsumer(natsConnection); return; } catch (IOException | InterruptedException e) { - logger.error("NATS connection error: {}", e.getMessage(), e); + log.error("NATS connection error: {}", e.getMessage(), e); } } } @@ -107,7 +104,7 @@ private Options buildNatsOptions() { return Options.builder() .server(natsServer) .token(natsAuthToken.toCharArray()) - .connectionListener((conn, type) -> logger.info("Connection event - Server: {}, {}", + .connectionListener((conn, type) -> log.info("Connection event - Server: {}, {}", conn.getServerInfo().getPort(), type)) .maxReconnects(-1) .reconnectWait(Duration.ofSeconds(INITIAL_RECONNECT_DELAY_SECONDS)) @@ -128,7 +125,7 @@ private void setupConsumer(Connection connection) throws IOException, Interrupte } if (consumerContext == null) { - logger.info("Setting up consumer for subjects: {}", Arrays.toString(getSubjects())); + log.info("Setting up consumer for subjects: {}", Arrays.toString(getSubjects())); ConsumerConfiguration.Builder consumerConfigBuilder = ConsumerConfiguration.builder() .filterSubjects(getSubjects()) .deliverPolicy(DeliverPolicy.ByStartTime) @@ -141,14 +138,14 @@ private void setupConsumer(Connection connection) throws IOException, Interrupte ConsumerConfiguration consumerConfig = consumerConfigBuilder.build(); consumerContext = streamContext.createOrUpdateConsumer(consumerConfig); } else { - logger.info("Consumer already exists. Skipping consumer setup."); + log.info("Consumer already exists. Skipping consumer setup."); } MessageHandler handler = this::handleMessage; consumerContext.consume(handler); - logger.info("Successfully started consuming messages."); + log.info("Successfully started consuming messages."); } catch (JetStreamApiException e) { - logger.error("JetStream API exception: {}", e.getMessage(), e); + log.error("JetStream API exception: {}", e.getMessage(), e); throw new IOException("Failed to set up consumer.", e); } } @@ -161,7 +158,7 @@ private void handleMessage(Message msg) { GitHubMessageHandler eventHandler = handlerRegistry.getHandler(eventType); if (eventHandler == null) { - logger.warn("No handler found for event type: {}", eventType); + log.warn("No handler found for event type: {}", eventType); msg.ack(); return; } @@ -169,9 +166,9 @@ private void handleMessage(Message msg) { eventHandler.onMessage(msg); msg.ack(); } catch (IllegalArgumentException e) { - logger.error("Invalid event type in subject '{}': {}", msg.getSubject(), e.getMessage()); + log.error("Invalid event type in subject '{}': {}", msg.getSubject(), e.getMessage()); } catch (Exception e) { - logger.error("Error processing message: {}", e.getMessage(), e); + log.error("Error processing message: {}", e.getMessage(), e); } finally { msg.ack(); } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java index fa3ff49..a1076aa 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/nats/NatsNotificationPublisherService.java @@ -5,9 +5,8 @@ import io.nats.client.Nats; import io.nats.client.Options; import io.nats.client.impl.NatsMessage; +import lombok.extern.log4j.Log4j2; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.boot.context.event.ApplicationReadyEvent; @@ -18,10 +17,9 @@ import java.time.Duration; @Service +@Log4j2 public class NatsNotificationPublisherService { - private static final Logger logger = LoggerFactory.getLogger(NatsNotificationPublisherService.class); - private Connection natsConnection; private JetStream jetStream; @@ -37,7 +35,7 @@ public class NatsNotificationPublisherService { @EventListener(ApplicationReadyEvent.class) public void init() { if (!isNatsEnabled) { - logger.info("NATS is disabled. Skipping initialization."); + log.info("NATS is disabled. Skipping initialization."); return; } @@ -48,11 +46,11 @@ public void init() { try { natsConnection = Nats.connect(options); jetStream = natsConnection.jetStream(); - logger.info("Connected to NATS at {}", natsServer); + log.info("Connected to NATS at {}", natsServer); // publishDummyNotification(); return; } catch (IOException | InterruptedException e) { - logger.error("NATS connection error: {}", e.getMessage(), e); + log.error("NATS connection error: {}", e.getMessage(), e); } } } @@ -67,7 +65,7 @@ private Options buildNatsOptions() { return Options.builder() .server(natsServer) .token(natsAuthToken.toCharArray()) - .connectionListener((conn, type) -> logger.info("Connection event - Server: {}, {}", + .connectionListener((conn, type) -> log.info("Connection event - Server: {}, {}", conn.getServerInfo().getPort(), type)) .maxReconnects(-1) .reconnectWait(Duration.ofSeconds(2)) @@ -80,16 +78,16 @@ public void publishNotification(String subject, byte[] message) throws IOExcepti .data(message) .build(); natsConnection.publish(msg); - logger.info("Published message to subject '{}'", "notification." + subject); + log.info("Published message to subject '{}'", "notification." + subject); } private void publishDummyNotification() { String dummyMessage = "This is a dummy notification message."; try { publishNotification("dummy", dummyMessage.getBytes(StandardCharsets.UTF_8)); - logger.info("Dummy notification message published successfully."); + log.info("Dummy notification message published successfully."); } catch (IOException | InterruptedException e) { - logger.error("Failed to publish dummy notification message: {}", e.getMessage(), e); + log.error("Failed to publish dummy notification message: {}", e.getMessage(), e); } } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java index 62b1c0d..d8cfdb6 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestConverter.java @@ -1,8 +1,6 @@ package de.tum.cit.aet.helios.pullrequest.github; import org.kohsuke.github.GHPullRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @@ -10,14 +8,14 @@ import de.tum.cit.aet.helios.issue.github.GitHubIssueConverter; import de.tum.cit.aet.helios.pullrequest.PullRequest; import de.tum.cit.aet.helios.util.DateUtil; +import lombok.extern.log4j.Log4j2; import java.io.IOException; @Component +@Log4j2 public class GitHubPullRequestConverter extends BaseGitServiceEntityConverter { - private static final Logger logger = LoggerFactory.getLogger(GitHubPullRequestConverter.class); - private final GitHubIssueConverter issueConverter; public GitHubPullRequestConverter(GitHubIssueConverter issueConverter) { @@ -37,58 +35,58 @@ public PullRequest update(@NonNull GHPullRequest source, @NonNull PullRequest pu try { pullRequest.setMergeCommitSha(source.getMergeCommitSha()); } catch (IOException e) { - logger.error("Failed to convert mergeCommitSha field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert mergeCommitSha field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setDraft(source.isDraft()); } catch (IOException e) { - logger.error("Failed to convert draft field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert draft field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setMerged(source.isMerged()); } catch (IOException e) { - logger.error("Failed to convert merged field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert merged field for source {}: {}", source.getId(), e.getMessage()); } try { if (source.getMergeable() != null) { pullRequest.setIsMergeable(Boolean.TRUE.equals(source.getMergeable())); } } catch (IOException e) { - logger.error("Failed to convert mergeable field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert mergeable field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setMergeableState(source.getMergeableState()); } catch (IOException e) { - logger.error("Failed to convert mergeableState field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert mergeableState field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setMaintainerCanModify(source.canMaintainerModify()); } catch (IOException e) { - logger.error("Failed to convert maintainerCanModify field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert maintainerCanModify field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setCommits(source.getCommits()); } catch (IOException e) { - logger.error("Failed to convert commits field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert commits field for source {}: {}", source.getId(), e.getMessage()); } try { if (pullRequest.getAdditions() == 0 || source.getAdditions() != 0) { pullRequest.setAdditions(source.getAdditions()); } } catch (IOException e) { - logger.error("Failed to convert additions field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert additions field for source {}: {}", source.getId(), e.getMessage()); } try { if (pullRequest.getDeletions() == 0 || source.getDeletions() != 0) { pullRequest.setDeletions(source.getDeletions()); } } catch (IOException e) { - logger.error("Failed to convert deletions field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert deletions field for source {}: {}", source.getId(), e.getMessage()); } try { pullRequest.setChangedFiles(source.getChangedFiles()); } catch (IOException e) { - logger.error("Failed to convert changedFiles field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert changedFiles field for source {}: {}", source.getId(), e.getMessage()); } return pullRequest; diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java index 9a48cc4..028c8a7 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestMessageHandler.java @@ -2,18 +2,16 @@ import org.kohsuke.github.GHEvent; import org.kohsuke.github.GHEventPayload; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import de.tum.cit.aet.helios.github.GitHubMessageHandler; import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; +import lombok.extern.log4j.Log4j2; @Component +@Log4j2 public class GitHubPullRequestMessageHandler extends GitHubMessageHandler { - private static final Logger logger = LoggerFactory.getLogger(GitHubPullRequestMessageHandler.class); - private final GitHubPullRequestSyncService pullRequestSyncService; private final GitHubRepositorySyncService repositorySyncService; @@ -27,7 +25,7 @@ private GitHubPullRequestMessageHandler( @Override protected void handleEvent(GHEventPayload.PullRequest eventPayload) { - logger.info("Received pull request event for repository: {}, pull request: {}, action: {}", + log.info("Received pull request event for repository: {}, pull request: {}, action: {}", eventPayload.getRepository().getFullName(), eventPayload.getPullRequest().getNumber(), eventPayload.getAction()); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java index 280aec8..ea34591 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/pullrequest/github/GitHubPullRequestSyncService.java @@ -2,13 +2,13 @@ import jakarta.transaction.Transactional; +import lombok.extern.log4j.Log4j2; + import org.kohsuke.github.GHDirection; import org.kohsuke.github.GHIssueState; import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHPullRequestQueryBuilder.Sort; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import de.tum.cit.aet.helios.gitrepo.GitRepoRepository; @@ -24,10 +24,9 @@ import java.util.*; @Service +@Log4j2 public class GitHubPullRequestSyncService { - private static final Logger logger = LoggerFactory.getLogger(GitHubPullRequestSyncService.class); - private final PullRequestRepository pullRequestRepository; private final GitRepoRepository gitRepoRepository; private final UserRepository userRepository; @@ -93,7 +92,7 @@ public List syncPullRequestsOfRepository(GHRepository repository, try { return sinceDate.isEmpty() || pullRequest.getUpdatedAt().after(sinceDate.get()); } catch (IOException e) { - logger.error("Failed to filter pull request {}: {}", pullRequest.getId(), e.getMessage()); + log.error("Failed to filter pull request {}: {}", pullRequest.getId(), e.getMessage()); return false; } }) @@ -131,7 +130,7 @@ public PullRequest processPullRequest(GHPullRequest ghPullRequest) { } return pullRequest; } catch (IOException e) { - logger.error("Failed to update pull request {}: {}", ghPullRequest.getId(), e.getMessage()); + log.error("Failed to update pull request {}: {}", ghPullRequest.getId(), e.getMessage()); return null; } }).orElseGet(() -> pullRequestConverter.convert(ghPullRequest)); @@ -158,7 +157,7 @@ public PullRequest processPullRequest(GHPullRequest ghPullRequest) { .orElseGet(() -> userRepository.save(userConverter.convert(author))); result.setAuthor(resultAuthor); } catch (IOException e) { - logger.error("Failed to link author for pull request {}: {}", ghPullRequest.getId(), e.getMessage()); + log.error("Failed to link author for pull request {}: {}", ghPullRequest.getId(), e.getMessage()); } // Link assignees @@ -183,7 +182,7 @@ public PullRequest processPullRequest(GHPullRequest ghPullRequest) { result.setMergedBy(null); } } catch (IOException e) { - logger.error("Failed to link merged by user for pull request {}: {}", ghPullRequest.getId(), + log.error("Failed to link merged by user for pull request {}: {}", ghPullRequest.getId(), e.getMessage()); } @@ -199,7 +198,7 @@ public PullRequest processPullRequest(GHPullRequest ghPullRequest) { result.getRequestedReviewers().clear(); result.getRequestedReviewers().addAll(resultRequestedReviewers); } catch (IOException e) { - logger.error("Failed to link requested reviewers for pull request {}: {}", ghPullRequest.getId(), + log.error("Failed to link requested reviewers for pull request {}: {}", ghPullRequest.getId(), e.getMessage()); } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java index 120e429..4a14d6b 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserConverter.java @@ -2,21 +2,19 @@ import org.kohsuke.github.GHUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; import de.tum.cit.aet.helios.github.BaseGitServiceEntityConverter; import de.tum.cit.aet.helios.user.User; +import lombok.extern.log4j.Log4j2; import java.io.IOException; @Component +@Log4j2 public class GitHubUserConverter extends BaseGitServiceEntityConverter { - private static final Logger logger = LoggerFactory.getLogger(GitHubUserConverter.class); - @Override public User convert(@NonNull GHUser source) { return update(source, new User()); @@ -32,43 +30,43 @@ public User update(@NonNull GHUser source, @NonNull User user) { try { user.setName(source.getName() != null ? source.getName() : source.getLogin()); } catch (IOException e) { - logger.error("Failed to convert user name field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user name field for source {}: {}", source.getId(), e.getMessage()); user.setName(source.getLogin()); } try { user.setCompany(source.getCompany()); } catch (IOException e) { - logger.error("Failed to convert user company field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user company field for source {}: {}", source.getId(), e.getMessage()); } try { user.setBlog(source.getBlog()); } catch (IOException e) { - logger.error("Failed to convert user blog field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user blog field for source {}: {}", source.getId(), e.getMessage()); } try { user.setLocation(source.getLocation()); } catch (IOException e) { - logger.error("Failed to convert user location field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user location field for source {}: {}", source.getId(), e.getMessage()); } try { user.setEmail(source.getEmail()); } catch (IOException e) { - logger.error("Failed to convert user email field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user email field for source {}: {}", source.getId(), e.getMessage()); } try { user.setType(convertUserType(source.getType())); } catch (IOException e) { - logger.error("Failed to convert user type field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user type field for source {}: {}", source.getId(), e.getMessage()); } try { user.setFollowers(source.getFollowersCount()); } catch (IOException e) { - logger.error("Failed to convert user followers field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user followers field for source {}: {}", source.getId(), e.getMessage()); } try { user.setFollowing(source.getFollowingCount()); } catch (IOException e) { - logger.error("Failed to convert user following field for source {}: {}", source.getId(), e.getMessage()); + log.error("Failed to convert user following field for source {}: {}", source.getId(), e.getMessage()); } return user; } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java index a046214..d3c901b 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/user/github/GitHubUserSyncService.java @@ -1,10 +1,10 @@ package de.tum.cit.aet.helios.user.github; import jakarta.transaction.Transactional; +import lombok.extern.log4j.Log4j2; + import org.kohsuke.github.GHUser; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import de.tum.cit.aet.helios.user.User; @@ -14,10 +14,9 @@ import java.io.IOException; @Service +@Log4j2 public class GitHubUserSyncService { - private static final Logger logger = LoggerFactory.getLogger(GitHubUserSyncService.class); - private final GitHub github; private final UserRepository userRepository; private final GitHubUserConverter userConverter; @@ -52,7 +51,7 @@ public void syncUser(String login) { try { processUser(github.getUser(login)); } catch (IOException e) { - logger.error("Failed to fetch user {}: {}", login, e.getMessage()); + log.error("Failed to fetch user {}: {}", login, e.getMessage()); } } @@ -75,7 +74,7 @@ public User processUser(GHUser ghUser) { } return user; } catch (IOException e) { - logger.error("Failed to update repository {}: {}", ghUser.getId(), e.getMessage()); + log.error("Failed to update repository {}: {}", ghUser.getId(), e.getMessage()); return null; } }).orElseGet(() -> userConverter.convert(ghUser)); diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java new file mode 100644 index 0000000..f64b7be --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java @@ -0,0 +1,58 @@ +package de.tum.cit.aet.helios.workflow.github; + +import org.kohsuke.github.GHEvent; +import org.kohsuke.github.GHEventPayload; +import org.springframework.stereotype.Component; + +import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; +import de.tum.cit.aet.helios.pullrequest.github.GitHubPullRequestSyncService; +import lombok.extern.log4j.Log4j2; + +@Log4j2 +@Component +public class GitHubWorkflowRunMessageHandler extends GitHubMessageHandler { + private final GitHubRepositorySyncService repositorySyncService; + private final GitHubPullRequestSyncService pullRequestSyncService; + private final GitHubWorkflowSyncService workflowSyncService; + + private GitHubWorkflowRunMessageHandler( + GitHubWorkflowSyncService workflowSyncService, + GitHubRepositorySyncService repositorySyncService, + GitHubPullRequestSyncService pullRequestSyncService) { + super(GHEventPayload.WorkflowRun.class); + + this.workflowSyncService = workflowSyncService; + this.repositorySyncService = repositorySyncService; + this.pullRequestSyncService = pullRequestSyncService; + } + + @Override + protected void handleEvent(GHEventPayload.WorkflowRun eventPayload) { + var action = eventPayload.getAction(); + var repository = eventPayload.getRepository(); + var run = eventPayload.getWorkflowRun(); + + log.info("Received worfklow run event for repository: {}, workflow run: {}, action: {}", + repository.getFullName(), + run.getUrl(), + action); + + repositorySyncService.processRepository(eventPayload.getRepository()); + + try { + run.getPullRequests().forEach(pullRequest -> { + pullRequestSyncService.processPullRequest(pullRequest); + }); + } catch (Exception e) { + log.error("Failed to process pull requests for workflow run {}: {}", run.getUrl(), e.getMessage()); + } + + workflowSyncService.processRun(run); + } + + @Override + protected GHEvent getHandlerEvent() { + return GHEvent.WORKFLOW_RUN; + } +} From 52cbefe8be5ea4be695a70b76fba043be29fe121 Mon Sep 17 00:00:00 2001 From: Turker Koc Date: Tue, 26 Nov 2024 01:34:32 +0100 Subject: [PATCH 05/10] github branch controller init --- .../de/tum/cit/aet/helios/branch/Branch.java | 42 +++++++++++++ .../aet/helios/branch/BranchBaseInfoDTO.java | 24 ++++++++ .../aet/helios/branch/BranchController.java | 38 ++++++++++++ .../cit/aet/helios/branch/BranchInfoDTO.java | 36 +++++++++++ .../aet/helios/branch/BranchRepository.java | 9 +++ .../cit/aet/helios/branch/BranchService.java | 28 +++++++++ .../github/GitHubBranchMessageHandler.java | 61 +++++++++++++++++++ 7 files changed, 238 insertions(+) create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java new file mode 100644 index 0000000..86c6c4d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java @@ -0,0 +1,42 @@ +package de.tum.cit.aet.helios.branch; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.time.OffsetDateTime; + +import de.tum.cit.aet.helios.gitrepo.GitRepository; +import de.tum.cit.aet.helios.user.User; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@ToString +public class Branch { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + private boolean isProtected; + + @ManyToOne + @JoinColumn(name = "author_id") + @ToString.Exclude + private User author; + + @ManyToOne + @JoinColumn(name = "repository_id") + @ToString.Exclude + private GitRepository repository; + + private OffsetDateTime createdAt; + + private OffsetDateTime updatedAt; +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java new file mode 100644 index 0000000..e740580 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java @@ -0,0 +1,24 @@ +package de.tum.cit.aet.helios.branch; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.cit.aet.helios.gitrepo.RepositoryInfoDTO; +import de.tum.cit.aet.helios.issue.Issue.State; + +import org.springframework.lang.NonNull; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record BranchBaseInfoDTO( + @NonNull Long id, + @NonNull String name, + @NonNull Boolean isProtected, + RepositoryInfoDTO repository) { + + public static BranchBaseInfoDTO fromBranch(Branch branch) { + return new BranchBaseInfoDTO( + branch.getId(), + branch.getName(), + branch.isProtected(), + RepositoryInfoDTO.fromRepository(branch.getRepository())); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java new file mode 100644 index 0000000..ec5db2b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java @@ -0,0 +1,38 @@ +package de.tum.cit.aet.helios.branch; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.PathVariable; + +import java.util.List; + +@RestController +@RequestMapping("/api/branches") +public class BranchController { + + private final BranchService branchService; + + public BranchController(BranchService branchService) { + this.branchService = branchService; + } + + @GetMapping + public ResponseEntity> getAllBranches() { + List branches = branchService.getAllBranches(); + if (branches.isEmpty()) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(branches); + } + } + + @GetMapping("/{id}") + public ResponseEntity getBranchById(@PathVariable Long id) { + return branchService.getBranchById(id) + .map(ResponseEntity::ok) + .orElseGet(() -> ResponseEntity.notFound().build()); + } + +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java new file mode 100644 index 0000000..412fcf7 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java @@ -0,0 +1,36 @@ +package de.tum.cit.aet.helios.branch; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.cit.aet.helios.gitrepo.RepositoryInfoDTO; +import de.tum.cit.aet.helios.issue.Issue.State; +import de.tum.cit.aet.helios.user.UserInfoDTO; + +import org.springframework.lang.NonNull; + +import java.time.OffsetDateTime; +import java.util.Comparator; +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record BranchInfoDTO( + @NonNull Long id, + @NonNull String name, + @NonNull Boolean isProtected, + UserInfoDTO author, + RepositoryInfoDTO repository, + OffsetDateTime createdAt, + OffsetDateTime updatedAt) { + + public static BranchInfoDTO fromBranch(Branch branch) { + return new BranchInfoDTO( + branch.getId(), + branch.getName(), + branch.isProtected(), + UserInfoDTO.fromUser(branch.getAuthor()), + RepositoryInfoDTO.fromRepository(branch.getRepository()), + branch.getCreatedAt(), + branch.getUpdatedAt()); + } + +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java new file mode 100644 index 0000000..3a4639d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java @@ -0,0 +1,9 @@ +package de.tum.cit.aet.helios.branch; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BranchRepository extends JpaRepository { + +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java new file mode 100644 index 0000000..17d1e63 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java @@ -0,0 +1,28 @@ +package de.tum.cit.aet.helios.branch; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.Optional; + +@Service +public class BranchService { + + private final BranchRepository branchRepository; + + public BranchService(BranchRepository branchRepository) { + this.branchRepository = branchRepository; + } + + public List getAllBranches() { + return branchRepository.findAll().stream() + .map(BranchInfoDTO::fromBranch) + .collect(Collectors.toList()); + } + + public Optional getBranchById(Long id) { + return branchRepository.findById(id) + .map(BranchInfoDTO::fromBranch); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java new file mode 100644 index 0000000..18b9217 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java @@ -0,0 +1,61 @@ +package de.tum.cit.aet.helios.branch.github; + +import java.io.IOException; + +import org.kohsuke.github.GHBranch; +import org.kohsuke.github.GHEvent; +import org.kohsuke.github.GHEventPayload; +import org.kohsuke.github.GHRepository; +import org.springframework.stereotype.Component; + +import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; +import lombok.extern.log4j.Log4j2; + +@Component +@Log4j2 +public class GitHubBranchMessageHandler extends GitHubMessageHandler { + + // private final GitHubBranchSyncService branchSyncService; + private final GitHubRepositorySyncService repositorySyncService; + + private GitHubBranchMessageHandler( + // GitHubBranchSyncService branchSyncService, + GitHubRepositorySyncService repositorySyncService) { + super(GHEventPayload.Create.class); + // this.branchSyncService = branchSyncService; + this.repositorySyncService = repositorySyncService; + } + + @Override + protected void handleEvent(GHEventPayload.Create eventPayload) { + String refType = eventPayload.getRefType(); + String ref = eventPayload.getRef(); + if ("branch".equals(refType)) { + log.info("Received branch event for repository: {}, ref: {}, refType: {}, masterBranch {}, description: {} ", + eventPayload.getRepository().getFullName(), + eventPayload.getRef(), + eventPayload.getRefType(), + eventPayload.getMasterBranch(), + eventPayload.getDescription() + ); + GHBranch branch; + try { + + GHRepository repository = eventPayload.getRepository(); + branch = repository.getBranch(ref); + log.info("Branch: {}", branch); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return; + } + repositorySyncService.processRepository(eventPayload.getRepository()); + } + + @Override + protected GHEvent getHandlerEvent() { + return GHEvent.CREATE; + } +} From 7369ec97256e945b9afe123388ef20f7606e54b9 Mon Sep 17 00:00:00 2001 From: Stefan Nemeth Date: Tue, 26 Nov 2024 13:02:15 +0100 Subject: [PATCH 06/10] Do not sync pull request twice --- server/application-server/.env.example | 4 ++-- .../github/GitHubWorkflowRunMessageHandler.java | 15 +-------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/server/application-server/.env.example b/server/application-server/.env.example index d6ba118..631688b 100644 --- a/server/application-server/.env.example +++ b/server/application-server/.env.example @@ -2,7 +2,7 @@ DATASOURCE_URL=jdbc:postgresql://127.0.0.1/helios DATASOURCE_USERNAME=helios DATASOURCE_PASSWORD=helios NATS_SERVER=localhost:4222 -NATS_AUTH_TOKEN='5760e8ae09adfb2756f9f8cd5cb2caa704cd3f549eaa9298be843ceb165185d815b81f90c680fa7f626b7cd63abf6ac9' +NATS_AUTH_TOKEN=5760e8ae09adfb2756f9f8cd5cb2caa704cd3f549eaa9298be843ceb165185d815b81f90c680fa7f626b7cd63abf6ac9 REPOSITORY_NAME= ORGANIZATION_NAME= -GITHUB_AUTH_TOKEN= +GITHUB_AUTH_TOKEN= \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java index f64b7be..29da32f 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/workflow/github/GitHubWorkflowRunMessageHandler.java @@ -6,25 +6,21 @@ import de.tum.cit.aet.helios.github.GitHubMessageHandler; import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; -import de.tum.cit.aet.helios.pullrequest.github.GitHubPullRequestSyncService; import lombok.extern.log4j.Log4j2; @Log4j2 @Component public class GitHubWorkflowRunMessageHandler extends GitHubMessageHandler { private final GitHubRepositorySyncService repositorySyncService; - private final GitHubPullRequestSyncService pullRequestSyncService; private final GitHubWorkflowSyncService workflowSyncService; private GitHubWorkflowRunMessageHandler( GitHubWorkflowSyncService workflowSyncService, - GitHubRepositorySyncService repositorySyncService, - GitHubPullRequestSyncService pullRequestSyncService) { + GitHubRepositorySyncService repositorySyncService) { super(GHEventPayload.WorkflowRun.class); this.workflowSyncService = workflowSyncService; this.repositorySyncService = repositorySyncService; - this.pullRequestSyncService = pullRequestSyncService; } @Override @@ -39,15 +35,6 @@ protected void handleEvent(GHEventPayload.WorkflowRun eventPayload) { action); repositorySyncService.processRepository(eventPayload.getRepository()); - - try { - run.getPullRequests().forEach(pullRequest -> { - pullRequestSyncService.processPullRequest(pullRequest); - }); - } catch (Exception e) { - log.error("Failed to process pull requests for workflow run {}: {}", run.getUrl(), e.getMessage()); - } - workflowSyncService.processRun(run); } From 36db7b748843ba0beb0928bfa8f77ef02620218e Mon Sep 17 00:00:00 2001 From: Turker Koc Date: Sat, 30 Nov 2024 02:56:42 +0100 Subject: [PATCH 07/10] Github Branch REST & Webhook implementation --- .../de/tum/cit/aet/helios/branch/Branch.java | 28 +++-- .../aet/helios/branch/BranchBaseInfoDTO.java | 24 ---- .../aet/helios/branch/BranchController.java | 10 +- .../tum/cit/aet/helios/branch/BranchId.java | 32 +++++ .../cit/aet/helios/branch/BranchInfoDTO.java | 16 +-- .../aet/helios/branch/BranchRepository.java | 10 +- .../cit/aet/helios/branch/BranchService.java | 12 ++ .../branch/github/GitHubBranchConverter.java | 35 ++++++ .../github/GitHubBranchSyncService.java | 112 ++++++++++++++++++ ...r.java => GitHubCreateMessageHandler.java} | 36 +++--- .../github/GitHubDeleteMessageHandler.java | 51 ++++++++ .../github/sync/GitHubDataSyncService.java | 7 +- 12 files changed, 299 insertions(+), 74 deletions(-) delete mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchId.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java rename server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/{GitHubBranchMessageHandler.java => GitHubCreateMessageHandler.java} (58%) create mode 100644 server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubDeleteMessageHandler.java diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java index 86c6c4d..3a992d3 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/Branch.java @@ -8,35 +8,39 @@ import java.time.OffsetDateTime; +import com.fasterxml.jackson.annotation.JsonProperty; + import de.tum.cit.aet.helios.gitrepo.GitRepository; import de.tum.cit.aet.helios.user.User; @Entity +@IdClass(BranchId.class) @Getter @Setter @NoArgsConstructor -@ToString +@ToString(callSuper = true) public class Branch { @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private boolean isProtected; - - @ManyToOne - @JoinColumn(name = "author_id") - @ToString.Exclude - private User author; - + @Id @ManyToOne - @JoinColumn(name = "repository_id") + @JoinColumn(name = "repository_id", nullable = false) @ToString.Exclude private GitRepository repository; + private String commit_sha; + + @JsonProperty("protected") + private boolean protection; + private OffsetDateTime createdAt; private OffsetDateTime updatedAt; + + public void forEach(Object object) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'forEach'"); + } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java deleted file mode 100644 index e740580..0000000 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchBaseInfoDTO.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.tum.cit.aet.helios.branch; - -import com.fasterxml.jackson.annotation.JsonInclude; - -import de.tum.cit.aet.helios.gitrepo.RepositoryInfoDTO; -import de.tum.cit.aet.helios.issue.Issue.State; - -import org.springframework.lang.NonNull; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record BranchBaseInfoDTO( - @NonNull Long id, - @NonNull String name, - @NonNull Boolean isProtected, - RepositoryInfoDTO repository) { - - public static BranchBaseInfoDTO fromBranch(Branch branch) { - return new BranchBaseInfoDTO( - branch.getId(), - branch.getName(), - branch.isProtected(), - RepositoryInfoDTO.fromRepository(branch.getRepository())); - } -} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java index ec5db2b..23530e6 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java @@ -4,9 +4,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.PathVariable; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("/api/branches") @@ -27,12 +27,4 @@ public ResponseEntity> getAllBranches() { return ResponseEntity.ok(branches); } } - - @GetMapping("/{id}") - public ResponseEntity getBranchById(@PathVariable Long id) { - return branchService.getBranchById(id) - .map(ResponseEntity::ok) - .orElseGet(() -> ResponseEntity.notFound().build()); - } - } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchId.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchId.java new file mode 100644 index 0000000..cd42e6b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchId.java @@ -0,0 +1,32 @@ +package de.tum.cit.aet.helios.branch; + +import java.io.Serializable; +import java.util.Objects; + +public class BranchId implements Serializable { + private String name; + private Long repository; + + // Default constructor + public BranchId() {} + + public BranchId(String name, Long repository) { + this.name = name; + this.repository = repository; + } + + // Equals and hashCode + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BranchId branchId = (BranchId) o; + return Objects.equals(name, branchId.name) && + Objects.equals(repository, branchId.repository); + } + + @Override + public int hashCode() { + return Objects.hash(name, repository); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java index 412fcf7..a17d8c8 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchInfoDTO.java @@ -14,23 +14,15 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) public record BranchInfoDTO( - @NonNull Long id, @NonNull String name, - @NonNull Boolean isProtected, - UserInfoDTO author, - RepositoryInfoDTO repository, - OffsetDateTime createdAt, - OffsetDateTime updatedAt) { + RepositoryInfoDTO repository + ) { public static BranchInfoDTO fromBranch(Branch branch) { return new BranchInfoDTO( - branch.getId(), branch.getName(), - branch.isProtected(), - UserInfoDTO.fromUser(branch.getAuthor()), - RepositoryInfoDTO.fromRepository(branch.getRepository()), - branch.getCreatedAt(), - branch.getUpdatedAt()); + RepositoryInfoDTO.fromRepository(branch.getRepository()) + ); } } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java index 3a4639d..49b6908 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchRepository.java @@ -1,9 +1,17 @@ package de.tum.cit.aet.helios.branch; +import java.util.List; +import java.util.Optional; + + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import de.tum.cit.aet.helios.gitrepo.GitRepository; + @Repository public interface BranchRepository extends JpaRepository { - + Optional findByNameAndRepositoryId(String name, Long repositoryId); + void deleteByNameAndRepositoryId(String name, Long repositoryId); + List findByRepositoryId(Long repositoryId); } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java index 17d1e63..d67fcdf 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchService.java @@ -1,6 +1,7 @@ package de.tum.cit.aet.helios.branch; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.stream.Collectors; @@ -25,4 +26,15 @@ public Optional getBranchById(Long id) { return branchRepository.findById(id) .map(BranchInfoDTO::fromBranch); } + + @Transactional + public void deleteBranchByNameAndRepositoryId(String name, Long repositoryId) { + branchRepository.deleteByNameAndRepositoryId(name, repositoryId); + } + + public List getBranchesByRepositoryId(Long repositoryId) { + return branchRepository.findByRepositoryId(repositoryId).stream() + .map(BranchInfoDTO::fromBranch) + .collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java new file mode 100644 index 0000000..b5af10d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java @@ -0,0 +1,35 @@ +package de.tum.cit.aet.helios.branch.github; + +import org.kohsuke.github.GHBranch; +import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; + +import de.tum.cit.aet.helios.branch.Branch; +import lombok.extern.log4j.Log4j2; +import org.springframework.core.convert.converter.Converter; + + +@Component +@Log4j2 +public class GitHubBranchConverter implements Converter { + @Override + public Branch convert(@NonNull GHBranch source) { + return update(source, new Branch()); + } + + public Branch update(@NonNull GHBranch source, @NonNull Branch branch) { + try { + if (source.getName() != null) { + branch.setName(source.getName()); + } else { + throw new IllegalArgumentException("Branch name cannot be null"); + } + branch.setCommit_sha(source.getSHA1()); + branch.setProtection(source.isProtected()); + } catch (Exception e) { + log.error("Failed to convert fields for source {}: {}", source.getName(), e.getMessage()); + throw e; // Rethrow exception to stop processing invalid data + } + return branch; + } +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java new file mode 100644 index 0000000..fb4e78d --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java @@ -0,0 +1,112 @@ +package de.tum.cit.aet.helios.branch.github; + + +import jakarta.transaction.Transactional; +import lombok.extern.log4j.Log4j2; + +import org.kohsuke.github.GHBranch; +import org.kohsuke.github.GHRepository; +import org.springframework.stereotype.Service; + +import de.tum.cit.aet.helios.branch.BranchRepository; +import de.tum.cit.aet.helios.gitrepo.GitRepoRepository; +import de.tum.cit.aet.helios.branch.Branch; + +import java.io.IOException; +import java.util.*; + +@Service +@Log4j2 +public class GitHubBranchSyncService { + + private final BranchRepository branchRepository; + private final GitRepoRepository gitRepoRepository; + private final GitHubBranchConverter branchConverter; + + public GitHubBranchSyncService( + BranchRepository branchRepository, + GitRepoRepository gitRepoRepository, + GitHubBranchConverter branchConverter) { + this.branchRepository = branchRepository; + this.gitRepoRepository = gitRepoRepository; + this.branchConverter = branchConverter; + } + + /** + * Synchronizes all branches from the specified GitHub repositories. + * + * @param repositories the list of GitHub repositories to sync pull requests + * from + * @param since an optional date to filter pull requests by their last + * update + * @return a list of GitHub pull requests that were successfully fetched and + * processed + */ + public List syncBranchesOfAllRepositories(List repositories) { + return repositories.stream() + .map(repository -> syncBranchesOfRepository(repository)) + .flatMap(List::stream) + .toList(); + } + + /** + * Synchronizes all pull requests from a specific GitHub repository. + * + * @param repository the GitHub repository to sync pull requests from + * @param since an optional date to filter pull requests by their last + * update + * @return a list of GitHub pull requests that were successfully fetched and + * processed + */ + public List syncBranchesOfRepository(GHRepository repository) { + try { + var branches = repository.getBranches().values().stream().toList(); + branches.forEach(branch -> processBranch(branch, repository)); + //Get all branches for current repo + var dbBranches = branchRepository.findByRepositoryId(repository.getId()); + //Delete each branch that exists in db and not in branches + dbBranches.stream().filter(dbBranch -> branches.stream().noneMatch(b -> b.getName().equals(dbBranch.getName()))) + .forEach(dbBranch -> branchRepository.delete(dbBranch)); + return branches; + } catch (IOException e) { + log.error("Failed to fetch branches of repository {}: {}", repository.getFullName(), e.getMessage()); + return Collections.emptyList(); + } + } + + /** + * Processes a single GitHub pull request by updating or creating it in the + * local repository. + * Manages associations with repositories, labels, milestones, authors, + * assignees, merged by users, + * and requested reviewers. + * + * @param ghPullRequest the GitHub pull request to process + * @return the updated or newly created PullRequest entity, or {@code null} if + * an error occurred + */ + @Transactional + public Branch processBranch(GHBranch ghBranch, GHRepository ghRepository) { + // Link with existing repository if not already linked + var repository = gitRepoRepository.findByNameWithOwner(ghRepository.getFullName()); + + var result = branchRepository.findByNameAndRepositoryId(ghBranch.getName(), repository.getId()) + .map(branch -> { + try { + return branchConverter.update(ghBranch, branch); + } catch (Exception e) { + log.error("Failed to update branch {}: {}", ghBranch.getName(), e.getMessage()); + return null; + } + }).orElseGet(() -> branchConverter.convert(ghBranch)); + + if (result == null) { + return null; + } + + if (repository != null) { + result.setRepository(repository); + } + return branchRepository.save(result); + } +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubCreateMessageHandler.java similarity index 58% rename from server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java rename to server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubCreateMessageHandler.java index 18b9217..d4857c7 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchMessageHandler.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubCreateMessageHandler.java @@ -9,28 +9,34 @@ import org.springframework.stereotype.Component; import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import de.tum.cit.aet.helios.github.GitHubService; import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; import lombok.extern.log4j.Log4j2; @Component @Log4j2 -public class GitHubBranchMessageHandler extends GitHubMessageHandler { +public class GitHubCreateMessageHandler extends GitHubMessageHandler { - // private final GitHubBranchSyncService branchSyncService; + private final GitHubBranchSyncService branchSyncService; private final GitHubRepositorySyncService repositorySyncService; + private final GitHubService gitHubService; - private GitHubBranchMessageHandler( - // GitHubBranchSyncService branchSyncService, - GitHubRepositorySyncService repositorySyncService) { + private GitHubCreateMessageHandler( + GitHubBranchSyncService branchSyncService, + GitHubRepositorySyncService repositorySyncService, + GitHubService gitHubService) { super(GHEventPayload.Create.class); - // this.branchSyncService = branchSyncService; + this.branchSyncService = branchSyncService; this.repositorySyncService = repositorySyncService; + this.gitHubService = gitHubService; } @Override protected void handleEvent(GHEventPayload.Create eventPayload) { String refType = eventPayload.getRefType(); String ref = eventPayload.getRef(); + GHRepository repository; + GHBranch branch; if ("branch".equals(refType)) { log.info("Received branch event for repository: {}, ref: {}, refType: {}, masterBranch {}, description: {} ", eventPayload.getRepository().getFullName(), @@ -39,19 +45,19 @@ protected void handleEvent(GHEventPayload.Create eventPayload) { eventPayload.getMasterBranch(), eventPayload.getDescription() ); - GHBranch branch; - try { - - GHRepository repository = eventPayload.getRepository(); - branch = repository.getBranch(ref); - log.info("Branch: {}", branch); - } catch (IOException e) { - // TODO Auto-generated catch block + + try { + repository = eventPayload.getRepository(); + var curRepo = gitHubService.getRepository(repository.getFullName()); + branch = curRepo.getBranch(ref); + + repositorySyncService.processRepository(eventPayload.getRepository()); + branchSyncService.processBranch(branch, repository); + } catch (IOException e) { e.printStackTrace(); } return; } - repositorySyncService.processRepository(eventPayload.getRepository()); } @Override diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubDeleteMessageHandler.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubDeleteMessageHandler.java new file mode 100644 index 0000000..13019d0 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubDeleteMessageHandler.java @@ -0,0 +1,51 @@ +package de.tum.cit.aet.helios.branch.github; + +import org.kohsuke.github.GHEvent; +import org.kohsuke.github.GHEventPayload; +import org.kohsuke.github.GHRepository; +import org.springframework.stereotype.Component; + +import de.tum.cit.aet.helios.github.GitHubMessageHandler; +import lombok.extern.log4j.Log4j2; +import de.tum.cit.aet.helios.branch.BranchService; + +@Component +@Log4j2 +public class GitHubDeleteMessageHandler extends GitHubMessageHandler { + + private final BranchService branchService; + + private GitHubDeleteMessageHandler( + BranchService branchService) { + super(GHEventPayload.Delete.class); + this.branchService = branchService; + } + + @Override + protected void handleEvent(GHEventPayload.Delete eventPayload) { + String refType = eventPayload.getRefType(); + String ref = eventPayload.getRef(); + GHRepository repository; + if ("branch".equals(refType)) { + log.info("Received branch event for repository: {}, ref: {}, refType: {}", + eventPayload.getRepository().getFullName(), + eventPayload.getRef(), + eventPayload.getRefType() + ); + + try { + repository = eventPayload.getRepository(); + //delete the branch from db + branchService.deleteBranchByNameAndRepositoryId(ref, repository.getId()); + } catch (Exception e) { + e.printStackTrace(); + } + return; + } + } + + @Override + protected GHEvent getHandlerEvent() { + return GHEvent.DELETE; + } +} diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java index ecd2972..940d9c5 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/github/sync/GitHubDataSyncService.java @@ -2,6 +2,7 @@ import de.tum.cit.aet.helios.pullrequest.github.GitHubPullRequestSyncService; +import de.tum.cit.aet.helios.branch.github.GitHubBranchSyncService; import de.tum.cit.aet.helios.gitrepo.github.GitHubRepositorySyncService; import de.tum.cit.aet.helios.user.github.GitHubUserSyncService; import de.tum.cit.aet.helios.workflow.github.GitHubWorkflowSyncService; @@ -28,17 +29,20 @@ public class GitHubDataSyncService { private final GitHubRepositorySyncService repositorySyncService; private final GitHubPullRequestSyncService pullRequestSyncService; private final GitHubWorkflowSyncService workflowSyncService; + private final GitHubBranchSyncService branchSyncService; public GitHubDataSyncService( DataSyncStatusRepository dataSyncStatusRepository, GitHubUserSyncService userSyncService, GitHubRepositorySyncService repositorySyncService, GitHubPullRequestSyncService pullRequestSyncService, - GitHubWorkflowSyncService workflowSyncService) { + GitHubWorkflowSyncService workflowSyncService, + GitHubBranchSyncService branchSyncService) { this.dataSyncStatusRepository = dataSyncStatusRepository; this.userSyncService = userSyncService; this.repositorySyncService = repositorySyncService; this.pullRequestSyncService = pullRequestSyncService; this.workflowSyncService = workflowSyncService; + this.branchSyncService = branchSyncService; } @Transactional @@ -66,6 +70,7 @@ public void syncData() { pullRequestSyncService.syncPullRequestsOfAllRepositories(repositories, Optional.of(cutoffDate)); userSyncService.syncAllExistingUsers(); workflowSyncService.syncRunsOfAllRepositories(repositories, Optional.of(cutoffDate)); + branchSyncService.syncBranchesOfAllRepositories(repositories); var endTime = OffsetDateTime.now(); From 98db600380e0cab2b72e1bb33dc16b5cb2a4fda3 Mon Sep 17 00:00:00 2001 From: Turker Koc Date: Sun, 1 Dec 2024 01:12:10 +0100 Subject: [PATCH 08/10] server openapi --- server/application-server/openapi.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index d101127..4437987 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -58,6 +58,20 @@ paths: application/json: schema: $ref: "#/components/schemas/PullRequestInfoDTO" + /api/branches: + get: + tags: + - branch-controller + operationId: getAllBranches + responses: + "200": + description: OK + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/BranchInfoDTO" components: schemas: PullRequestInfoDTO: @@ -161,3 +175,12 @@ components: type: string htmlUrl: type: string + BranchInfoDTO: + required: + - name + type: object + properties: + name: + type: string + repository: + $ref: "#/components/schemas/RepositoryInfoDTO" From f84feb60f42c128aeb08831a7ab4d198bb62e8c1 Mon Sep 17 00:00:00 2001 From: Turker Koc Date: Mon, 2 Dec 2024 20:53:31 +0100 Subject: [PATCH 09/10] client openapi --- .../modules/openapi/.openapi-generator/FILES | 3 + .../src/app/core/modules/openapi/api/api.ts | 5 +- .../openapi/api/branch-controller.service.ts | 155 ++++++++++++++++++ .../api/branch-controller.serviceInterface.ts | 31 ++++ .../modules/openapi/model/branch-info-dto.ts | 17 ++ .../app/core/modules/openapi/model/models.ts | 1 + 6 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 client/src/app/core/modules/openapi/api/branch-controller.service.ts create mode 100644 client/src/app/core/modules/openapi/api/branch-controller.serviceInterface.ts create mode 100644 client/src/app/core/modules/openapi/model/branch-info-dto.ts diff --git a/client/src/app/core/modules/openapi/.openapi-generator/FILES b/client/src/app/core/modules/openapi/.openapi-generator/FILES index b4a6ec0..85634ba 100644 --- a/client/src/app/core/modules/openapi/.openapi-generator/FILES +++ b/client/src/app/core/modules/openapi/.openapi-generator/FILES @@ -2,6 +2,8 @@ README.md api.module.ts api/api.ts +api/branch-controller.service.ts +api/branch-controller.serviceInterface.ts api/pull-request-controller.service.ts api/pull-request-controller.serviceInterface.ts api/status-controller.service.ts @@ -10,6 +12,7 @@ configuration.ts encoder.ts git_push.sh index.ts +model/branch-info-dto.ts model/models.ts model/pull-request-info-dto.ts model/repository-info-dto.ts diff --git a/client/src/app/core/modules/openapi/api/api.ts b/client/src/app/core/modules/openapi/api/api.ts index 0f34ef6..0ae8e56 100644 --- a/client/src/app/core/modules/openapi/api/api.ts +++ b/client/src/app/core/modules/openapi/api/api.ts @@ -1,7 +1,10 @@ +export * from './branch-controller.service'; +import { BranchControllerService } from './branch-controller.service'; +export * from './branch-controller.serviceInterface'; export * from './pull-request-controller.service'; import { PullRequestControllerService } from './pull-request-controller.service'; export * from './pull-request-controller.serviceInterface'; export * from './status-controller.service'; import { StatusControllerService } from './status-controller.service'; export * from './status-controller.serviceInterface'; -export const APIS = [PullRequestControllerService, StatusControllerService]; +export const APIS = [BranchControllerService, PullRequestControllerService, StatusControllerService]; diff --git a/client/src/app/core/modules/openapi/api/branch-controller.service.ts b/client/src/app/core/modules/openapi/api/branch-controller.service.ts new file mode 100644 index 0000000..090df45 --- /dev/null +++ b/client/src/app/core/modules/openapi/api/branch-controller.service.ts @@ -0,0 +1,155 @@ +/** + * Helios API + * + * Contact: turker.koc@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpParameterCodec, HttpContext + } from '@angular/common/http'; +import { CustomHttpParameterCodec } from '../encoder'; +import { Observable } from 'rxjs'; + +// @ts-ignore +import { BranchInfoDTO } from '../model/branch-info-dto'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { + BranchControllerServiceInterface +} from './branch-controller.serviceInterface'; + + + +@Injectable({ + providedIn: 'root' +}) +export class BranchControllerService implements BranchControllerServiceInterface { + + protected basePath = 'http://localhost'; + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); + public encoder: HttpParameterCodec; + + constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) { + if (configuration) { + this.configuration = configuration; + } + if (typeof this.configuration.basePath !== 'string') { + const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined; + if (firstBasePath != undefined) { + basePath = firstBasePath; + } + + if (typeof basePath !== 'string') { + basePath = this.basePath; + } + this.configuration.basePath = basePath; + } + this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); + } + + + // @ts-ignore + private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { + if (typeof value === "object" && value instanceof Date === false) { + httpParams = this.addToHttpParamsRecursive(httpParams, value); + } else { + httpParams = this.addToHttpParamsRecursive(httpParams, value, key); + } + return httpParams; + } + + private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { + if (value == null) { + return httpParams; + } + + if (typeof value === "object") { + if (Array.isArray(value)) { + (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); + } else if (value instanceof Date) { + if (key != null) { + httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10)); + } else { + throw Error("key may not be null if value is Date"); + } + } else { + Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive( + httpParams, value[k], key != null ? `${key}.${k}` : k)); + } + } else if (key != null) { + httpParams = httpParams.append(key, value); + } else { + throw Error("key may not be null if value is not object or array"); + } + return httpParams; + } + + /** + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public getAllBranches(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAllBranches(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllBranches(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllBranches(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + + let localVarHeaders = this.defaultHeaders; + + let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; + if (localVarHttpHeaderAcceptSelected === undefined) { + // to determine the Accept header + const httpHeaderAccepts: string[] = [ + 'application/json' + ]; + localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); + } + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + let localVarHttpContext: HttpContext | undefined = options && options.context; + if (localVarHttpContext === undefined) { + localVarHttpContext = new HttpContext(); + } + + let localVarTransferCache: boolean | undefined = options && options.transferCache; + if (localVarTransferCache === undefined) { + localVarTransferCache = true; + } + + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/api/branches`; + return this.httpClient.request>('get', `${this.configuration.basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + withCredentials: this.configuration.withCredentials, + headers: localVarHeaders, + observe: observe, + transferCache: localVarTransferCache, + reportProgress: reportProgress + } + ); + } + +} diff --git a/client/src/app/core/modules/openapi/api/branch-controller.serviceInterface.ts b/client/src/app/core/modules/openapi/api/branch-controller.serviceInterface.ts new file mode 100644 index 0000000..30848f2 --- /dev/null +++ b/client/src/app/core/modules/openapi/api/branch-controller.serviceInterface.ts @@ -0,0 +1,31 @@ +/** + * Helios API + * + * Contact: turker.koc@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { HttpHeaders } from '@angular/common/http'; + +import { Observable } from 'rxjs'; + +import { BranchInfoDTO } from '../model/models'; + + +import { Configuration } from '../configuration'; + + + +export interface BranchControllerServiceInterface { + defaultHeaders: HttpHeaders; + configuration: Configuration; + + /** + * + * + */ + getAllBranches(extraHttpRequestParams?: any): Observable>; + +} diff --git a/client/src/app/core/modules/openapi/model/branch-info-dto.ts b/client/src/app/core/modules/openapi/model/branch-info-dto.ts new file mode 100644 index 0000000..37fb591 --- /dev/null +++ b/client/src/app/core/modules/openapi/model/branch-info-dto.ts @@ -0,0 +1,17 @@ +/** + * Helios API + * + * Contact: turker.koc@tum.de + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { RepositoryInfoDTO } from './repository-info-dto'; + + +export interface BranchInfoDTO { + name: string; + repository?: RepositoryInfoDTO; +} + diff --git a/client/src/app/core/modules/openapi/model/models.ts b/client/src/app/core/modules/openapi/model/models.ts index a2131af..89b6973 100644 --- a/client/src/app/core/modules/openapi/model/models.ts +++ b/client/src/app/core/modules/openapi/model/models.ts @@ -1,3 +1,4 @@ +export * from './branch-info-dto'; export * from './pull-request-info-dto'; export * from './repository-info-dto'; export * from './user-info-dto'; From da02e7f45b041f154d7b80eab589b862ef1a6c51 Mon Sep 17 00:00:00 2001 From: Turker Koc Date: Mon, 2 Dec 2024 21:20:55 +0100 Subject: [PATCH 10/10] minor bug fixes --- .../aet/helios/branch/BranchController.java | 7 +-- .../branch/github/GitHubBranchConverter.java | 1 - .../github/GitHubBranchSyncService.java | 49 ++++++++----------- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java index 23530e6..bee3934 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/BranchController.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; -import java.util.stream.Collectors; @RestController @RequestMapping("/api/branches") @@ -21,10 +20,6 @@ public BranchController(BranchService branchService) { @GetMapping public ResponseEntity> getAllBranches() { List branches = branchService.getAllBranches(); - if (branches.isEmpty()) { - return ResponseEntity.notFound().build(); - } else { - return ResponseEntity.ok(branches); - } + return ResponseEntity.ok(branches); } } \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java index b5af10d..ded9406 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchConverter.java @@ -28,7 +28,6 @@ public Branch update(@NonNull GHBranch source, @NonNull Branch branch) { branch.setProtection(source.isProtected()); } catch (Exception e) { log.error("Failed to convert fields for source {}: {}", source.getName(), e.getMessage()); - throw e; // Rethrow exception to stop processing invalid data } return branch; } diff --git a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java index fb4e78d..2949b48 100644 --- a/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java +++ b/server/application-server/src/main/java/de/tum/cit/aet/helios/branch/github/GitHubBranchSyncService.java @@ -15,6 +15,9 @@ import java.io.IOException; import java.util.*; +/** + * Service for synchronizing branches from GitHub repositories. + */ @Service @Log4j2 public class GitHubBranchSyncService { @@ -35,12 +38,8 @@ public GitHubBranchSyncService( /** * Synchronizes all branches from the specified GitHub repositories. * - * @param repositories the list of GitHub repositories to sync pull requests - * from - * @param since an optional date to filter pull requests by their last - * update - * @return a list of GitHub pull requests that were successfully fetched and - * processed + * @param repositories the list of GitHub repositories to sync branches from + * @return a list of GitHub branches that were successfully fetched and processed */ public List syncBranchesOfAllRepositories(List repositories) { return repositories.stream() @@ -50,40 +49,34 @@ public List syncBranchesOfAllRepositories(List repositor } /** - * Synchronizes all pull requests from a specific GitHub repository. + * Synchronizes all branches from a specific GitHub repository. * - * @param repository the GitHub repository to sync pull requests from - * @param since an optional date to filter pull requests by their last - * update - * @return a list of GitHub pull requests that were successfully fetched and - * processed + * @param repository the GitHub repository to sync branches from + * @return a list of GitHub branches that were successfully fetched and processed */ public List syncBranchesOfRepository(GHRepository repository) { try { var branches = repository.getBranches().values().stream().toList(); branches.forEach(branch -> processBranch(branch, repository)); - //Get all branches for current repo - var dbBranches = branchRepository.findByRepositoryId(repository.getId()); - //Delete each branch that exists in db and not in branches + // Get all branches for the current repository + var dbBranches = branchRepository.findByRepositoryId(repository.getId()); + // Delete each branch that exists in the database and not in the fetched branches dbBranches.stream().filter(dbBranch -> branches.stream().noneMatch(b -> b.getName().equals(dbBranch.getName()))) .forEach(dbBranch -> branchRepository.delete(dbBranch)); return branches; } catch (IOException e) { log.error("Failed to fetch branches of repository {}: {}", repository.getFullName(), e.getMessage()); return Collections.emptyList(); - } + } } /** - * Processes a single GitHub pull request by updating or creating it in the - * local repository. - * Manages associations with repositories, labels, milestones, authors, - * assignees, merged by users, - * and requested reviewers. + * Processes a single GitHub branch by updating or creating it in the local repository. + * Manages associations with repositories. * - * @param ghPullRequest the GitHub pull request to process - * @return the updated or newly created PullRequest entity, or {@code null} if - * an error occurred + * @param ghBranch the GitHub branch to process + * @param ghRepository the GitHub repository to which the branch belongs + * @return the updated or newly created Branch entity, or {@code null} if an error occurred */ @Transactional public Branch processBranch(GHBranch ghBranch, GHRepository ghRepository) { @@ -93,14 +86,14 @@ public Branch processBranch(GHBranch ghBranch, GHRepository ghRepository) { var result = branchRepository.findByNameAndRepositoryId(ghBranch.getName(), repository.getId()) .map(branch -> { try { - return branchConverter.update(ghBranch, branch); + return branchConverter.update(ghBranch, branch); } catch (Exception e) { log.error("Failed to update branch {}: {}", ghBranch.getName(), e.getMessage()); return null; } - }).orElseGet(() -> branchConverter.convert(ghBranch)); - - if (result == null) { + }).orElseGet(() -> branchConverter.convert(ghBranch)); + + if (result == null) { return null; }