Skip to content

Commit

Permalink
Merge branch 'develop' into feature/leaderboard-page
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Sep 13, 2024
2 parents eee3cd7 + bafe553 commit 3937532
Show file tree
Hide file tree
Showing 45 changed files with 902 additions and 178 deletions.
91 changes: 87 additions & 4 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/UserDTO"
/user/{login}/full:
get:
tags:
- user
operationId: getFullUser
parameters:
- name: login
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/User"
/pullrequest/{id}:
get:
tags:
Expand Down Expand Up @@ -101,6 +119,20 @@ paths:
type: array
items:
$ref: "#/components/schemas/PullRequest"
/leaderboard:
get:
tags:
- leaderboard
operationId: getLeaderboard
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/LeaderboardEntry"
/admin:
get:
tags:
Expand Down Expand Up @@ -210,8 +242,6 @@ components:
items:
$ref: "#/components/schemas/IssueCommentDTO"
IssueComment:
required:
- body
type: object
properties:
id:
Expand Down Expand Up @@ -300,12 +330,38 @@ components:
submittedAt:
type: string
format: date-time
comments:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestReviewComment"
pullRequest:
$ref: "#/components/schemas/PullRequest"
PullRequestReviewComment:
required:
- commit
type: object
properties:
id:
type: integer
format: int64
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
body:
type: string
author:
$ref: "#/components/schemas/User"
review:
$ref: "#/components/schemas/PullRequestReview"
commit:
type: string
Repository:
required:
- defaultBranch
- description
- name
- nameWithOwner
- url
Expand Down Expand Up @@ -382,13 +438,40 @@ components:
type: array
items:
$ref: "#/components/schemas/PullRequest"
comments:
issueComments:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/IssueComment"
reviewComments:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestReviewComment"
reviews:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestReview"
LeaderboardEntry:
type: object
properties:
githubName:
type: string
name:
type: string
score:
type: integer
format: int32
total:
type: integer
format: int32
changesRequested:
type: integer
format: int32
approvals:
type: integer
format: int32
comments:
type: integer
format: int32
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package de.tum.in.www1.hephaestus.codereview.base;

