mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Allow to set protected file patterns that can not be changed under no conditions (#10806)
Co-Authored-By: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user