Skip to content

Commit

Permalink
fix: approval duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
AKharytonchyk committed Mar 28, 2024
1 parent 0897abf commit 70bb58d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/PullRequestsApprovals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const PullRequestsApprovals: React.FC<PullRequestsApprovalsProps> = ({
if (!octokit) return;
octokit
.getPRApprovals(owner, repo, prNumber)
.then((response) => setApprovals(response.data as Approvals[]));
.then((response) => setApprovals(response as Approvals[]));

return () => {
setApprovals([]);
Expand Down
9 changes: 8 additions & 1 deletion src/service/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export class GitService {
}

async getPRApprovals(owner: string, repo: string, prNumber: number) {
return this.octokit.pulls.listReviews({owner, repo, pull_number: prNumber});
const reviews = await this.octokit.pulls.listReviews({owner, repo, pull_number: prNumber});

return reviews.data.reduce((acc: any, review: any) => {
if (!acc[review.user.login] || new Date(acc[review.user.login].submitted_at) < new Date(review.submitted_at)) {
acc[review.user.login] = review;
}
return acc;
}, {} as Record<string, any>).values();
}
}

0 comments on commit 70bb58d

Please sign in to comment.