Skip to content

Commit

Permalink
Add Reviews to PullRequest entities (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Felix T.J. Dietrich <[email protected]>
  • Loading branch information
3 people authored Sep 9, 2024
1 parent 5cf278d commit 23c3967
Show file tree
Hide file tree
Showing 25 changed files with 483 additions and 52 deletions.
76 changes: 72 additions & 4 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ components:
items:
$ref: "#/components/schemas/IssueCommentDTO"
IssueComment:
required:
- body
type: object
properties:
id:
Expand Down Expand Up @@ -259,19 +257,79 @@ components:
- OPEN
mergedAt:
type: string
format: date-time
author:
$ref: "#/components/schemas/User"
comments:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/IssueComment"
reviews:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/PullRequestReview"
repository:
$ref: "#/components/schemas/Repository"
PullRequestReview:
required:
- state
type: object
properties:
id:
type: integer
format: int64
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
author:
$ref: "#/components/schemas/User"
state:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- DISMISSED
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 @@ -348,8 +406,18 @@ 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"
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void convertBaseFields(S source, T target) {
}
}

private OffsetDateTime convertToOffsetDateTime(Date date) {
protected OffsetDateTime convertToOffsetDateTime(Date date) {
return date != null ? date.toInstant().atOffset(ZoneOffset.UTC) : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.tum.in.www1.hephaestus.codereview.base;

import de.tum.in.www1.hephaestus.codereview.user.User;
import jakarta.persistence.Basic;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@MappedSuperclass
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
public abstract class Comment extends BaseGitServiceEntity {
@Lob
@Basic(fetch = FetchType.EAGER)
protected String body;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
@ToString.Exclude
protected User author;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
package de.tum.in.www1.hephaestus.codereview.comment;

import jakarta.persistence.Table;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity;
import de.tum.in.www1.hephaestus.codereview.base.Comment;
import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.codereview.user.User;
import jakarta.persistence.Basic;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -24,17 +17,7 @@
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class IssueComment extends BaseGitServiceEntity {
@NonNull
@Lob
@Basic(fetch = FetchType.EAGER)
private String body;

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

public class IssueComment extends Comment {
@ManyToOne(optional = false)
@JoinColumn(name = "pullrequest_id", referencedColumnName = "id")
@ToString.Exclude
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.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(optional = false)
@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
@@ -1,12 +1,14 @@
package de.tum.in.www1.hephaestus.codereview.pullrequest;

import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.Set;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity;
import de.tum.in.www1.hephaestus.codereview.comment.IssueComment;
import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReview;
import de.tum.in.www1.hephaestus.codereview.repository.Repository;
import de.tum.in.www1.hephaestus.codereview.user.User;
import jakarta.persistence.Table;
Expand Down Expand Up @@ -41,7 +43,7 @@ public class PullRequest extends BaseGitServiceEntity {
@NonNull
private IssueState state;

private String mergedAt;
private OffsetDateTime mergedAt;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
Expand All @@ -50,10 +52,22 @@ public class PullRequest extends BaseGitServiceEntity {

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

@OneToMany(cascade = CascadeType.ALL, mappedBy = "pullRequest")
@ToString.Exclude
private Set<PullRequestReview> reviews = new HashSet<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "repository_id", referencedColumnName = "id")
@ToString.Exclude
private Repository repository;

public void addComment(IssueComment comment) {
comments.add(comment);
}

public void addReview(PullRequestReview review) {
reviews.add(review);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

@Component
public class PullRequestConverter extends BaseGitServiceEntityConverter<GHPullRequest, PullRequest> {

@Override
public PullRequest convert(@NonNull GHPullRequest source) {
IssueState state = convertState(source.getState());
Expand All @@ -17,7 +18,7 @@ public PullRequest convert(@NonNull GHPullRequest source) {
pullRequest.setUrl(source.getHtmlUrl().toString());
pullRequest.setState(state);
if (source.getMergedAt() != null) {
pullRequest.setMergedAt(source.getMergedAt().toString());
pullRequest.setMergedAt(convertToOffsetDateTime(source.getMergedAt()));
}
return pullRequest;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.tum.in.www1.hephaestus.codereview.pullrequest.review;

import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.Set;

import org.springframework.lang.NonNull;

import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity;
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;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Entity
@Table(name = "pull_request_review")
@Getter
@Setter
@NoArgsConstructor
@ToString(callSuper = true)
public class PullRequestReview extends BaseGitServiceEntity {

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

@NonNull
private PullRequestReviewState state;

private OffsetDateTime submittedAt;

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

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

public void addComment(PullRequestReviewComment comment) {
comments.add(comment);
}
}
Loading

0 comments on commit 23c3967

Please sign in to comment.