Skip to content

Commit

Permalink
Support for PR Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Oct 10, 2024
1 parent 42b587f commit 434bcc4
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ 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());
PullRequestLabel pullRequestLabel = new PullRequestLabel(label.getName(), label.getColor());
pullRequestLabels.add(pullRequestLabel);
}
return pullRequestLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public PullRequestDTO(Long id, String title, int number, String url, IssueState
OffsetDateTime updatedAt,
OffsetDateTime mergedAt, Set<PullRequestLabel> labels, RepositoryDTO repository) {
this(id, title, number, url, state, additions, deletions, createdAt, updatedAt, mergedAt, null, null,
null,
repository);
labels, repository);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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;

@Embeddable
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PullRequestLabel {
@NonNull
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -61,14 +62,28 @@ public Optional<UserProfileDTO> getUserProfileDTO(String login) {
.min(OffsetDateTime::compareTo).orElse(null);
Set<String> repositories = mapToDTO(user.getPullRequests(), pr -> pr.getRepository().getNameWithOwner(),
(r1, r2) -> r1.compareTo(r2));
Set<PullRequestDTO> 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<PullRequestDTO> pullRequests = getPullRequestDTOs(user.getPullRequests());
Set<PullRequestReviewDTO> activity = getPullRequestReviewDTOs(user.getReviews());

return Optional.of(new UserProfileDTO(user.getId(), user.getLogin(), user.getAvatarUrl(), firstContribution,
repositories, activity, pullRequests));
}

private Set<PullRequestDTO> getPullRequestDTOs(Set<PullRequest> 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<PullRequestReviewDTO> activity = mapToDTO(user.getReviews(), re -> {
}

private Set<PullRequestReviewDTO> getPullRequestReviewDTOs(Set<PullRequestReview> reviews) {
return mapToDTO(reviews, re -> {
PullRequest pr = re.getPullRequest();
return new PullRequestReviewDTO(re.getId(),
re.getCreatedAt(), re.getUpdatedAt(), re.getSubmittedAt(), re.getState(), re.getUrl(),
Expand All @@ -78,8 +93,6 @@ public Optional<UserProfileDTO> 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 <T extends BaseGitServiceEntity, G> Set<G> mapToDTO(Set<T> entities, Function<T, G> mapper,
Expand Down
11 changes: 10 additions & 1 deletion webapp/src/app/core/issue-card/issue-card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
</a>
<div class="flex gap-1 flex-wrap">
@for (label of pullRequestLabels(); track label.name) {
<span class="px-2 py-1 rounded-full text-xs mr-2 text-neutral-100/95" [style.background-color]="label.color">{{ label.name }}</span>
@let labelColors = calculateLabelColors(label.color);
<span
class="px-2 py-0.5 rounded-full text-xs mr-2 text-neutral-100/95"
[style.border-width.px]="'0.5'"
[style.background-color]="labelColors.backgroundColor"
[style.color]="labelColors.color"
[style.border-color]="labelColors.borderColor"
>
{{ label.name }}
</span>
}
</div>
</div>
36 changes: 36 additions & 0 deletions webapp/src/app/core/issue-card/issue-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class IssueCardComponent {
protected readonly octFileDiff = octFileDiff;
protected readonly octGitPullRequestClosed = octGitPullRequestClosed;

ngOnInit() {

Check warning on line 34 in webapp/src/app/core/issue-card/issue-card.component.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Lifecycle interface 'OnInit' should be implemented for method 'ngOnInit'. (https://angular.dev/style-guide#style-09-01)
console.log('pullRequestLabels', this.pullRequestLabels());
}

displayCreated = computed(() => dayjs(this.createdAt()));

getMostRecentReview() {
Expand All @@ -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()));
}

0 comments on commit 434bcc4

Please sign in to comment.