Skip to content

Commit

Permalink
Take pending reviews into account
Browse files Browse the repository at this point in the history
  • Loading branch information
ukupat committed Jul 4, 2024
1 parent b7e9323 commit 5bcf334
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34528,8 +34528,10 @@ exports["default"] = moveOrArchiveCards;
async function getActivePullRequestReviews() {
const reviews = await (0, github_1.getPullRequestReviews)();
const requestedReviewers = await (0, github_1.getPullRequestRequestedReviewers)();
// Filters out pending reviews
const submittedReviews = reviews?.filter((review) => review.state !== 'PENDING');
// Filters in only the latest review per person
const latestReviews = Array.from(reviews?.reduce((map, review) => map.set(review.user?.id, review), new Map()).values() || []);
const latestReviews = Array.from(submittedReviews?.reduce((map, review) => map.set(review.user?.id, review), new Map()).values() || []);
// Filters out reviews by people who have been re-requested for review
return latestReviews.filter((r) => !requestedReviewers?.users.some((u) => u.id === r.user?.id));
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remato/trello-integration-action",
"version": "9.5.1",
"version": "9.5.2",
"license": "MIT",
"description": "GitHub Action to integrate Github pull requests with Trello cards",
"main": "dist/index.js",
Expand Down
45 changes: 45 additions & 0 deletions src/actions/moveOrArchiveCards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ describe('Moving cards', () => {
expect(moveCardToList).toHaveBeenCalledWith('card', 'changes-requested-list-id', undefined)
})

it('moves the card to Changes requested list after approving changes', async () => {
getPullRequestReviewsMock.mockResolvedValue([
{ state: 'APPROVED', user: { id: 'user-1' } },
{ state: 'CHANGES_REQUESTED', user: { id: 'user-1' } },
])

await moveOrArchiveCards(conf, ['card'], pr)

expect(moveCardToList).toHaveBeenCalledWith('card', 'changes-requested-list-id', undefined)
})

it('moves the card to Changes requested list while writing another review', async () => {
getPullRequestReviewsMock.mockResolvedValue([
{ state: 'CHANGES_REQUESTED', user: { id: 'user-1' } },
{ state: 'PENDING', user: { id: 'user-1' } },
])

await moveOrArchiveCards(conf, ['card'], pr)

expect(moveCardToList).toHaveBeenCalledWith('card', 'changes-requested-list-id', undefined)
})

it('skips move when review is re-requested', async () => {
getPullRequestRequestedReviewersMock.mockResolvedValue({ users: [{ id: 'user-id' }] })

Expand Down Expand Up @@ -93,6 +115,17 @@ describe('Moving cards', () => {
expect(moveCardToList).toHaveBeenCalledWith('card', 'approved-list-id', undefined)
})

it('moves the card to Approved list after requesting changes', async () => {
getPullRequestReviewsMock.mockResolvedValue([
{ state: 'CHANGES_REQUESTED', user: { id: 'user-1' } },
{ state: 'APPROVED', user: { id: 'user-1' } },
])

await moveOrArchiveCards(conf, ['card'], pr)

expect(moveCardToList).toHaveBeenCalledWith('card', 'approved-list-id', undefined)
})

it('skips move when someone else has requested changes', async () => {
getPullRequestReviewsMock.mockResolvedValue([
{ state: 'APPROVED', user: { id: 'user-1' } },
Expand All @@ -104,6 +137,18 @@ describe('Moving cards', () => {
expect(moveCardToList).not.toHaveBeenCalled()
})

it('skips move when someone else has requested changes while writing another review', async () => {
getPullRequestReviewsMock.mockResolvedValue([
{ state: 'APPROVED', user: { id: 'user-1' } },
{ state: 'CHANGES_REQUESTED', user: { id: 'user-2' } },
{ state: 'PENDING', user: { id: 'user-2' } },
])

await moveOrArchiveCards(conf, ['card'], pr)

expect(moveCardToList).not.toHaveBeenCalled()
})

it('skips move when list not configured', async () => {
await moveOrArchiveCards({}, ['card'], pr)
expect(moveCardToList).not.toHaveBeenCalled()
Expand Down
5 changes: 4 additions & 1 deletion src/actions/moveOrArchiveCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ async function getActivePullRequestReviews(): Promise<{ state: string }[]> {
const reviews = await getPullRequestReviews()
const requestedReviewers = await getPullRequestRequestedReviewers()

// Filters out pending reviews
const submittedReviews = reviews?.filter((review) => review.state !== 'PENDING')

// Filters in only the latest review per person
const latestReviews = Array.from(
reviews?.reduce((map, review) => map.set(review.user?.id, review), new Map()).values() || [],
submittedReviews?.reduce((map, review) => map.set(review.user?.id, review), new Map()).values() || [],
)

// Filters out reviews by people who have been re-requested for review
Expand Down

0 comments on commit 5bcf334

Please sign in to comment.