summaryrefslogtreecommitdiffstats
path: root/models/branches.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2020-03-27 00:26:34 +0200
committerGitHub <noreply@github.com>2020-03-27 00:26:34 +0200
commitbbd910ed1b4f52ee66a5cdd8d11f856598161bef (patch)
tree8392e0f8208b5b7d8e6df8335677518aa07f194f /models/branches.go
parent52cfd2743c0e85b36081cf80a850e6a5901f1865 (diff)
downloadgitea-bbd910ed1b4f52ee66a5cdd8d11f856598161bef.tar.gz
gitea-bbd910ed1b4f52ee66a5cdd8d11f856598161bef.zip
Allow to set protected file patterns that can not be changed under no conditions (#10806)
Co-Authored-By: zeripath <art27@cantab.net>
Diffstat (limited to 'models/branches.go')
-rw-r--r--models/branches.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/models/branches.go b/models/branches.go
index 75f5c0a3a7..d488fc9fcc 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -7,6 +7,7 @@ package models
import (
"context"
"fmt"
+ "strings"
"time"
"code.gitea.io/gitea/modules/base"
@@ -15,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+ "github.com/gobwas/glob"
"github.com/unknwon/com"
)
@@ -47,6 +49,7 @@ type ProtectedBranch struct {
BlockOnRejectedReviews bool `xorm:"NOT NULL DEFAULT false"`
DismissStaleApprovals bool `xorm:"NOT NULL DEFAULT false"`
RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"`
+ ProtectedFilePatterns string `xorm:"TEXT"`
CreatedUnix timeutil.TimeStamp `xorm:"created"`
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
@@ -190,6 +193,22 @@ func (protectBranch *ProtectedBranch) MergeBlockedByRejectedReview(pr *PullReque
return rejectExist
}
+// 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)
+ for _, expr := range strings.Split(strings.ToLower(protectBranch.ProtectedFilePatterns), ";") {
+ expr = strings.TrimSpace(expr)
+ if expr != "" {
+ if g, err := glob.Compile(expr, '.', '/'); err != nil {
+ log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
+ } else {
+ extarr = append(extarr, g)
+ }
+ }
+ }
+ return extarr
+}
+
// GetProtectedBranchByRepoID getting protected branch by repo ID
func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) {
protectedBranches := make([]*ProtectedBranch, 0)