From 2791cc139e809856f894cd9dfcfceb9c4a9b8865 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Sun, 22 Nov 2020 14:58:12 +0100 Subject: [PATCH] Don't show a dropdown menu when only 1 merge option is available (#13660) (#13670) --- models/repo_unit.go | 18 +++++++++++ templates/repo/issue/view_content/pull.tmpl | 34 +++++++++++---------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/models/repo_unit.go b/models/repo_unit.go index d4c74515f..b208276d9 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -113,6 +113,24 @@ func (cfg *PullRequestsConfig) IsMergeStyleAllowed(mergeStyle MergeStyle) bool { mergeStyle == MergeStyleSquash && cfg.AllowSquash } +// AllowedMergeStyleCount returns the total count of allowed merge styles for the PullRequestsConfig +func (cfg *PullRequestsConfig) AllowedMergeStyleCount() int { + count := 0 + if cfg.AllowMerge { + count++ + } + if cfg.AllowRebase { + count++ + } + if cfg.AllowRebaseMerge { + count++ + } + if cfg.AllowSquash { + count++ + } + return count +} + // BeforeSet is invoked from XORM before setting the value of a field of this object. func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { switch colName { diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index 347b3b15d..f7870d60d 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -335,23 +335,25 @@ {{end}} - {{else}}