fix approvals limitation (#5521)
This commit is contained in:
parent
58c4559d3b
commit
b1f3685015
2 changed files with 6 additions and 3 deletions
|
@ -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.
|
// 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 {
|
func (protectBranch *ProtectedBranch) GetGrantedApprovalsCount(pr *PullRequest) int64 {
|
||||||
reviews, err := GetReviewersByPullID(pr.ID)
|
reviews, err := GetReviewersByPullID(pr.Issue.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(1, "GetUniqueApprovalsByPullRequestID:", err)
|
log.Error(1, "GetUniqueApprovalsByPullRequestID:", err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
approvals := int64(0)
|
approvals := int64(0)
|
||||||
userIDs := make([]int64, 0)
|
userIDs := make([]int64, 0)
|
||||||
for _, review := range reviews {
|
for _, review := range reviews {
|
||||||
|
|
|
@ -776,6 +776,7 @@ func ViewIssue(ctx *context.Context) {
|
||||||
|
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
pull := issue.PullRequest
|
pull := issue.PullRequest
|
||||||
|
pull.Issue = issue
|
||||||
canDelete := false
|
canDelete := false
|
||||||
|
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
|
@ -833,8 +834,9 @@ func ViewIssue(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pull.ProtectedBranch != nil {
|
if pull.ProtectedBranch != nil {
|
||||||
ctx.Data["IsBlockedByApprovals"] = !pull.ProtectedBranch.HasEnoughApprovals(pull)
|
cnt := pull.ProtectedBranch.GetGrantedApprovalsCount(pull)
|
||||||
ctx.Data["GrantedApprovals"] = 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)
|
ctx.Data["IsPullBranchDeletable"] = canDelete && pull.HeadRepo != nil && git.IsBranchExist(pull.HeadRepo.RepoPath(), pull.HeadBranch)
|
||||||
|
|
||||||
|
|
Reference in a new issue