From b1f3685015246d3458f6d8c1d892eab076b3ed4a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 12 Dec 2018 07:49:33 +0800 Subject: [PATCH] fix approvals limitation (#5521) --- models/branches.go | 3 ++- routers/repo/issue.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/models/branches.go b/models/branches.go index f2bf9a80a0a..a1e97ffaaa3 100644 --- a/models/branches.go +++ b/models/branches.go @@ -99,11 +99,12 @@ func (protectBranch *ProtectedBranch) HasEnoughApprovals(pr *PullRequest) bool { // GetGrantedApprovalsCount returns the number of granted approvals for pr. A granted approval must be authored by a user in an approval whitelist. func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 { - reviews, err := GetReviewersByPullID(pr.ID) + reviews, err := GetReviewersByPullID(pr.Issue.ID) if err != nil { log.Error(1, "GetUniqueApprovalsByPullRequestID:", err) return 0 } + approvals := int64(0) userIDs := make([]int64, 0) for _, review := range reviews { diff --git a/routers/repo/issue.go b/routers/repo/issue.go index c04cc277468..e0fb4ac52f6 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -776,6 +776,7 @@ func ViewIssue(ctx *context.Context) { if issue.IsPull { pull := issue.PullRequest + pull.Issue = issue canDelete := false if ctx.IsSigned { @@ -833,8 +834,9 @@ func ViewIssue(ctx *context.Context) { return } if pull.ProtectedBranch != nil { - ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull) - ctx.Data["GrantedApprovals"] = pull.ProtectedBranch.GetGrantedApprovalsCount(pull) + cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull) + ctx.Data["IsBlockedByApprovals"] = pull.ProtectedBranch.RequiredApprovals > 0 && cnt < pull.ProtectedBranch.RequiredApprovals + ctx.Data["GrantedApprovals"] = cnt } ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)