aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/review.go
diff options
context:
space:
mode:
authorNanguan Lin <70063547+lng2020@users.noreply.github.com>2023-09-29 07:24:36 +0800
committerGitHub <noreply@github.com>2023-09-28 23:24:36 +0000
commit15a504cb9f83fbe40df252159f68c8ed510c99d1 (patch)
tree41320b315753711e622b267ab552d86436344040 /models/issues/review.go
parent9d9cebc5e7da242245bd2418a43cc7f294fb485b (diff)
downloadgitea-15a504cb9f83fbe40df252159f68c8ed510c99d1.tar.gz
gitea-15a504cb9f83fbe40df252159f68c8ed510c99d1.zip
Fix the approval count of PR when there is no protection branch rule (#27272)
As title ![ksnip_20230926-115158](https://github.com/go-gitea/gitea/assets/70063547/a60be44a-06ad-421e-ba27-e4e0adfa5db7)
Diffstat (limited to 'models/issues/review.go')
-rw-r--r--models/issues/review.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/models/issues/review.go b/models/issues/review.go
index 931f1a2ba7..f7ef16f6c9 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -231,7 +231,7 @@ type CreateReviewOptions struct {
}
// IsOfficialReviewer check if at least one of the provided reviewers can make official reviews in issue (counts towards required approvals)
-func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_model.User) (bool, error) {
+func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewer *user_model.User) (bool, error) {
pr, err := GetPullRequestByIssueID(ctx, issue.ID)
if err != nil {
return false, err
@@ -242,14 +242,21 @@ func IsOfficialReviewer(ctx context.Context, issue *Issue, reviewers ...*user_mo
return false, err
}
if rule == nil {
- return false, nil
+ // if no rule is found, then user with write access can make official reviews
+ err := pr.LoadBaseRepo(ctx)
+ if err != nil {
+ return false, err
+ }
+ writeAccess, err := access_model.HasAccessUnit(ctx, reviewer, pr.BaseRepo, unit.TypeCode, perm.AccessModeWrite)
+ if err != nil {
+ return false, err
+ }
+ return writeAccess, nil
}
- for _, reviewer := range reviewers {
- official, err := git_model.IsUserOfficialReviewer(ctx, rule, reviewer)
- if official || err != nil {
- return official, err
- }
+ official, err := git_model.IsUserOfficialReviewer(ctx, rule, reviewer)
+ if official || err != nil {
+ return official, err
}
return false, nil
@@ -578,7 +585,9 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
return nil, nil
}
- official, err := IsOfficialReviewer(ctx, issue, reviewer, doer)
+ // if the reviewer is an official reviewer,
+ // remove the official flag in the all previous reviews
+ official, err := IsOfficialReviewer(ctx, issue, reviewer)
if err != nil {
return nil, err
} else if official {