Skip to content

Commit

Permalink
Fix: Ignore own Issue Comments for Score Calculation (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums authored Dec 7, 2024
1 parent 566ae85 commit 88bd599
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<LeaderboardEntryDTO> createLeaderboard(
Collectors.toMap(Map.Entry::getKey, entry ->
calculateTotalScore(
entry.getValue(),
issueCommentsByUserId.getOrDefault(entry.getKey(), List.of()).size()
issueCommentsByUserId.getOrDefault(entry.getKey(), List.of())
)
)
);
Expand All @@ -117,6 +117,7 @@ public List<LeaderboardEntryDTO> createLeaderboard(
List<PullRequestInfoDTO> reviewedPullRequests = userReviews
.stream()
.map(review -> review.getPullRequest())
.filter(pullRequest -> pullRequest.getAuthor().getId() != userId)
// First collect to a map keyed by PR ID to ensure uniqueness
.collect(
Collectors.groupingBy(
Expand Down Expand Up @@ -179,7 +180,8 @@ public List<LeaderboardEntryDTO> createLeaderboard(
return leaderboard;
}

private int calculateTotalScore(List<PullRequestReview> reviews, int numberOfIssueComments) {
private int calculateTotalScore(List<PullRequestReview> reviews, List<IssueComment> issueComments) {
int numberOfIssueComments = issueComments.stream().filter(issueComment -> issueComment.getIssue().getAuthor().getId() != issueComment.getAuthor().getId()).collect(Collectors.toList()).size();
// Could contain multiple reviews for the same pull request
Map<Long, List<PullRequestReview>> reviewsByPullRequestId = reviews
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public double calculateReviewScore(IssueComment issueComment) {
}
pullRequest = optionalPR.get();
}
if (pullRequest.getAuthor().getId() == issueComment.getAuthor().getId()) {
return 0;
}

int complexityScore = calculateComplexityScore(pullRequest);

Expand Down

0 comments on commit 88bd599

Please sign in to comment.