diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java index 7822ba3a..16a18fe5 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequest.java @@ -4,6 +4,7 @@ import java.util.HashSet; import java.util.Set; +import jakarta.persistence.*; import org.springframework.lang.NonNull; import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; @@ -11,13 +12,6 @@ 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; -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 lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -36,6 +30,9 @@ public class PullRequest extends BaseGitServiceEntity { @NonNull private String url; + @NonNull + private int number; + /** * State of the PullRequest. * Does not include the state of the merge. @@ -71,6 +68,9 @@ public class PullRequest extends BaseGitServiceEntity { @ToString.Exclude private Repository repository; + @ElementCollection + private Set pullRequestLabels = new HashSet<>(); + public void addComment(IssueComment comment) { comments.add(comment); } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java index ba10d1d1..956b453d 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestConverter.java @@ -1,7 +1,11 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import java.io.IOException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.kohsuke.github.GHLabel; import org.kohsuke.github.GHPullRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,6 +27,8 @@ public PullRequest convert(@NonNull GHPullRequest source) { pullRequest.setTitle(source.getTitle()); pullRequest.setUrl(source.getHtmlUrl().toString()); pullRequest.setState(state); + pullRequest.setNumber(source.getNumber()); + pullRequest.setPullRequestLabels(convertLabels(source.getLabels())); try { pullRequest.setAdditions(source.getAdditions()); } catch (IOException e) { @@ -64,4 +70,14 @@ private IssueState convertState(org.kohsuke.github.GHIssueState state) { } } + private Set convertLabels(Collection labels) { + Set pullRequestLabels = new HashSet<>(); + for (GHLabel label : labels) { + PullRequestLabel pullRequestLabel = new PullRequestLabel(); + pullRequestLabel.setName(label.getName()); + pullRequestLabel.setColor(label.getColor()); + pullRequestLabels.add(pullRequestLabel); + } + return pullRequestLabels; + } } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestLabel.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestLabel.java new file mode 100644 index 00000000..cc4c1803 --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestLabel.java @@ -0,0 +1,15 @@ +package de.tum.in.www1.hephaestus.codereview.pullrequest; + +import jakarta.persistence.Embeddable; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Embeddable +@Getter +@Setter +@NoArgsConstructor +public class PullRequestLabel { + private String name; + private String color; +}