Skip to content

Commit

Permalink
Respond with reviews instead of counter
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Sep 18, 2024
1 parent 2707cc7 commit f8d3792
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 27 deletions.
38 changes: 33 additions & 5 deletions server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ components:
updatedAt:
type: string
format: date-time
number:
type: integer
format: int32
title:
type: string
url:
Expand Down Expand Up @@ -450,11 +453,36 @@ components:
type: integer
format: int32
changesRequested:
type: integer
format: int32
type: array
items:
$ref: "#/components/schemas/PullRequestReviewDTO"
approvals:
type: integer
format: int32
type: array
items:
$ref: "#/components/schemas/PullRequestReviewDTO"
comments:
type: array
items:
$ref: "#/components/schemas/PullRequestReviewDTO"
PullRequestReviewDTO:
type: object
properties:
id:
type: integer
format: int32
format: int64
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
submittedAt:
type: string
format: date-time
state:
type: string
enum:
- COMMENTED
- APPROVED
- CHANGES_REQUESTED
- DISMISSED
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.tum.in.www1.hephaestus.codereview.pullrequest.review;

import java.time.OffsetDateTime;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record PullRequestReviewDTO(Long id, OffsetDateTime createdAt, OffsetDateTime updatedAt,
OffsetDateTime submittedAt, PullRequestReviewState state) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.tum.in.www1.hephaestus.leaderboard;

import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReviewDTO;
import de.tum.in.www1.hephaestus.codereview.user.UserType;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -19,7 +21,7 @@ public class LeaderboardEntry {
private UserType type;
private int score;
private int rank;
private int changesRequested;
private int approvals;
private int comments;
private PullRequestReviewDTO[] changesRequested;
private PullRequestReviewDTO[] approvals;
private PullRequestReviewDTO[] comments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

Expand All @@ -16,6 +18,7 @@
import org.springframework.stereotype.Service;

import de.tum.in.www1.hephaestus.codereview.pullrequest.PullRequest;
import de.tum.in.www1.hephaestus.codereview.pullrequest.review.PullRequestReviewDTO;
import de.tum.in.www1.hephaestus.codereview.user.User;
import de.tum.in.www1.hephaestus.codereview.user.UserService;
import de.tum.in.www1.hephaestus.codereview.user.UserType;
Expand Down Expand Up @@ -47,37 +50,39 @@ public List<LeaderboardEntry> createLeaderboard() {
return null;
}
logger.info("User: " + user.getLogin());
AtomicInteger comments = new AtomicInteger(0);
AtomicInteger changesRequested = new AtomicInteger(0);
AtomicInteger changesApproved = new AtomicInteger(0);
AtomicInteger score = new AtomicInteger(0);
Set<PullRequestReviewDTO> changesRequestedSet = new HashSet<>();
Set<PullRequestReviewDTO> approvedSet = new HashSet<>();
Set<PullRequestReviewDTO> commentSet = new HashSet<>();

user.getReviews().stream()
.filter(review -> (review.getCreatedAt() != null && review.getCreatedAt().isAfter(cutOffTime))
|| (review.getUpdatedAt() != null && review.getUpdatedAt().isAfter(cutOffTime)))
.forEach(review -> {
if (review.getPullRequest().getAuthor().getLogin().equals(user.getLogin())) {
return;
}
PullRequestReviewDTO reviewDTO = new PullRequestReviewDTO(review.getId(), review.getCreatedAt(),
review.getUpdatedAt(), review.getSubmittedAt(), review.getState());
switch (review.getState()) {
case CHANGES_REQUESTED:
changesRequested.incrementAndGet();
changesRequestedSet.add(reviewDTO);
break;
case APPROVED:
changesApproved.incrementAndGet();
approvedSet.add(reviewDTO);
break;
default:
comments.incrementAndGet();
logger.info("Commented Review: " + review.getPullRequest().getNumber());
commentSet.add(reviewDTO);
break;
}
score.addAndGet(calculateScore(review.getPullRequest()));
});
return new LeaderboardEntry(user.getLogin(), user.getAvatarUrl(), user.getName(), user.getType(),
score.get(),
0, // preliminary rank
changesRequested.get(),
changesApproved.get(),
comments.get());
changesRequestedSet.toArray(new PullRequestReviewDTO[changesRequestedSet.size()]),
approvedSet.toArray(new PullRequestReviewDTO[approvedSet.size()]),
commentSet.toArray(new PullRequestReviewDTO[commentSet.size()]));
}).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));

