diff --git a/server/application-server/openapi.yaml b/server/application-server/openapi.yaml index 53a612d0..2b04452c 100644 --- a/server/application-server/openapi.yaml +++ b/server/application-server/openapi.yaml @@ -232,6 +232,9 @@ components: updatedAt: type: string format: date-time + number: + type: integer + format: int32 title: type: string url: @@ -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 diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/review/PullRequestReviewDTO.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/review/PullRequestReviewDTO.java new file mode 100644 index 00000000..92e2564b --- /dev/null +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/review/PullRequestReviewDTO.java @@ -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) { +} diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntry.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntry.java index 0faba666..28115cf1 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntry.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardEntry.java @@ -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; @@ -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; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java index 74fcea6f..952ec62f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/leaderboard/LeaderboardService.java @@ -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; @@ -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; @@ -47,10 +50,11 @@ public List 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 changesRequestedSet = new HashSet<>(); + Set approvedSet = new HashSet<>(); + Set commentSet = new HashSet<>(); + user.getReviews().stream() .filter(review -> (review.getCreatedAt() != null && review.getCreatedAt().isAfter(cutOffTime)) || (review.getUpdatedAt() != null && review.getUpdatedAt().isAfter(cutOffTime))) @@ -58,16 +62,17 @@ public List createLeaderboard() { 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())); @@ -75,9 +80,9 @@ public List createLeaderboard() { 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 diff --git a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES index 1840a28c..e40c7a6a 100644 --- a/webapp/src/app/core/modules/openapi/.openapi-generator/FILES +++ b/webapp/src/app/core/modules/openapi/.openapi-generator/FILES @@ -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 diff --git a/webapp/src/app/core/modules/openapi/model/leaderboard-entry.ts b/webapp/src/app/core/modules/openapi/model/leaderboard-entry.ts index 91663d60..eeb83ebf 100644 --- a/webapp/src/app/core/modules/openapi/model/leaderboard-entry.ts +++ b/webapp/src/app/core/modules/openapi/model/leaderboard-entry.ts @@ -9,6 +9,7 @@ * https://openapi-generator.tech * Do not edit the class manually. */ +import { PullRequestReviewDTO } from './pull-request-review-dto'; export interface LeaderboardEntry { @@ -18,9 +19,9 @@ export interface LeaderboardEntry { type?: LeaderboardEntry.TypeEnum; score?: number; rank?: number; - changesRequested?: number; - approvals?: number; - comments?: number; + changesRequested?: Array; + approvals?: Array; + comments?: Array; } export namespace LeaderboardEntry { export type TypeEnum = 'USER' | 'BOT'; diff --git a/webapp/src/app/core/modules/openapi/model/models.ts b/webapp/src/app/core/modules/openapi/model/models.ts index 81d76b51..967af558 100644 --- a/webapp/src/app/core/modules/openapi/model/models.ts +++ b/webapp/src/app/core/modules/openapi/model/models.ts @@ -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'; diff --git a/webapp/src/app/core/modules/openapi/model/pull-request-review-dto.ts b/webapp/src/app/core/modules/openapi/model/pull-request-review-dto.ts new file mode 100644 index 00000000..b4947f88 --- /dev/null +++ b/webapp/src/app/core/modules/openapi/model/pull-request-review-dto.ts @@ -0,0 +1,31 @@ +/** + * Hephaestus API + * API documentation for the Hephaestus application server. + * + * The version of the OpenAPI document: 0.0.1 + * Contact: felixtj.dietrich@tum.de + * + * 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 + }; +} + + diff --git a/webapp/src/app/core/modules/openapi/model/pull-request.ts b/webapp/src/app/core/modules/openapi/model/pull-request.ts index 0224aa04..f1fa06ad 100644 --- a/webapp/src/app/core/modules/openapi/model/pull-request.ts +++ b/webapp/src/app/core/modules/openapi/model/pull-request.ts @@ -19,6 +19,7 @@ export interface PullRequest { id?: number; createdAt?: string; updatedAt?: string; + number?: number; title: string; url: string; /** diff --git a/webapp/src/app/home/leaderboard/leaderboard.component.html b/webapp/src/app/home/leaderboard/leaderboard.component.html index af9a5c8d..73b269bd 100644 --- a/webapp/src/app/home/leaderboard/leaderboard.component.html +++ b/webapp/src/app/home/leaderboard/leaderboard.component.html @@ -24,22 +24,22 @@ {{ entry.score }} - @if (entry.changesRequested && entry.changesRequested > 0) { + @if (entry.changesRequested && entry.changesRequested.length > 0) {
- {{ entry.changesRequested }} + {{ entry.changesRequested.length }}
} - @if (entry.approvals && entry.approvals > 0) { + @if (entry.approvals && entry.approvals.length > 0) {
- {{ entry.approvals }} + {{ entry.approvals.length }}
} - @if (entry.comments && entry.comments > 0) { + @if (entry.comments && entry.comments.length > 0) {
- {{ entry.comments }} + {{ entry.comments.length }}
} diff --git a/webapp/src/app/home/leaderboard/leaderboard.component.ts b/webapp/src/app/home/leaderboard/leaderboard.component.ts index 3feb3dc8..dd01ba24 100644 --- a/webapp/src/app/home/leaderboard/leaderboard.component.ts +++ b/webapp/src/app/home/leaderboard/leaderboard.component.ts @@ -39,4 +39,9 @@ export class LeaderboardComponent { protected octComment = octComment; leaderboard = input(); + + // run on leaderboard changes + ngOnChanges() { + console.log('Leaderboard changes: ', this.leaderboard()); + } }