From 434bcc462954cbddf6fd0fe923e5953bb28d51d2 Mon Sep 17 00:00:00 2001 From: GODrums Date: Thu, 10 Oct 2024 05:20:42 +0200 Subject: [PATCH] Support for PR Labels --- .../pullrequest/PullRequestConverter.java | 4 +-- .../pullrequest/PullRequestDTO.java | 3 +- .../pullrequest/PullRequestLabel.java | 4 ++- .../codereview/user/UserService.java | 31 +++++++++++----- .../core/issue-card/issue-card.component.html | 11 +++++- .../core/issue-card/issue-card.component.ts | 36 +++++++++++++++++++ 6 files changed, 73 insertions(+), 16 deletions(-) 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 f065f597..22dbcdcf 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 @@ -78,9 +78,7 @@ 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()); + PullRequestLabel pullRequestLabel = new PullRequestLabel(label.getName(), label.getColor()); pullRequestLabels.add(pullRequestLabel); } return pullRequestLabels; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java index 1bb56c97..8477a0bb 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullRequestDTO.java @@ -29,7 +29,6 @@ public PullRequestDTO(Long id, String title, int number, String url, IssueState OffsetDateTime updatedAt, OffsetDateTime mergedAt, Set labels, RepositoryDTO repository) { this(id, title, number, url, state, additions, deletions, createdAt, updatedAt, mergedAt, null, null, - null, - repository); + labels, repository); } } 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 index 28c666e2..1dd201f8 100644 --- 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 @@ -1,8 +1,9 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; import jakarta.persistence.Embeddable; -import lombok.Getter; +import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -10,6 +11,7 @@ @Getter @Setter @NoArgsConstructor +@AllArgsConstructor public class PullRequestLabel { @NonNull private String name; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java index fbafbc56..24850674 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/user/UserService.java @@ -16,6 +16,7 @@ import de.tum.in.www1.hephaestus.codereview.base.BaseGitServiceEntity; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequestDTO; +import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReview; import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReviewDTO; import de.tum.in.www1.hephaestus.codereview.repository.RepositoryDTO; @@ -61,14 +62,28 @@ public Optional getUserProfileDTO(String login) { .min(OffsetDateTime::compareTo).orElse(null); Set repositories = mapToDTO(user.getPullRequests(), pr -> pr.getRepository().getNameWithOwner(), (r1, r2) -> r1.compareTo(r2)); - Set pullRequests = mapToDTO(user.getPullRequests(), pr -> new PullRequestDTO(pr.getId(), - pr.getTitle(), pr.getNumber(), pr.getUrl(), pr.getState(), pr.getAdditions(), pr.getDeletions(), - pr.getCreatedAt(), pr.getUpdatedAt(), null, pr.getPullRequestLabels(), - new RepositoryDTO(pr.getRepository().getName(), - pr.getRepository().getNameWithOwner(), null, - pr.getRepository().getUrl())), + Set pullRequests = getPullRequestDTOs(user.getPullRequests()); + Set activity = getPullRequestReviewDTOs(user.getReviews()); + + return Optional.of(new UserProfileDTO(user.getId(), user.getLogin(), user.getAvatarUrl(), firstContribution, + repositories, activity, pullRequests)); + } + + private Set getPullRequestDTOs(Set pullRequests) { + return mapToDTO(pullRequests, + pr -> new PullRequestDTO( + pr.getId(), pr.getTitle(), pr.getNumber(), pr.getUrl(), pr.getState(), pr.getAdditions(), + pr.getDeletions(), + pr.getCreatedAt(), pr.getUpdatedAt(), null, + pr.getPullRequestLabels(), + new RepositoryDTO(pr.getRepository().getName(), + pr.getRepository().getNameWithOwner(), null, + pr.getRepository().getUrl())), (pr1, pr2) -> pr1.createdAt().compareTo(pr2.createdAt())); - Set activity = mapToDTO(user.getReviews(), re -> { + } + + private Set getPullRequestReviewDTOs(Set reviews) { + return mapToDTO(reviews, re -> { PullRequest pr = re.getPullRequest(); return new PullRequestReviewDTO(re.getId(), re.getCreatedAt(), re.getUpdatedAt(), re.getSubmittedAt(), re.getState(), re.getUrl(), @@ -78,8 +93,6 @@ public Optional getUserProfileDTO(String login) { pr.getRepository().getNameWithOwner(), null, pr.getRepository().getUrl()))); }, (prr1, prr2) -> prr1.submittedAt().compareTo(prr2.submittedAt())); - return Optional.of(new UserProfileDTO(user.getId(), user.getLogin(), user.getAvatarUrl(), firstContribution, - repositories, activity, pullRequests)); } private Set mapToDTO(Set entities, Function mapper, diff --git a/webapp/src/app/core/issue-card/issue-card.component.html b/webapp/src/app/core/issue-card/issue-card.component.html index c99a4ad9..c6c34136 100644 --- a/webapp/src/app/core/issue-card/issue-card.component.html +++ b/webapp/src/app/core/issue-card/issue-card.component.html @@ -31,7 +31,16 @@
@for (label of pullRequestLabels(); track label.name) { - {{ label.name }} + @let labelColors = calculateLabelColors(label.color); + + {{ label.name }} + }
diff --git a/webapp/src/app/core/issue-card/issue-card.component.ts b/webapp/src/app/core/issue-card/issue-card.component.ts index 91d4f4f1..e491e1fe 100644 --- a/webapp/src/app/core/issue-card/issue-card.component.ts +++ b/webapp/src/app/core/issue-card/issue-card.component.ts @@ -31,6 +31,10 @@ export class IssueCardComponent { protected readonly octFileDiff = octFileDiff; protected readonly octGitPullRequestClosed = octGitPullRequestClosed; + ngOnInit() { + console.log('pullRequestLabels', this.pullRequestLabels()); + } + displayCreated = computed(() => dayjs(this.createdAt())); getMostRecentReview() { @@ -42,5 +46,37 @@ export class IssueCardComponent { }); } + calculateLabelColors(githubColor: string | undefined) { + if (!githubColor) { + return { + borderColor: '#27272a', + color: '#000000', + backgroundColor: '#09090b' + }; + } + const borderColor = this.shadeHexColor(githubColor, -0.5); + const backgroundColor = this.shadeHexColor(githubColor, -0.75); + console.log('borderColor', { + borderColor: borderColor, + color: githubColor, + backgroundColor: backgroundColor + }); + return { + borderColor: borderColor, + color: `#${githubColor}`, + backgroundColor: backgroundColor + }; + } + + shadeHexColor(color: string, percent: number) { + let f = parseInt(color, 16), + t = percent < 0 ? 0 : 255, + p = percent < 0 ? percent * -1 : percent, + R = f >> 16, + G = (f >> 8) & 0x00ff, + B = f & 0x0000ff; + return '#' + (0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1); + } + computedClass = computed(() => cn('border border-border bg-card rounded-lg p-4 w-72', this.class())); }