Skip to content

Commit

Permalink
#82: add labels and number on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
iam-flo committed Sep 16, 2024
1 parent 3eb2ffe commit 8d72dcb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
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;
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;
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;
Expand All @@ -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.
Expand Down Expand Up @@ -71,6 +68,9 @@ public class PullRequest extends BaseGitServiceEntity {
@ToString.Exclude
private Repository repository;

@ElementCollection
private Set<PullRequestLabel> pullRequestLabels = new HashSet<>();

public void addComment(IssueComment comment) {
comments.add(comment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -64,4 +70,14 @@ private IssueState convertState(org.kohsuke.github.GHIssueState state) {
}
}

private Set<PullRequestLabel> convertLabels(Collection<GHLabel> labels) {
Set<PullRequestLabel> pullRequestLabels = new HashSet<>();
for (GHLabel label : labels) {
PullRequestLabel pullRequestLabel = new PullRequestLabel();
pullRequestLabel.setName(label.getName());
pullRequestLabel.setColor(label.getColor());
pullRequestLabels.add(pullRequestLabel);
}
return pullRequestLabels;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 8d72dcb

Please sign in to comment.