Skip to content

Commit

Permalink
add issue comments to leaderboard and profile
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Oct 27, 2024
1 parent 73e75d7 commit e5b8cd8
Show file tree
Hide file tree
Showing 29 changed files with 325 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;

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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.tum.in.www1.hephaestus.gitprovider.issuecomment.dto;
package de.tum.in.www1.hephaestus.gitprovider.issuecomment;

import java.time.OffsetDateTime;

import org.springframework.lang.NonNull;
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IssueComment, Long> {

@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<IssueComment> 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<IssueComment> findAllInTimeframe(
@Param("after") OffsetDateTime after,
@Param("before") OffsetDateTime before,
@Param("repository") Optional<String> repository,
@Param("onlyFromPullRequests") boolean onlyFromPullRequests);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public void syncIssueCommentsOfAllIssues(List<GHIssue> ghIssues, Optional<Offset
public void syncIssueCommentsOfIssue(GHIssue ghIssue, Optional<OffsetDateTime> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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<LabelInfoDTO> labels,
List<UserInfoDTO> 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());
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit e5b8cd8

Please sign in to comment.