summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/branches.go6
-rw-r--r--models/migrations/migrations.go6
-rw-r--r--models/migrations/v137.go16
3 files changed, 26 insertions, 2 deletions
diff --git a/models/branches.go b/models/branches.go
index 44cfb41403..e6b8d61a70 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -47,6 +47,7 @@ type ProtectedBranch struct {
ApprovalsWhitelistTeamIDs []int64 `xorm:"JSON TEXT"`
RequiredApprovals int64 `xorm:"NOT NULL DEFAULT 0"`
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
+ BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
DismissStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
ProtectedFilePatterns string `xorm:"TEXT"`
@@ -194,6 +195,11 @@ func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullReque
return rejectExist
}
+// MergeBlockedByOutdatedBranch returns true if merge is blocked by an outdated head branch
+func (protectBranch *ProtectedBranch) MergeBlockedByOutdatedBranch(pr *PullRequest) bool {
+ return protectBranch.BlockOnOutdatedBranch && pr.CommitsBehind > 0
+}
+
// GetProtectedFilePatterns parses a semicolon separated list of protected file patterns and returns a glob.Glob slice
func (protectBranch *ProtectedBranch) GetProtectedFilePatterns() []glob.Glob {
extarr := make([]glob.Glob, 0, 10)
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index e1d46236a9..fe72d0f630 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -202,10 +202,12 @@ var migrations = []Migration{
NewMigration("Add EmailHash Table", addEmailHashTable),
// v134 -> v135
NewMigration("Refix merge base for merged pull requests", refixMergeBase),
- // v135 -> 136
+ // v135 -> v136
NewMigration("Add OrgID column to Labels table", addOrgIDLabelColumn),
- // v136 -> 137
+ // v136 -> v137
NewMigration("Add CommitsAhead and CommitsBehind Column to PullRequest Table", addCommitDivergenceToPulls),
+ // v137 -> v138
+ NewMigration("Add Branch Protection Block Outdated Branch", addBlockOnOutdatedBranch),
}
// GetCurrentDBVersion returns the current db version
diff --git a/models/migrations/v137.go b/models/migrations/v137.go
new file mode 100644
index 0000000000..f175cf8a80
--- /dev/null
+++ b/models/migrations/v137.go
@@ -0,0 +1,16 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "xorm.io/xorm"
+)
+
+func addBlockOnOutdatedBranch(x *xorm.Engine) error {
+ type ProtectedBranch struct {
+ BlockOnOutdatedBranch bool `xorm:"NOT NULL DEFAULT false"`
+ }
+ return x.Sync2(new(ProtectedBranch))
+}