diff options
Diffstat (limited to 'models/branches.go')
-rw-r--r-- | models/branches.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/models/branches.go b/models/branches.go index 322d33daae..a71c0e9622 100644 --- a/models/branches.go +++ b/models/branches.go @@ -63,6 +63,23 @@ func (repo *Repository) GetProtectedBranches() ([]*ProtectedBranch, error) { return protectedBranches, x.Find(&protectedBranches, &ProtectedBranch{RepoID: repo.ID}) } +// IsProtectedBranch checks if branch is protected +func (repo *Repository) IsProtectedBranch(branchName string) (bool, error) { + protectedBranch := &ProtectedBranch{ + RepoID: repo.ID, + BranchName: branchName, + } + + has, err := x.Get(protectedBranch) + if err != nil { + return true, err + } else if has { + return true, nil + } + + return false, nil +} + // AddProtectedBranch add protection to branch func (repo *Repository) AddProtectedBranch(branchName string, canPush bool) error { protectedBranch := &ProtectedBranch{ |