From a25f336abcca3c44705a354641a5b6d243620d15 Mon Sep 17 00:00:00 2001 From: James Lakin Date: Thu, 31 Oct 2019 09:00:40 +0000 Subject: [PATCH 1/2] Show approvals on the PR list page --- models/branches.go | 23 ++++++++++++----------- routers/repo/issue.go | 9 ++++++++- templates/repo/issue/list.tmpl | 8 ++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/models/branches.go b/models/branches.go index c5f227f1e5a1e..4684939fed3e7 100644 --- a/models/branches.go +++ b/models/branches.go @@ -31,17 +31,18 @@ type ProtectedBranch struct { BranchName string `xorm:"UNIQUE(s)"` CanPush bool `xorm:"NOT NULL DEFAULT false"` EnableWhitelist bool - WhitelistUserIDs []int64 `xorm:"JSON TEXT"` - WhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"` - WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"` - MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"` - MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"` - StatusCheckContexts []string `xorm:"JSON TEXT"` - ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"` - ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"` + WhitelistUserIDs []int64 `xorm:"JSON TEXT"` + WhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"` + WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"` + MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"` + MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"` + StatusCheckContexts []string `xorm:"JSON TEXT"` + ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"` + ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"` + GrantedApprovalsCount int64 CreatedUnix timeutil.TimeStamp `xorm:"created"` UpdatedUnix timeutil.TimeStamp `xorm:"updated"` } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 9a691471d54d6..3a22a337823f1 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -232,8 +232,15 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB ctx.ServerError("LoadPullRequest", err) return } + pull := issues[i].PullRequest - commitStatus[issues[i].PullRequest.ID], _ = issues[i].PullRequest.GetLastCommitStatus() + if err := pull.LoadProtectedBranch(); err == nil { + if pull.ProtectedBranch != nil && pull.ProtectedBranch.RequiredApprovals != 0 { + pull.ProtectedBranch.GrantedApprovalsCount = pull.ProtectedBranch.GetGrantedApprovalsCount(pull) + } + } + + commitStatus[pull.ID], _ = pull.GetLastCommitStatus() } } diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index d68e6dac26b38..6bd285244f7c9 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -222,6 +222,14 @@ {{.Name}} {{end}} + {{if .IsPull}} + {{if .PullRequest.ProtectedBranch}} + {{if .PullRequest.ProtectedBranch.RequiredApprovals}} + {{.PullRequest.ProtectedBranch.GrantedApprovalsCount}} / {{.PullRequest.ProtectedBranch.RequiredApprovals}} + {{end}} + {{end}} + {{end}} + {{if .NumComments}} {{.NumComments}} {{end}} From 43b3e7df98827c6378b0572f4ddfd7ab1f89a9bd Mon Sep 17 00:00:00 2001 From: James Lakin Date: Fri, 1 Nov 2019 12:02:54 +0000 Subject: [PATCH 2/2] Remove extra property on ProtectedBranch for PR approvals --- models/branches.go | 23 +++++++++++------------ routers/repo/issue.go | 15 +++++++++++---- templates/repo/issue/list.tmpl | 6 ++---- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/models/branches.go b/models/branches.go index 4684939fed3e7..c5f227f1e5a1e 100644 --- a/models/branches.go +++ b/models/branches.go @@ -31,18 +31,17 @@ type ProtectedBranch struct { BranchName string `xorm:"UNIQUE(s)"` CanPush bool `xorm:"NOT NULL DEFAULT false"` EnableWhitelist bool - WhitelistUserIDs []int64 `xorm:"JSON TEXT"` - WhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"` - WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"` - MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"` - MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"` - StatusCheckContexts []string `xorm:"JSON TEXT"` - ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"` - ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` - RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"` - GrantedApprovalsCount int64 + WhitelistUserIDs []int64 `xorm:"JSON TEXT"` + WhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + EnableMergeWhitelist bool `xorm:"NOT NULL DEFAULT false"` + WhitelistDeployKeys bool `xorm:"NOT NULL DEFAULT false"` + MergeWhitelistUserIDs []int64 `xorm:"JSON TEXT"` + MergeWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"` + StatusCheckContexts []string `xorm:"JSON TEXT"` + ApprovalsWhitelistUserIDs []int64 `xorm:"JSON TEXT"` + ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"` + RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"` CreatedUnix timeutil.TimeStamp `xorm:"created"` UpdatedUnix timeutil.TimeStamp `xorm:"updated"` } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 3a22a337823f1..3c044905f65a0 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -216,6 +216,8 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB } var commitStatus = make(map[int64]*models.CommitStatus, len(issues)) + var requiredApprovals = make(map[int64]int64, len(issues)) + var approvals = make(map[int64]int64, len(issues)) // Get posters. for i := range issues { @@ -234,10 +236,13 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB } pull := issues[i].PullRequest - if err := pull.LoadProtectedBranch(); err == nil { - if pull.ProtectedBranch != nil && pull.ProtectedBranch.RequiredApprovals != 0 { - pull.ProtectedBranch.GrantedApprovalsCount = pull.ProtectedBranch.GetGrantedApprovalsCount(pull) - } + if err := pull.LoadProtectedBranch(); err != nil { + return + } + + if pull.ProtectedBranch != nil && pull.ProtectedBranch.RequiredApprovals != 0 { + requiredApprovals[pull.ID] = pull.ProtectedBranch.RequiredApprovals + approvals[pull.ID] = pull.ProtectedBranch.GetGrantedApprovalsCount(pull) } commitStatus[pull.ID], _ = pull.GetLastCommitStatus() @@ -246,6 +251,8 @@ func issues(ctx *context.Context, milestoneID int64, isPullOption util.OptionalB ctx.Data["Issues"] = issues ctx.Data["CommitStatus"] = commitStatus + ctx.Data["RequiredApprovals"] = requiredApprovals + ctx.Data["Approvals"] = approvals // Get assignees. ctx.Data["Assignees"], err = repo.GetAssignees() diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 6bd285244f7c9..bb8824d5e6547 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -223,10 +223,8 @@ {{end}} {{if .IsPull}} - {{if .PullRequest.ProtectedBranch}} - {{if .PullRequest.ProtectedBranch.RequiredApprovals}} - {{.PullRequest.ProtectedBranch.GrantedApprovalsCount}} / {{.PullRequest.ProtectedBranch.RequiredApprovals}} - {{end}} + {{if ne (index $.RequiredApprovals .PullRequest.ID) 0}} + {{(index $.Approvals .PullRequest.ID)}} / {{(index $.RequiredApprovals .PullRequest.ID)}} {{end}} {{end}}