// update ranks by score
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ model/leaderboard-entry.ts
model/models.ts
model/pull-request-dto.ts
model/pull-request-review-comment.ts
model/pull-request-review-dto.ts
model/pull-request-review.ts
model/pull-request.ts
model/repository-dto.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { PullRequestReviewDTO } from './pull-request-review-dto';


export interface LeaderboardEntry {
Expand All @@ -18,9 +19,9 @@ export interface LeaderboardEntry {
type?: LeaderboardEntry.TypeEnum;
score?: number;
rank?: number;
changesRequested?: number;
approvals?: number;
comments?: number;
changesRequested?: Array<PullRequestReviewDTO>;
approvals?: Array<PullRequestReviewDTO>;
comments?: Array<PullRequestReviewDTO>;
}
export namespace LeaderboardEntry {
export type TypeEnum = 'USER' | 'BOT';
Expand Down
1 change: 1 addition & 0 deletions webapp/src/app/core/modules/openapi/model/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './pull-request';
export * from './pull-request-dto';
export * from './pull-request-review';
export * from './pull-request-review-comment';
export * from './pull-request-review-dto';
export * from './repository';
export * from './repository-dto';
export * from './user';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Hephaestus API
* API documentation for the Hephaestus application server.
*
* The version of the OpenAPI document: 0.0.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


export interface PullRequestReviewDTO {
id?: number;
createdAt?: string;
updatedAt?: string;
submittedAt?: string;
state?: PullRequestReviewDTO.StateEnum;
}
export namespace PullRequestReviewDTO {
export type StateEnum = 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'DISMISSED';
export const StateEnum = {
Commented: 'COMMENTED' as StateEnum,
Approved: 'APPROVED' as StateEnum,
ChangesRequested: 'CHANGES_REQUESTED' as StateEnum,
Dismissed: 'DISMISSED' as StateEnum
};
}


1 change: 1 addition & 0 deletions webapp/src/app/core/modules/openapi/model/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface PullRequest {
id?: number;
createdAt?: string;
updatedAt?: string;
number?: number;
title: string;
url: string;
/**
Expand Down
12 changes: 6 additions & 6 deletions webapp/src/app/home/leaderboard/leaderboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
</td>
<td appTableCell class="text-center">{{ entry.score }}</td>
<td appTableCell class="flex items-center gap-3">
@if (entry.changesRequested && entry.changesRequested > 0) {
@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" />
{{ entry.changesRequested }}
{{ entry.changesRequested.length }}
</div>
}
@if (entry.approvals && entry.approvals > 0) {
@if (entry.approvals && entry.approvals.length > 0) {
<div class="flex items-center gap-1 text-github-success-foreground" title="Approvals">
<ng-icon [svg]="octCheck" size="16" />
{{ entry.approvals }}
{{ entry.approvals.length }}
</div>
}
@if (entry.comments && entry.comments > 0) {
@if (entry.comments && entry.comments.length > 0) {
<div class="flex items-center gap-1 text-github-muted-foreground" title="Comments">
<ng-icon [svg]="octComment" size="16" />
{{ entry.comments }}
{{ entry.comments.length }}
</div>
}
</td>
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/app/home/leaderboard/leaderboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ export class LeaderboardComponent {
protected octComment = octComment;

leaderboard = input<LeaderboardEntry[]>();

// run on leaderboard changes
ngOnChanges() {

Check warning on line 44 in webapp/src/app/home/leaderboard/leaderboard.component.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Lifecycle interface 'OnChanges' should be implemented for method 'ngOnChanges'. (https://angular.dev/style-guide#style-09-01)
console.log('Leaderboard changes: ', this.leaderboard());
}
}

0 comments on commit f8d3792

Please sign in to comment.