Skip to content

Commit b1f3685

Browse files
lunnytechknowlogick
authored andcommitted
fix approvals limitation (#5521)
1 parent 58c4559 commit b1f3685

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

models/branches.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ func (protectBranch *ProtectedBranch) HasEnoughApprovals(pr *PullRequest) bool {
9999

100100
// GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist.
101101
func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 {
102-
reviews, err := GetReviewersByPullID(pr.ID)
102+
reviews, err := GetReviewersByPullID(pr.Issue.ID)
103103
if err != nil {
104104
log.Error(1, "GetUniqueApprovalsByPullRequestID:", err)
105105
return 0
106106
}
107+
107108
approvals := int64(0)
108109
userIDs := make([]int64, 0)
109110
for _, review := range reviews {

routers/repo/issue.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ func ViewIssue(ctx *context.Context) {
776776

777777
if issue.IsPull {
778778
pull := issue.PullRequest
779+
pull.Issue = issue
779780
canDelete := false
780781

781782
if ctx.IsSigned {
@@ -833,8 +834,9 @@ func ViewIssue(ctx *context.Context) {
833834
return
834835
}
835836
if pull.ProtectedBranch != nil {
836-
ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
837-
ctx.Data["GrantedApprovals"] = pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
837+
cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
838+
ctx.Data["IsBlockedByApprovals"] = pull.ProtectedBranch.RequiredApprovals > 0 && cnt < pull.ProtectedBranch.RequiredApprovals
839+
ctx.Data["GrantedApprovals"] = cnt
838840
}
839841
ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
840842

0 commit comments

Comments
 (0)