From e5b8cd89b14cb3d06a3d2a1dec05cee3ec64d356 Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Sun, 27 Oct 2024 13:28:34 +0100 Subject: [PATCH] add issue comments to leaderboard and profile --- ...assImportIntegratorIntegratorProvider.java | 16 ++--- .../issue/{dto => }/IssueInfoDTO.java | 6 +- .../{dto => }/IssueCommentInfoDTO.java | 6 +- .../issuecomment/IssueCommentRepository.java | 40 +++++++++++ .../github/GitHubIssueCommentSyncService.java | 2 + .../gitprovider/label/LabelInfoDTO.java | 16 +++++ .../label/dto/LabelDTOConverter.java | 16 ----- .../gitprovider/label/dto/LabelInfoDTO.java | 9 --- .../milestone/{dto => }/MilestoneInfoDTO.java | 2 +- .../pullrequest/PullRequestBaseInfoDTO.java | 44 ++++++++++++ .../pullrequest/PullRequestInfoDTO.java | 66 +++++++++++++++++ .../dto/PullRequestBaseInfoDTO.java | 20 ------ .../dto/PullRequestDTOConverter.java | 72 ------------------- .../pullrequest/dto/PullRequestInfoDTO.java | 35 --------- .../PullRequestReviewInfoDTO.java | 48 +++++++++++++ .../PullRequestReviewRepository.java | 4 +- .../dto/PullRequestReviewDTOConverter.java | 32 --------- .../dto/PullRequestReviewInfoDTO.java | 23 ------ .../repository/RepositoryInfoDTO.java | 22 ++++++ .../dto/RepositoryDTOConverter.java | 18 ----- .../repository/dto/RepositoryInfoDTO.java | 13 ---- .../gitprovider/user/UserController.java | 2 - .../user/{dto => }/UserInfoDTO.java | 11 ++- .../user/{dto => }/UserProfileDTO.java | 8 +-- .../gitprovider/user/UserService.java | 63 ++++++++-------- .../user/dto/UserDTOConverter.java | 18 ----- .../leaderboard/LeaderboardController.java | 2 - .../{dto => }/LeaderboardEntryDTO.java | 4 +- .../leaderboard/LeaderboardService.java | 34 ++++++--- 29 files changed, 325 insertions(+), 327 deletions(-) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/{dto => }/IssueInfoDTO.java (74%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/{dto => }/IssueCommentInfoDTO.java (71%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/LabelInfoDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelDTOConverter.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelInfoDTO.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/{dto => }/MilestoneInfoDTO.java (88%) create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestBaseInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestInfoDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestBaseInfoDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestDTOConverter.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewInfoDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewDTOConverter.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewInfoDTO.java create mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/RepositoryInfoDTO.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryDTOConverter.java delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryInfoDTO.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/{dto => }/UserInfoDTO.java (51%) rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/{dto => }/UserProfileDTO.java (61%) delete mode 100644 server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserDTOConverter.java rename server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/{dto => }/LeaderboardEntryDTO.java (79%) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java index b5627d0d..d3180a5d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/ClassImportIntegratorIntegratorProvider.java @@ -6,14 +6,14 @@ import org.hibernate.integrator.spi.Integrator; import org.hibernate.jpa.boot.spi.IntegratorProvider; -import de.tum.in.www1.hephaestus.gitprovider.issue.dto.IssueInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.issuecomment.dto.IssueCommentInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.label.dto.LabelInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.milestone.dto.MilestoneInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto.PullRequestReviewInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.issue.IssueInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueCommentInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.label.LabelInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.milestone.MilestoneInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; import io.hypersistence.utils.hibernate.type.util.ClassImportIntegrator; public class ClassImportIntegratorIntegratorProvider implements IntegratorProvider { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/dto/IssueInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/IssueInfoDTO.java similarity index 74% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/dto/IssueInfoDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/IssueInfoDTO.java index 2a6820db..dcac6917 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/dto/IssueInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issue/IssueInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.gitprovider.issue.dto; +package de.tum.in.www1.hephaestus.gitprovider.issue; import java.time.OffsetDateTime; import java.util.List; @@ -6,8 +6,8 @@ import org.springframework.lang.NonNull; import de.tum.in.www1.hephaestus.gitprovider.issue.Issue.State; -import de.tum.in.www1.hephaestus.gitprovider.label.dto.LabelInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.label.LabelInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; public record IssueInfoDTO( @NonNull Long id, diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/dto/IssueCommentInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentInfoDTO.java similarity index 71% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/dto/IssueCommentInfoDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentInfoDTO.java index 6248b634..bd843666 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/dto/IssueCommentInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.gitprovider.issuecomment.dto; +package de.tum.in.www1.hephaestus.gitprovider.issuecomment; import java.time.OffsetDateTime; @@ -6,8 +6,8 @@ import com.fasterxml.jackson.annotation.JsonInclude; import de.tum.in.www1.hephaestus.gitprovider.common.AuthorAssociation; -import de.tum.in.www1.hephaestus.gitprovider.issue.dto.IssueInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.issue.IssueInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) public record IssueCommentInfoDTO( diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentRepository.java index aa1604fd..41943b29 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/IssueCommentRepository.java @@ -1,7 +1,47 @@ package de.tum.in.www1.hephaestus.gitprovider.issuecomment; +import java.time.OffsetDateTime; +import java.util.List; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface IssueCommentRepository extends JpaRepository { + @Query(""" + SELECT ic + FROM IssueComment ic + LEFT JOIN FETCH ic.author + LEFT JOIN FETCH ic.issue + LEFT JOIN FETCH ic.issue.repository + WHERE + ic.author.login = :authorLogin AND ic.createdAt >= :activitySince + AND (:onlyFromPullRequests = false OR ic.issue.htmlUrl LIKE '%/pull/%') + ORDER BY ic.createdAt DESC + """) + List findAllByAuthorLoginSince( + @Param("authorLogin") String authorLogin, + @Param("activitySince") OffsetDateTime activitySince, + @Param("onlyFromPullRequests") boolean onlyFromPullRequests); + + @Query(""" + SELECT ic + FROM IssueComment ic + LEFT JOIN FETCH ic.author + LEFT JOIN FETCH ic.issue + LEFT JOIN FETCH ic.issue.repository + WHERE + ic.createdAt BETWEEN :after AND :before + AND (:repository IS NULL OR ic.issue.repository.nameWithOwner = :repository) + AND ic.author.type = 'USER' + AND (:onlyFromPullRequests = false OR ic.issue.htmlUrl LIKE '%/pull/%') + ORDER BY ic.createdAt DESC + """) + List findAllInTimeframe( + @Param("after") OffsetDateTime after, + @Param("before") OffsetDateTime before, + @Param("repository") Optional repository, + @Param("onlyFromPullRequests") boolean onlyFromPullRequests); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/github/GitHubIssueCommentSyncService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/github/GitHubIssueCommentSyncService.java index 0f85c047..8e421141 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/github/GitHubIssueCommentSyncService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/issuecomment/github/GitHubIssueCommentSyncService.java @@ -67,6 +67,8 @@ public void syncIssueCommentsOfAllIssues(List ghIssues, Optional since) { var builder = ghIssue.queryComments(); if (ghIssue.isPullRequest()) { + since.ifPresent(date -> builder.since(Date.from(date.toInstant()))); + builder.list().withPageSize(100).forEach(this::processIssueComment); return; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/LabelInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/LabelInfoDTO.java new file mode 100644 index 00000000..504a35c0 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/LabelInfoDTO.java @@ -0,0 +1,16 @@ +package de.tum.in.www1.hephaestus.gitprovider.label; + +import org.springframework.lang.NonNull; + +public record LabelInfoDTO( + @NonNull Long id, + @NonNull String name, + @NonNull String color) { + + public static LabelInfoDTO fromLabel(Label label) { + return new LabelInfoDTO( + label.getId(), + label.getName(), + label.getColor()); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelDTOConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelDTOConverter.java deleted file mode 100644 index 77766737..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelDTOConverter.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.label.dto; - -import org.springframework.stereotype.Component; - -import de.tum.in.www1.hephaestus.gitprovider.label.Label; - -@Component -public class LabelDTOConverter { - - public LabelInfoDTO convertToDTO(Label label) { - return new LabelInfoDTO( - label.getId(), - label.getName(), - label.getColor()); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelInfoDTO.java deleted file mode 100644 index d0812067..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/label/dto/LabelInfoDTO.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.label.dto; - -import org.springframework.lang.NonNull; - -public record LabelInfoDTO( - @NonNull Long id, - @NonNull String name, - @NonNull String color) { -} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/dto/MilestoneInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/MilestoneInfoDTO.java similarity index 88% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/dto/MilestoneInfoDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/MilestoneInfoDTO.java index f56aaff6..230503a1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/dto/MilestoneInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/milestone/MilestoneInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.gitprovider.milestone.dto; +package de.tum.in.www1.hephaestus.gitprovider.milestone; import java.time.OffsetDateTime; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestBaseInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestBaseInfoDTO.java new file mode 100644 index 00000000..bdb2d50b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestBaseInfoDTO.java @@ -0,0 +1,44 @@ +package de.tum.in.www1.hephaestus.gitprovider.pullrequest; + +import org.springframework.lang.NonNull; +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.gitprovider.issue.Issue; +import de.tum.in.www1.hephaestus.gitprovider.issue.Issue.State; +import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record PullRequestBaseInfoDTO( + @NonNull Long id, + @NonNull Integer number, + @NonNull String title, + @NonNull State state, + @NonNull Boolean isDraft, + @NonNull Boolean isMerged, + RepositoryInfoDTO repository, + @NonNull String htmlUrl) { + + public static PullRequestBaseInfoDTO fromPullRequest(PullRequest pullRequest) { + return new PullRequestBaseInfoDTO( + pullRequest.getId(), + pullRequest.getNumber(), + pullRequest.getTitle(), + pullRequest.getState(), + pullRequest.isDraft(), + pullRequest.isMerged(), + RepositoryInfoDTO.fromRepository(pullRequest.getRepository()), + pullRequest.getHtmlUrl()); + } + + public static PullRequestBaseInfoDTO fromIssue(Issue issue) { + return new PullRequestBaseInfoDTO( + issue.getId(), + issue.getNumber(), + issue.getTitle(), + issue.getState(), + false, + false, + RepositoryInfoDTO.fromRepository(issue.getRepository()), + issue.getHtmlUrl()); + } +} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestInfoDTO.java new file mode 100644 index 00000000..99950d44 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/PullRequestInfoDTO.java @@ -0,0 +1,66 @@ +package de.tum.in.www1.hephaestus.gitprovider.pullrequest; + +import java.util.Comparator; +import java.util.List; +import java.time.OffsetDateTime; + +import org.springframework.lang.NonNull; +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.gitprovider.issue.Issue.State; +import de.tum.in.www1.hephaestus.gitprovider.label.LabelInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record PullRequestInfoDTO( + @NonNull Long id, + @NonNull Integer number, + @NonNull String title, + @NonNull State state, + @NonNull Boolean isDraft, + @NonNull Boolean isMerged, + @NonNull Integer commentsCount, + UserInfoDTO author, + List labels, + List assignees, + RepositoryInfoDTO repository, + @NonNull Integer additions, + @NonNull Integer deletions, + OffsetDateTime mergedAt, + OffsetDateTime closedAt, + @NonNull String htmlUrl, + OffsetDateTime createdAt, + OffsetDateTime updatedAt) { + + public static PullRequestInfoDTO fromPullRequest(PullRequest pullRequest) { + return new PullRequestInfoDTO( + pullRequest.getId(), + pullRequest.getNumber(), + pullRequest.getTitle(), + pullRequest.getState(), + pullRequest.isDraft(), + pullRequest.isMerged(), + pullRequest.getCommentsCount(), + UserInfoDTO.fromUser(pullRequest.getAuthor()), + pullRequest.getLabels() + .stream() + .map(LabelInfoDTO::fromLabel) + .sorted(Comparator.comparing(LabelInfoDTO::name)) + .toList(), + pullRequest.getAssignees() + .stream() + .map(UserInfoDTO::fromUser) + .sorted(Comparator.comparing(UserInfoDTO::login)) + .toList(), + RepositoryInfoDTO.fromRepository(pullRequest.getRepository()), + pullRequest.getAdditions(), + pullRequest.getDeletions(), + pullRequest.getMergedAt(), + pullRequest.getClosedAt(), + pullRequest.getHtmlUrl(), + pullRequest.getCreatedAt(), + pullRequest.getUpdatedAt()); + } + +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestBaseInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestBaseInfoDTO.java deleted file mode 100644 index 52a3edfe..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestBaseInfoDTO.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto; - -import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonInclude; - -import de.tum.in.www1.hephaestus.gitprovider.issue.Issue.State; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryInfoDTO; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record PullRequestBaseInfoDTO( - @NonNull Long id, - @NonNull Integer number, - @NonNull String title, - @NonNull State state, - @NonNull Boolean isDraft, - @NonNull Boolean isMerged, - RepositoryInfoDTO repository, - @NonNull String htmlUrl) { - -} \ No newline at end of file diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestDTOConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestDTOConverter.java deleted file mode 100644 index 525acec3..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestDTOConverter.java +++ /dev/null @@ -1,72 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto; - -import java.util.Comparator; - -import org.springframework.stereotype.Component; - -import de.tum.in.www1.hephaestus.gitprovider.label.dto.LabelDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.label.dto.LabelInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; - -@Component -public class PullRequestDTOConverter { - - private final LabelDTOConverter labelDTOConverter; - private final UserDTOConverter userDTOConverter; - private final RepositoryDTOConverter repositoryDTOConverter; - - public PullRequestDTOConverter( - LabelDTOConverter labelDTOConverter, - UserDTOConverter userDTOConverter, - RepositoryDTOConverter repositoryDTOConverter) { - this.labelDTOConverter = labelDTOConverter; - this.userDTOConverter = userDTOConverter; - this.repositoryDTOConverter = repositoryDTOConverter; - } - - public PullRequestInfoDTO convertToDTO(PullRequest pullRequest) { - return new PullRequestInfoDTO( - pullRequest.getId(), - pullRequest.getNumber(), - pullRequest.getTitle(), - pullRequest.getState(), - pullRequest.isDraft(), - pullRequest.isMerged(), - pullRequest.getCommentsCount(), - userDTOConverter.convertToDTO(pullRequest.getAuthor()), - pullRequest.getLabels() - .stream() - .map(labelDTOConverter::convertToDTO) - .sorted(Comparator.comparing(LabelInfoDTO::name)) - .toList(), - pullRequest.getAssignees() - .stream() - .map(userDTOConverter::convertToDTO) - .sorted(Comparator.comparing(UserInfoDTO::login)) - .toList(), - repositoryDTOConverter.convertToDTO(pullRequest.getRepository()), - pullRequest.getAdditions(), - pullRequest.getDeletions(), - pullRequest.getMergedAt(), - pullRequest.getClosedAt(), - pullRequest.getHtmlUrl(), - pullRequest.getCreatedAt(), - pullRequest.getUpdatedAt()); - } - - public PullRequestBaseInfoDTO convertToBaseDTO(PullRequest pullRequest) { - return new PullRequestBaseInfoDTO( - pullRequest.getId(), - pullRequest.getNumber(), - pullRequest.getTitle(), - pullRequest.getState(), - pullRequest.isDraft(), - pullRequest.isMerged(), - repositoryDTOConverter.convertToDTO(pullRequest.getRepository()), - pullRequest.getHtmlUrl()); - } - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestInfoDTO.java deleted file mode 100644 index d67c853e..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequest/dto/PullRequestInfoDTO.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto; - -import java.util.List; -import java.time.OffsetDateTime; - -import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonInclude; - -import de.tum.in.www1.hephaestus.gitprovider.issue.Issue.State; -import de.tum.in.www1.hephaestus.gitprovider.label.dto.LabelInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record PullRequestInfoDTO( - @NonNull Long id, - @NonNull Integer number, - @NonNull String title, - @NonNull State state, - @NonNull Boolean isDraft, - @NonNull Boolean isMerged, - @NonNull Integer commentsCount, - UserInfoDTO author, - List labels, - List assignees, - RepositoryInfoDTO repository, - @NonNull Integer additions, - @NonNull Integer deletions, - OffsetDateTime mergedAt, - OffsetDateTime closedAt, - @NonNull String htmlUrl, - OffsetDateTime createdAt, - OffsetDateTime updatedAt) { - -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewInfoDTO.java new file mode 100644 index 00000000..fd5049fa --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewInfoDTO.java @@ -0,0 +1,48 @@ +package de.tum.in.www1.hephaestus.gitprovider.pullrequestreview; + +import java.time.OffsetDateTime; + +import org.springframework.lang.NonNull; +import com.fasterxml.jackson.annotation.JsonInclude; + +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueComment; +import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestBaseInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record PullRequestReviewInfoDTO( + @NonNull Long id, + @NonNull Boolean isDismissed, + @NonNull PullRequestReview.State state, + @NonNull Integer codeComments, + UserInfoDTO author, + PullRequestBaseInfoDTO pullRequest, + @NonNull String htmlUrl, + OffsetDateTime submittedAt) { + // We do not have createdAt and updatedAt for reviews + + public static PullRequestReviewInfoDTO fromPullRequestReview(PullRequestReview pullRequestReview) { + return new PullRequestReviewInfoDTO( + pullRequestReview.getId(), + pullRequestReview.isDismissed(), + pullRequestReview.getState(), + pullRequestReview.getComments().size(), + UserInfoDTO.fromUser(pullRequestReview.getAuthor()), + PullRequestBaseInfoDTO.fromPullRequest(pullRequestReview.getPullRequest()), + pullRequestReview.getHtmlUrl(), + pullRequestReview.getSubmittedAt()); + } + + public static PullRequestReviewInfoDTO fromIssueComment(IssueComment issueComment) { + return new PullRequestReviewInfoDTO( + issueComment.getId(), + false, + PullRequestReview.State.COMMENTED, + 0, + UserInfoDTO.fromUser(issueComment.getAuthor()), + PullRequestBaseInfoDTO.fromIssue(issueComment.getIssue()), + issueComment.getHtmlUrl(), + issueComment.getCreatedAt() + ); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewRepository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewRepository.java index f39808d5..6ba427c9 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewRepository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/PullRequestReviewRepository.java @@ -15,7 +15,7 @@ public interface PullRequestReviewRepository extends JpaRepository findAllByAuthorLoginSince( @Query(""" SELECT prr FROM PullRequestReview prr - JOIN FETCH prr.author + LEFT JOIN FETCH prr.author LEFT JOIN FETCH prr.pullRequest LEFT JOIN FETCH prr.pullRequest.repository LEFT JOIN FETCH prr.comments diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewDTOConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewDTOConverter.java deleted file mode 100644 index 0aad592c..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewDTOConverter.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto; - -import org.springframework.stereotype.Component; - -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserDTOConverter; - -@Component -public class PullRequestReviewDTOConverter { - - private final UserDTOConverter userDTOConverter; - private final PullRequestDTOConverter pullRequestDTOConverter; - - public PullRequestReviewDTOConverter(UserDTOConverter userDTOConverter, - PullRequestDTOConverter pullRequestDTOConverter) { - this.userDTOConverter = userDTOConverter; - this.pullRequestDTOConverter = pullRequestDTOConverter; - } - - public PullRequestReviewInfoDTO convertToDTO(PullRequestReview pullRequestReview) { - return new PullRequestReviewInfoDTO( - pullRequestReview.getId(), - pullRequestReview.isDismissed(), - pullRequestReview.getState(), - pullRequestReview.getComments().size(), - userDTOConverter.convertToDTO(pullRequestReview.getAuthor()), - pullRequestDTOConverter.convertToBaseDTO(pullRequestReview.getPullRequest()), - pullRequestReview.getHtmlUrl(), - pullRequestReview.getSubmittedAt()); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewInfoDTO.java deleted file mode 100644 index 4da8195a..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/pullrequestreview/dto/PullRequestReviewInfoDTO.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto; - -import java.time.OffsetDateTime; - -import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonInclude; - -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestBaseInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record PullRequestReviewInfoDTO( - @NonNull Long id, - @NonNull Boolean isDismissed, - @NonNull PullRequestReview.State state, - @NonNull Integer codeComments, - UserInfoDTO author, - PullRequestBaseInfoDTO pullRequest, - @NonNull String htmlUrl, - OffsetDateTime submittedAt) { - // We do not have createdAt and updatedAt for reviews -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/RepositoryInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/RepositoryInfoDTO.java new file mode 100644 index 00000000..191cf5f8 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/RepositoryInfoDTO.java @@ -0,0 +1,22 @@ +package de.tum.in.www1.hephaestus.gitprovider.repository; + +import org.springframework.lang.NonNull; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public record RepositoryInfoDTO( + @NonNull Long id, + @NonNull String name, + @NonNull String nameWithOwner, + String description, + @NonNull String htmlUrl) { + + public static RepositoryInfoDTO fromRepository(Repository repository) { + return new RepositoryInfoDTO( + repository.getId(), + repository.getName(), + repository.getNameWithOwner(), + repository.getDescription(), + repository.getHtmlUrl()); + } +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryDTOConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryDTOConverter.java deleted file mode 100644 index 7bd99837..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryDTOConverter.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.repository.dto; - -import org.springframework.stereotype.Component; - -import de.tum.in.www1.hephaestus.gitprovider.repository.Repository; - -@Component -public class RepositoryDTOConverter { - - public RepositoryInfoDTO convertToDTO(Repository repository) { - return new RepositoryInfoDTO( - repository.getId(), - repository.getName(), - repository.getNameWithOwner(), - repository.getDescription(), - repository.getHtmlUrl()); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryInfoDTO.java deleted file mode 100644 index d609944f..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/repository/dto/RepositoryInfoDTO.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.repository.dto; - -import org.springframework.lang.NonNull; -import com.fasterxml.jackson.annotation.JsonInclude; - -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public record RepositoryInfoDTO( - @NonNull Long id, - @NonNull String name, - @NonNull String nameWithOwner, - String description, - @NonNull String htmlUrl) { -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserController.java index 04258481..bd9ef741 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserController.java @@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserProfileDTO; - @RestController @RequestMapping("/user") public class UserController { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserInfoDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserInfoDTO.java similarity index 51% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserInfoDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserInfoDTO.java index d627241f..9aaca2c7 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserInfoDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserInfoDTO.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.gitprovider.user.dto; +package de.tum.in.www1.hephaestus.gitprovider.user; import org.springframework.lang.NonNull; import com.fasterxml.jackson.annotation.JsonInclude; @@ -10,4 +10,13 @@ public record UserInfoDTO( @NonNull String avatarUrl, @NonNull String name, @NonNull String htmlUrl) { + + public static UserInfoDTO fromUser(User user) { + return new UserInfoDTO( + user.getId(), + user.getLogin(), + user.getAvatarUrl(), + user.getName(), + user.getHtmlUrl()); + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserProfileDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserProfileDTO.java similarity index 61% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserProfileDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserProfileDTO.java index acf89eeb..34b2d128 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserProfileDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserProfileDTO.java @@ -1,4 +1,4 @@ -package de.tum.in.www1.hephaestus.gitprovider.user.dto; +package de.tum.in.www1.hephaestus.gitprovider.user; import java.time.OffsetDateTime; import java.util.List; @@ -6,9 +6,9 @@ import org.springframework.lang.NonNull; import com.fasterxml.jackson.annotation.JsonInclude; -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto.PullRequestReviewInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; @JsonInclude(JsonInclude.Include.NON_EMPTY) public record UserProfileDTO( diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserService.java index 17612791..75159b16 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/UserService.java @@ -1,28 +1,26 @@ package de.tum.in.www1.hephaestus.gitprovider.user; +import java.util.ArrayList; import java.util.Comparator; import java.time.OffsetDateTime; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import de.tum.in.www1.hephaestus.gitprovider.issue.Issue; +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueComment; +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueCommentRepository; +import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestInfoDTO; import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequestRepository; -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewInfoDTO; import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewRepository; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto.PullRequestReviewDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.dto.PullRequestReviewInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryInfoDTO; import de.tum.in.www1.hephaestus.gitprovider.repository.RepositoryRepository; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.repository.dto.RepositoryInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserProfileDTO; import jakarta.transaction.Transactional; @Service @@ -33,62 +31,63 @@ public class UserService { private final RepositoryRepository repositoryRepository; private final PullRequestRepository pullRequestRepository; private final PullRequestReviewRepository pullRequestReviewRepository; - private final UserDTOConverter userDTOConverter; - private final RepositoryDTOConverter repositoryDTOConverter; - private final PullRequestDTOConverter pullRequestDTOConverter; - private final PullRequestReviewDTOConverter pullRequestReviewDTOConverter; + private final IssueCommentRepository issueCommentRepository; public UserService( UserRepository userRepository, RepositoryRepository repositoryRepository, PullRequestRepository pullRequestRepository, PullRequestReviewRepository pullRequestReviewRepository, - UserDTOConverter userDTOConverter, - RepositoryDTOConverter repositoryDTOConverter, - PullRequestDTOConverter pullRequestDTOConverter, - PullRequestReviewDTOConverter pullRequestReviewDTOConverter) { + IssueCommentRepository issueCommentRepository) { this.userRepository = userRepository; this.repositoryRepository = repositoryRepository; this.pullRequestRepository = pullRequestRepository; this.pullRequestReviewRepository = pullRequestReviewRepository; - this.userDTOConverter = userDTOConverter; - this.repositoryDTOConverter = repositoryDTOConverter; - this.pullRequestDTOConverter = pullRequestDTOConverter; - this.pullRequestReviewDTOConverter = pullRequestReviewDTOConverter; + this.issueCommentRepository = issueCommentRepository; } @Transactional public Optional getUserProfile(String login) { logger.info("Getting user profile with login: " + login); - Optional optionalUser = userRepository.findByLogin(login).map(userDTOConverter::convertToDTO); + Optional optionalUser = userRepository.findByLogin(login).map(UserInfoDTO::fromUser); if (optionalUser.isEmpty()) { return Optional.empty(); } UserInfoDTO user = optionalUser.get(); OffsetDateTime firstContribution = pullRequestRepository.firstContributionByAuthorLogin(login).orElse(null); - List openPullRequests = pullRequestRepository.findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN)) + List openPullRequests = pullRequestRepository + .findAssignedByLoginAndStates(login, Set.of(Issue.State.OPEN)) .stream() - .map(pullRequestDTOConverter::convertToDTO) + .map(PullRequestInfoDTO::fromPullRequest) .toList(); List contributedRepositories = repositoryRepository.findContributedByLogin(login) .stream() - .map(repositoryDTOConverter::convertToDTO) + .map(RepositoryInfoDTO::fromRepository) .sorted(Comparator.comparing(RepositoryInfoDTO::name)) .toList(); - List reviewActivity = pullRequestReviewRepository.findAllByAuthorLoginSince(login, OffsetDateTime.now().minusDays(7)) + + // Review activity includes both pull request reviews and issue comments + List reviewActivity = pullRequestReviewRepository + .findAllByAuthorLoginSince(login, OffsetDateTime.now().minusDays(7)) .stream() - .map(pullRequestReviewDTOConverter::convertToDTO) - .sorted(Comparator.comparing(PullRequestReviewInfoDTO::submittedAt).reversed()) - .toList(); - + .map(PullRequestReviewInfoDTO::fromPullRequestReview) + .collect(Collectors.toCollection(ArrayList::new)); + reviewActivity.addAll( + issueCommentRepository + .findAllByAuthorLoginSince(login, OffsetDateTime.now().minusDays(7), true) + .stream() + .map(PullRequestReviewInfoDTO::fromIssueComment) + .toList() + ); + reviewActivity.sort(Comparator.comparing(PullRequestReviewInfoDTO::submittedAt).reversed()); + return Optional.of(new UserProfileDTO( user, firstContribution, contributedRepositories, reviewActivity, - openPullRequests - )); + openPullRequests)); } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserDTOConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserDTOConverter.java deleted file mode 100644 index 63e57f91..00000000 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/gitprovider/user/dto/UserDTOConverter.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.tum.in.www1.hephaestus.gitprovider.user.dto; - -import org.springframework.stereotype.Component; - -import de.tum.in.www1.hephaestus.gitprovider.user.User; - -@Component -public class UserDTOConverter { - - public UserInfoDTO convertToDTO(User user) { - return new UserInfoDTO( - user.getId(), - user.getLogin(), - user.getAvatarUrl(), - user.getName(), - user.getHtmlUrl()); - } -} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardController.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardController.java index f193a2f6..1f5064cd 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardController.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardController.java @@ -11,8 +11,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import de.tum.in.www1.hephaestus.leaderboard.dto.LeaderboardEntryDTO; - @RestController @RequestMapping("/leaderboard") public class LeaderboardController { diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/dto/LeaderboardEntryDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntryDTO.java similarity index 79% rename from server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/dto/LeaderboardEntryDTO.java rename to server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntryDTO.java index 65092943..34aa9004 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/dto/LeaderboardEntryDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntryDTO.java @@ -1,6 +1,6 @@ -package de.tum.in.www1.hephaestus.leaderboard.dto; +package de.tum.in.www1.hephaestus.leaderboard; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; import io.micrometer.common.lang.NonNull; public record LeaderboardEntryDTO( diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java index 51e195a8..e00e063b 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java @@ -16,13 +16,13 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueComment; +import de.tum.in.www1.hephaestus.gitprovider.issuecomment.IssueCommentRepository; import de.tum.in.www1.hephaestus.gitprovider.pullrequest.PullRequest; import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReview; import de.tum.in.www1.hephaestus.gitprovider.pullrequestreview.PullRequestReviewRepository; import de.tum.in.www1.hephaestus.gitprovider.user.User; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserDTOConverter; -import de.tum.in.www1.hephaestus.gitprovider.user.dto.UserInfoDTO; -import de.tum.in.www1.hephaestus.leaderboard.dto.LeaderboardEntryDTO; +import de.tum.in.www1.hephaestus.gitprovider.user.UserInfoDTO; import jakarta.transaction.Transactional; @Service @@ -30,16 +30,16 @@ public class LeaderboardService { private static final Logger logger = LoggerFactory.getLogger(LeaderboardService.class); private final PullRequestReviewRepository pullRequestReviewRepository; - private final UserDTOConverter userDTOConverter; + private final IssueCommentRepository issueCommentRepository; @Value("${monitoring.timeframe}") private int timeframe; public LeaderboardService( PullRequestReviewRepository pullRequestReviewRepository, - UserDTOConverter userDTOConverter) { + IssueCommentRepository issueCommentRepository) { this.pullRequestReviewRepository = pullRequestReviewRepository; - this.userDTOConverter = userDTOConverter; + this.issueCommentRepository = issueCommentRepository; } @Transactional @@ -55,13 +55,21 @@ public List createLeaderboard(Optional after, Op var beforeOffset = beforeCutOff.map(b -> b.atOffset(ZoneOffset.UTC)).orElse(OffsetDateTime.now()); List reviews = pullRequestReviewRepository.findAllInTimeframe(afterOffset, beforeOffset, repository); + List issueComments = issueCommentRepository.findAllInTimeframe(afterOffset, beforeOffset, + repository, true); Map usersById = reviews.stream().map(PullRequestReview::getAuthor) .collect(Collectors.toMap(User::getId, user -> user, (u1, u2) -> u1)); + + // Review activity Map> reviewsByUserId = reviews.stream() .collect(Collectors.groupingBy(review -> review.getAuthor().getId())); + Map> issueCommentsByUserId = issueComments.stream() + .collect(Collectors.groupingBy(comment -> comment.getAuthor().getId())); + Map scoresByUserId = reviewsByUserId.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, entry -> calculateTotalScore(entry.getValue()))); + .collect(Collectors.toMap(Map.Entry::getKey, entry -> calculateTotalScore(entry.getValue(), + issueCommentsByUserId.getOrDefault(entry.getKey(), List.of()).size()))); // Ranking (sorted by score descending) List rankingByUserId = scoresByUserId.entrySet().stream() @@ -74,8 +82,10 @@ public List createLeaderboard(Optional after, Op int rank = index + 1; Long userId = rankingByUserId.get(index); int score = scoresByUserId.get(userId); - UserInfoDTO user = userDTOConverter.convertToDTO(usersById.get(userId)); - List userReviews = reviewsByUserId.get(userId); + UserInfoDTO user = UserInfoDTO.fromUser(usersById.get(userId)); + List userReviews = reviewsByUserId.getOrDefault(userId, List.of()); + List userIssueComments = issueCommentsByUserId.getOrDefault(userId, List.of()); + int numberOfReviewedPRs = userReviews.stream().map(review -> review.getPullRequest().getId()) .collect(Collectors.toSet()).size(); int numberOfApprovals = (int) userReviews.stream() @@ -85,6 +95,8 @@ public List createLeaderboard(Optional after, Op int numberOfComments = (int) userReviews.stream() .filter(review -> review.getState() == PullRequestReview.State.COMMENTED) .filter(review -> review.getBody() != null).count(); + numberOfComments += userIssueComments.size(); + int numberOfUnknowns = (int) userReviews.stream() .filter(review -> review.getState() == PullRequestReview.State.UNKNOWN) .filter(review -> review.getBody() != null).count(); @@ -99,7 +111,7 @@ public List createLeaderboard(Optional after, Op return leaderboard; } - private int calculateTotalScore(List reviews) { + private int calculateTotalScore(List reviews, int numberOfIssueComments) { // Could contain multiple reviews for the same pull request Map> reviewsByPullRequestId = reviews.stream() .collect(Collectors.groupingBy(review -> review.getPullRequest().getId())); @@ -132,7 +144,7 @@ private int calculateTotalScore(List reviews) { double interactionScore = (approvalReviews * 1.5 + changesRequestedReviews * 2.0 + - (commentReviews + unknownReviews) + + (commentReviews + unknownReviews + numberOfIssueComments) + codeComments * 0.5); double complexityBonus = 1 + (complexityScore - 1) / 32.0;