import de.tum.in.www1.hephaestus.codereview.user.User;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;
import lombok.AllArgsConstructor;
Expand All @@ -20,11 +19,10 @@
@AllArgsConstructor
@ToString(callSuper = true)
public abstract class Comment extends BaseGitServiceEntity {
@Lob
@Basic(fetch = FetchType.EAGER)
@Column(columnDefinition = "TEXT")
protected String body;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "author_id")
@ToString.Exclude
protected User author;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@NoArgsConstructor
@ToString(callSuper = true)
public class IssueComment extends Comment {
@ManyToOne(optional = false)
@ManyToOne
@JoinColumn(name = "pullrequest_id", referencedColumnName = "id")
@ToString.Exclude
private PullRequest pullRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.tum.in.www1.hephaestus.codereview.comment.review;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.base.Comment;
import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReview;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@Table(name = "pull_request_review_comment")
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class PullRequestReviewComment extends Comment {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "review_id", referencedColumnName = "id")
@ToString.Exclude
private PullRequestReview review;

@NonNull
private String commit;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.tum.in.www1.hephaestus.codereview.comment.review;

import org.kohsuke.github.GHPullRequestReviewComment;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntityConverter;

@Component
public class PullRequestReviewCommentConverter
extends BaseGitServiceEntityConverter<GHPullRequestReviewComment, PullRequestReviewComment> {

@Override
public PullRequestReviewComment convert(@NonNull GHPullRequestReviewComment source) {
PullRequestReviewComment comment = new PullRequestReviewComment();
convertBaseFields(source, comment);
comment.setBody(source.getBody());
comment.setCommit(source.getCommitId());
return comment;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.tum.in.www1.hephaestus.codereview.comment.review;

import org.springframework.data.jpa.repository.JpaRepository;

public interface PullRequestReviewCommentRepository extends JpaRepository<PullRequestReviewComment, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PullRequest extends BaseGitServiceEntity {

private OffsetDateTime mergedAt;

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "author_id")
@ToString.Exclude
private User author;
Expand All @@ -58,7 +58,7 @@ public class PullRequest extends BaseGitServiceEntity {
@ToString.Exclude
private Set<PullRequestReview> reviews = new HashSet<>();

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne
@JoinColumn(name = "repository_id", referencedColumnName = "id")
@ToString.Exclude
private Repository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity;
import de.tum.in.www1.hephaestus.codereview.comment.review.ReviewComment;
import de.tum.in.www1.hephaestus.codereview.comment.review.PullRequestReviewComment;
import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.codereview.user.User;
import jakarta.persistence.CascadeType;
Expand All @@ -30,30 +30,26 @@
@ToString(callSuper = true)
public class PullRequestReview extends BaseGitServiceEntity {

@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "author_id")
@ToString.Exclude
private User author;

@NonNull
private PullRequestReviewState state;

private OffsetDateTime createdAt;

private OffsetDateTime submittedAt;

private OffsetDateTime updatedAt;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "review")
@ToString.Exclude
private Set<ReviewComment> comments = new HashSet<>();
private Set<PullRequestReviewComment> comments = new HashSet<>();

@ManyToOne(optional = false)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "pullrequest_id", referencedColumnName = "id")
@ToString.Exclude
private PullRequest pullRequest;

public void addComment(ReviewComment comment) {
public void addComment(PullRequestReviewComment comment) {
comments.add(comment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,11 @@ public PullRequestReview convert(@NonNull GHPullRequestReview source) {
PullRequestReview review = new PullRequestReview();
convertBaseFields(source, review);
review.setState(convertState(source.getState()));
try {
review.setCreatedAt(convertToOffsetDateTime(source.getCreatedAt()));
} catch (IOException e) {
logger.error("Failed to convert submittedAt field for source {}: {}", source.getId(), e.getMessage());
}
try {
review.setSubmittedAt(convertToOffsetDateTime(source.getSubmittedAt()));
} catch (IOException e) {
logger.error("Failed to convert submittedAt field for source {}: {}", source.getId(), e.getMessage());
}
try {
review.setUpdatedAt(convertToOffsetDateTime(source.getUpdatedAt()));
} catch (IOException e) {
logger.error("Failed to convert submittedAt field for source {}: {}", source.getId(), e.getMessage());
}
return review;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -11,4 +12,12 @@ public interface PullRequestReviewRepository extends JpaRepository<PullRequestRe
Optional<PullRequestReview> findByAuthor_Login(String authorLogin);

Optional<PullRequestReview> findByPullRequest(PullRequestReview pullRequest);

@Query("""
SELECT pr
FROM PullRequestReview pr
JOIN FETCH pr.comments
WHERE pr.id = :reviewId
""")
Optional<PullRequestReview> findByIdWithEagerComments(Long reviewId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.micrometer.common.lang.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Getter;
Expand Down Expand Up @@ -45,7 +44,7 @@ public class Repository extends BaseGitServiceEntity {

String homepage;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "repository", fetch = FetchType.EAGER)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "repository")
@ToString.Exclude
private Set<PullRequest> pullRequests = new HashSet<>();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package de.tum.in.www1.hephaestus.codereview.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

@org.springframework.stereotype.Repository
public interface RepositoryRepository
extends JpaRepository<Repository, Long> {

Repository findByNameWithOwner(String nameWithOwner);

@Query("""
SELECT r
FROM Repository r
JOIN FETCH r.pullRequests
WHERE r.nameWithOwner = :nameWithOwner
""")
Repository findByNameWithOwnerWithEagerPullRequests(String nameWithOwner);
}
Loading

0 comments on commit 3937532

Please sign in to comment.