diff --git a/workflow-pr/maintainership.go b/workflow-pr/maintainership.go index 456c049..05f3519 100644 --- a/workflow-pr/maintainership.go +++ b/workflow-pr/maintainership.go @@ -125,9 +125,13 @@ func IsPrjGitPRApproved(gitea common.GiteaMaintainershipInterface, giteapr Gitea } } + requiredReviews := slices.Clone(config.Reviewers) for _, r := range prjPR.reviews { - + if !r.Stale && r.State == common.ReviewStateApproved && slices.Contains(requiredReviews, r.User.UserName) { + idx := slices.Index(requiredReviews, r.User.UserName) + requiredReviews = slices.Delete(requiredReviews, idx, idx+1) + } } - return true, nil + return len(requiredReviews) == 0, nil } diff --git a/workflow-pr/maintainership_test.go b/workflow-pr/maintainership_test.go index c743055..6ffeffc 100644 --- a/workflow-pr/maintainership_test.go +++ b/workflow-pr/maintainership_test.go @@ -179,7 +179,7 @@ func TestReviewApproval(t *testing.T) { }{ { name: "Maintainer not approved", - pr: &models.PullRequest{Body: "", Index: 10, RequestedReviewers: []*models.User{}}, + pr: &models.PullRequest{Body: "PR: foo/foo#10", Index: 10, RequestedReviewers: []*models.User{}}, reviews: []*models.PullReview{}, maintainerFile: []byte(`{"foo": ["bingo"]}`), @@ -187,11 +187,11 @@ func TestReviewApproval(t *testing.T) { approved: false, }, { - name: "Maintainer approved", - pr: &models.PullRequest{Body: "", Index: 10, RequestedReviewers: []*models.User{}}, + name: "Maintainer approved", + pr: &models.PullRequest{Body: "", Index: 10, RequestedReviewers: []*models.User{}}, reviews: []*models.PullReview{ &models.PullReview{ - Body: "wow!", + Body: "wow!", Stale: false, State: common.ReviewStateApproved, User: &models.User{ @@ -217,8 +217,8 @@ func TestReviewApproval(t *testing.T) { mi.EXPECT().FetchMaintainershipFile("foo", common.DefaultGitPrj, "bar").Return(test.maintainerFile, nil) approved, err := IsPrjGitPRApproved(mi, pri, config, 10) - if approved == test.approved { - t.Error("Unexpected approved or err:", err) + if approved != test.approved { + t.Error("Unexpected approve state:", approved, "vs. expected", test.approved, ", or err:", err) } if err != nil { t.Error("Unexpected error", err)