Skip to content

Commit 90cdc51

Browse files
committed
fix: handle dismissed review state
1 parent 69af6e2 commit 90cdc51

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

contribs/github-bot/internal/requirements/reviewer.go

+11
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ func deduplicateReviews(reviews []*github.PullRequestReview) []*github.PullReque
3636
result = append(result, rev)
3737
added[rev.User.GetLogin()] = len(result) - 1
3838
}
39+
case utils.ReviewStateDismissed:
40+
// this state just dismisses any previous review, so remove previous
41+
// entry for this user if it exists.
42+
if ok {
43+
result[idx] = nil
44+
}
3945
default:
4046
panic(fmt.Sprintf("invalid review state %q", rev.GetState()))
4147
}
4248
}
49+
// Remove nil entries from the result (dismissed reviews).
50+
result = slices.DeleteFunc(result, func(r *github.PullRequestReview) bool {
51+
return r == nil
52+
})
53+
4354
return result
4455
}
4556

contribs/github-bot/internal/requirements/reviewer_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func Test_deduplicateReviews(t *testing.T) {
6868
{User: &github.User{Login: github.String("userB")}, State: github.String("CHANGES_REQUESTED")},
6969
},
7070
},
71+
{
72+
name: "two authors - approval/changes requested then dismissed",
73+
reviews: []*github.PullRequestReview{
74+
{User: &github.User{Login: github.String("user1")}, State: github.String("APPROVED")},
75+
{User: &github.User{Login: github.String("user1")}, State: github.String("DISMISSED")},
76+
{User: &github.User{Login: github.String("user2")}, State: github.String("CHANGES_REQUESTED")},
77+
{User: &github.User{Login: github.String("user2")}, State: github.String("DISMISSED")},
78+
},
79+
expected: []*github.PullRequestReview{},
80+
},
7181
}
7282

7383
for _, tt := range tests {

contribs/github-bot/internal/utils/github_const.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
ReviewStateApproved ReviewState = "APPROVED"
2424
ReviewStateChangesRequested ReviewState = "CHANGES_REQUESTED"
2525
ReviewStateCommented ReviewState = "COMMENTED"
26+
ReviewStateDismissed ReviewState = "DISMISSED"
2627
)
2728

2829
// Valid determines whether the ReviewState is one of the known ReviewStates.

0 commit comments

Comments
 (0)