From 2782c1439679402a1f8731a94dc66214781282ba Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 16 Jan 2023 16:00:22 +0800 Subject: Supports wildcard protected branch (#20825) This PR introduce glob match for protected branch name. The separator is `/` and you can use `*` matching non-separator chars and use `**` across separator. It also supports input an exist or non-exist branch name as matching condition and branch name condition has high priority than glob rule. Should fix #2529 and #15705 screenshots image Co-authored-by: zeripath --- modules/context/repo.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/context/repo.go') diff --git a/modules/context/repo.go b/modules/context/repo.go index dba20b48a0..a5ade21e43 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -119,14 +119,15 @@ type CanCommitToBranchResults struct { // // and branch is not protected for push func (r *Repository) CanCommitToBranch(ctx context.Context, doer *user_model.User) (CanCommitToBranchResults, error) { - protectedBranch, err := git_model.GetProtectedBranchBy(ctx, r.Repository.ID, r.BranchName) + protectedBranch, err := git_model.GetFirstMatchProtectedBranchRule(ctx, r.Repository.ID, r.BranchName) if err != nil { return CanCommitToBranchResults{}, err } userCanPush := true requireSigned := false if protectedBranch != nil { - userCanPush = protectedBranch.CanUserPush(ctx, doer.ID) + protectedBranch.Repo = r.Repository + userCanPush = protectedBranch.CanUserPush(ctx, doer) requireSigned = protectedBranch.RequireSignedCommits } -- cgit v1.2.3