Skip to content

Commit

Permalink
fix server side
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixTJDietrich committed Oct 26, 2024
1 parent db23fe7 commit b4c3b06
Show file tree
Hide file tree
Showing 33 changed files with 458 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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.leaderboard.dto.LeaderboardEntryDTO;
import io.hypersistence.utils.hibernate.type.util.ClassImportIntegrator;

public class ClassImportIntegratorIntegratorProvider implements IntegratorProvider {
Expand All @@ -30,14 +29,9 @@ public List<Integrator> getIntegrators() {
classes.add(MilestoneInfoDTO.class);
classes.add(PullRequestInfoDTO.class);
classes.add(IssueCommentInfoDTO.class);

classes.add(PullRequestReviewInfoDTO.class);
classes.add(PullRequestReviewInfoDTO.PullRequest.class);

classes.add(RepositoryInfoDTO.class);

classes.add(LeaderboardEntryDTO.class);

return List.of(new ClassImportIntegrator(classes));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.kohsuke.github.connector.GitHubConnector;

@Configuration
public class GitHubConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import de.tum.in.www1.hephaestus.gitprovider.common.AuthorAssociation;
import io.micrometer.common.lang.NonNull;

@Component
public class GitHubAuthorAssociationConverter implements Converter<GHCommentAuthorAssociation, AuthorAssociation> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.in.www1.hephaestus.gitprovider.issue.dto;

import java.time.OffsetDateTime;
import java.util.List;

import org.springframework.lang.NonNull;
Expand All @@ -17,9 +18,9 @@ public record IssueInfoDTO(
UserInfoDTO author,
List<LabelInfoDTO> labels,
List<UserInfoDTO> assignees,
@NonNull String repositoryNameWithOwner,
String repositoryNameWithOwner,
@NonNull String htmlUrl,
@NonNull String createdAt,
@NonNull String updatedAt
OffsetDateTime createdAt,
OffsetDateTime updatedAt
) {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.hephaestus.gitprovider.issuecomment.dto;

import java.time.OffsetDateTime;

import org.springframework.lang.NonNull;
import com.fasterxml.jackson.annotation.JsonInclude;

Expand All @@ -14,7 +16,6 @@ public record IssueCommentInfoDTO(
UserInfoDTO author,
IssueInfoDTO issue,
@NonNull String htmlUrl,
@NonNull String createdAt,
@NonNull String updatedAt) {

OffsetDateTime createdAt,
OffsetDateTime updatedAt) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.tum.in.www1.hephaestus.gitprovider.milestone.dto;

import java.time.OffsetDateTime;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.gitprovider.milestone.Milestone.State;
Expand All @@ -10,10 +12,10 @@ public record MilestoneInfoDTO(
@NonNull State state,
@NonNull String title,
String description,
String closedAt,
String dueOn,
OffsetDateTime closedAt,
OffsetDateTime dueOn,
@NonNull String htmlUrl,
@NonNull String createdAt,
@NonNull String updatedAt
OffsetDateTime createdAt,
OffsetDateTime updatedAt
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import de.tum.in.www1.hephaestus.gitprovider.pullrequest.dto.PullRequestInfoDTO;

@Repository
public interface PullRequestRepository extends JpaRepository<PullRequest, Long> {

Expand All @@ -23,29 +21,18 @@ SELECT MIN(p.createdAt)
WHERE p.author.login = :authorLogin
""")
Optional<OffsetDateTime> firstContributionByAuthorLogin(@Param("authorLogin") String authorLogin);

@Query("""
SELECT new PullRequestInfoDTO(
p.id,
p.number,
p.title,
p.state,
p.commentCount,
new UserInfoDTO(p.author.id, p.author.login, p.author.avatarUrl, p.author.name, p.author.htmlUrl, p.author.createdAt, p.author.updatedAt),
(SELECT new LabelInfoDTO(l.id, l.name, l.color) FROM Label l WHERE l MEMBER OF p.labels ORDER BY l.name),
(SELECT new UserInfoDTO(u.id, u.login, u.avatarUrl, u.name, u.htmlUrl, u.createdAt, u.updatedAt) FROM User u WHERE u MEMBER OF p.assignees ORDER BY u.login),
p.repository.nameWithOwner,
p.additions,
p.deletions,
p.mergedAt,
p.htmlUrl,
p.createdAt,
p.updatedAt)
SELECT p
FROM PullRequest p
JOIN FETCH p.labels
JOIN FETCH p.author
JOIN FETCH p.assignees
JOIN FETCH p.repository
WHERE (p.author.login = :assigneeLogin OR :assigneeLogin IN (SELECT u.login FROM p.assignees u)) AND p.state IN :states
ORDER BY p.createdAt DESC
""")
List<PullRequestInfoDTO> findAssignedByLoginAndStates(
List<PullRequest> findAssignedByLoginAndStates(
@Param("assigneeLogin") String assigneeLogin,
@Param("states") Set<PullRequest.State> states);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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,
RepositoryInfoDTO repository,
@NonNull String htmlUrl) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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.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(),
repositoryDTOConverter.convertToDTO(pullRequest.getRepository()),
pullRequest.getHtmlUrl());
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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)
Expand All @@ -19,11 +21,13 @@ public record PullRequestInfoDTO(
UserInfoDTO author,
List<LabelInfoDTO> labels,
List<UserInfoDTO> assignees,
@NonNull String repositoryNameWithOwner,
RepositoryInfoDTO repository,
@NonNull Integer additions,
@NonNull Integer deletions,
@NonNull String mergedAt,
OffsetDateTime mergedAt,
OffsetDateTime closedAt,
@NonNull String htmlUrl,
@NonNull String createdAt,
@NonNull String updatedAt) {
OffsetDateTime createdAt,
OffsetDateTime updatedAt) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class PullRequestReview {
private String body;

// We handle dismissed in a separate field to keep the original state
@NonNull
@Enumerated(EnumType.STRING)
private PullRequestReview.State state;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
package de.tum.in.www1.hephaestus.gitprovider.pullrequestreview;

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;
import org.springframework.stereotype.Repository;

@Repository
public interface PullRequestReviewRepository extends JpaRepository<PullRequestReview, Long> {

Optional<PullRequestReview> findByAuthor_Login(String authorLogin);

Optional<PullRequestReview> findByPullRequest(PullRequestReview pullRequest);
@Query("""
SELECT prr
FROM PullRequestReview prr
JOIN FETCH prr.author
JOIN FETCH prr.pullRequest
JOIN FETCH prr.pullRequest.repository
JOIN FETCH prr.comments
WHERE prr.author.login = :authorLogin AND prr.submittedAt >= :activitySince
ORDER BY prr.submittedAt DESC
""")
List<PullRequestReview> findAllByAuthorLoginSince(
@Param("authorLogin") String authorLogin,
@Param("activitySince") OffsetDateTime activitySince);

@Query("""
SELECT pr
FROM PullRequestReview pr
JOIN FETCH pr.comments
WHERE pr.id = :reviewId
SELECT prr
FROM PullRequestReview prr
JOIN FETCH prr.author
JOIN FETCH prr.pullRequest
JOIN FETCH prr.pullRequest.repository
JOIN FETCH prr.comments
WHERE
prr.submittedAt BETWEEN :after AND :before
AND (:repository IS NULL OR prr.pullRequest.repository.nameWithOwner = :repository)
AND prr.author.type = 'USER'
ORDER BY prr.submittedAt DESC
""")
Optional<PullRequestReview> findByIdWithEagerComments(Long reviewId);
List<PullRequestReview> findAllInTimeframe(
@Param("after") OffsetDateTime after,
@Param("before") OffsetDateTime before,
@Param("repository") Optional<String> repository);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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());
}
}
Loading

0 comments on commit b4c3b06

Please sign in to comment.