Skip to content

Commit

Permalink
Add Review and Reviewed PR Count to Leaderboard Activity (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Felix T.J. Dietrich <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent 2bf309a commit e0c3fd3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ components:
rank:
type: integer
format: int32
numberOfReviewedPRs:
type: integer
format: int32
changesRequested:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class LeaderboardEntry {
private UserType type;
private int score;
private int rank;
private int numberOfReviewedPRs;
private PullRequestReviewDTO[] changesRequested;
private PullRequestReviewDTO[] approvals;
private PullRequestReviewDTO[] comments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public List<LeaderboardEntry> createLeaderboard(Optional<LocalDate> after, Optio
return null;
}
AtomicInteger score = new AtomicInteger(0);
Set<Integer> reviewedPRs = new HashSet<>();
Set<PullRequestReviewDTO> changesRequestedSet = new HashSet<>();
Set<PullRequestReviewDTO> approvedSet = new HashSet<>();
Set<PullRequestReviewDTO> commentSet = new HashSet<>();
Expand All @@ -69,6 +70,7 @@ public List<LeaderboardEntry> createLeaderboard(Optional<LocalDate> after, Optio
PullRequestReviewDTO reviewDTO = new PullRequestReviewDTO(review.getId(), review.getCreatedAt(),
review.getUpdatedAt(), review.getSubmittedAt(), review.getState());

reviewedPRs.add(review.getPullRequest().getNumber());
switch (review.getState()) {
case CHANGES_REQUESTED:
changesRequestedSet.add(reviewDTO);
Expand All @@ -88,6 +90,7 @@ public List<LeaderboardEntry> createLeaderboard(Optional<LocalDate> after, Optio
return new LeaderboardEntry(user.getLogin(), user.getAvatarUrl(), user.getName(), user.getType(),
score.get(),
0, // preliminary rank
reviewedPRs.size(),
changesRequestedSet.toArray(new PullRequestReviewDTO[changesRequestedSet.size()]),
approvedSet.toArray(new PullRequestReviewDTO[approvedSet.size()]),
commentSet.toArray(new PullRequestReviewDTO[commentSet.size()]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface LeaderboardEntry {
type?: LeaderboardEntry.TypeEnum;
score?: number;
rank?: number;
numberOfReviewedPRs?: number;
changesRequested?: Array<PullRequestReviewDTO>;
approvals?: Array<PullRequestReviewDTO>;
comments?: Array<PullRequestReviewDTO>;
Expand Down
9 changes: 8 additions & 1 deletion webapp/src/app/home/leaderboard/leaderboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
</td>
<td appTableCell class="text-center">{{ entry.score }}</td>
<td appTableCell class="py-2">
<div class="flex items-center gap-3">
<div class="flex items-center gap-2">
<div class="flex items-center gap-1 text-github-muted-foreground" title="Total reviewed PRs">
<ng-icon [svg]="octGitPullRequest" size="16" />
{{ entry.numberOfReviewedPRs }}
</div>
<div class="flex items-center text-github-muted-foreground">
<ng-icon [svg]="octChevronLeft" size="16" />
</div>
@if (entry.changesRequested && entry.changesRequested.length > 0) {
<div class="flex items-center gap-1 text-github-danger-foreground" title="Changes Requested">
<ng-icon [svg]="octFileDiff" size="16" />
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/app/home/leaderboard/leaderboard.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, input } from '@angular/core';
import { NgIconComponent } from '@ng-icons/core';
import { octFileDiff, octCheck, octComment } from '@ng-icons/octicons';
import { octFileDiff, octCheck, octComment, octGitPullRequest, octChevronLeft } from '@ng-icons/octicons';
import { LeaderboardEntry } from 'app/core/modules/openapi';
import { AvatarFallbackComponent } from 'app/ui/avatar/avatar-fallback.component';
import { AvatarImageComponent } from 'app/ui/avatar/avatar-image.component';
Expand Down Expand Up @@ -37,6 +37,8 @@ export class LeaderboardComponent {
protected octFileDiff = octFileDiff;
protected octCheck = octCheck;
protected octComment = octComment;
protected octGitPullRequest = octGitPullRequest;
protected octChevronLeft = octChevronLeft;

leaderboard = input<LeaderboardEntry[]>();
}
12 changes: 8 additions & 4 deletions webapp/src/app/home/leaderboard/leaderboard.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const leaderboardEntries: LeaderboardEntry[] = [
changesRequested: generateReviews(3, PullRequestReviewDTO.StateEnum.ChangesRequested),
approvals: generateReviews(5, PullRequestReviewDTO.StateEnum.Approved),
comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented),
rank: 1
rank: 1,
numberOfReviewedPRs: 10
},
{
githubName: 'FelixTJDietrich',
Expand All @@ -36,7 +37,8 @@ const leaderboardEntries: LeaderboardEntry[] = [
changesRequested: generateReviews(1, PullRequestReviewDTO.StateEnum.ChangesRequested),
approvals: generateReviews(1, PullRequestReviewDTO.StateEnum.Approved),
comments: generateReviews(14, PullRequestReviewDTO.StateEnum.Commented),
rank: 2
rank: 2,
numberOfReviewedPRs: 16
},
{
githubName: 'krusche',
Expand All @@ -47,7 +49,8 @@ const leaderboardEntries: LeaderboardEntry[] = [
changesRequested: [],
approvals: generateReviews(3, PullRequestReviewDTO.StateEnum.Approved),
comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented),
rank: 3
rank: 3,
numberOfReviewedPRs: 3
},
{
githubName: 'shadcn',
Expand All @@ -58,7 +61,8 @@ const leaderboardEntries: LeaderboardEntry[] = [
changesRequested: [],
approvals: [],
comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented),
rank: 4
rank: 4,
numberOfReviewedPRs: 1
}
];

Expand Down

0 comments on commit e0c3fd3

Please sign in to comment.