This commit is contained in:
Adam Majer 2024-12-11 01:12:59 +01:00
parent a7d81d6013
commit 68ba45ca9c
2 changed files with 12 additions and 8 deletions

View File

@ -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
}

View File

@ -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)