mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 17:24:22 +00:00 
			
		
		
		
	Fix the approval count of PR when there is no protection branch rule (#27272)
As title 
This commit is contained in:
		@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user