diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-01-16 16:00:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-16 16:00:22 +0800 |
commit | 2782c1439679402a1f8731a94dc66214781282ba (patch) | |
tree | 66739f30beb529119694290bdcdba9e02bdcfabd /templates | |
parent | cc1f8cbe96c195aab79761c48bc4ec0bff2b3431 (diff) | |
download | gitea-2782c1439679402a1f8731a94dc66214781282ba.tar.gz gitea-2782c1439679402a1f8731a94dc66214781282ba.zip |
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
<img width="1160" alt="image"
src="https://user-images.githubusercontent.com/81045/205651179-ebb5492a-4ade-4bb4-a13c-965e8c927063.png">
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'templates')
-rw-r--r-- | templates/repo/issue/view_content/pull.tmpl | 4 | ||||
-rw-r--r-- | templates/repo/settings/branches.tmpl | 37 | ||||
-rw-r--r-- | templates/repo/settings/protected_branch.tmpl | 75 | ||||
-rw-r--r-- | templates/swagger/v1_json.tmpl | 10 |
4 files changed, 72 insertions, 54 deletions
diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index 665f782053..1f94001db0 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -204,7 +204,7 @@ {{if .IsBlockedByApprovals}} <div class="item"> <i class="icon icon-octicon">{{svg "octicon-x"}}</i> - {{$.locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .Issue.PullRequest.ProtectedBranch.RequiredApprovals}} + {{$.locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .ProtectedBranch.RequiredApprovals}} </div> {{else if .IsBlockedByRejection}} <div class="item"> @@ -444,7 +444,7 @@ {{if .IsBlockedByApprovals}} <div class="item text red"> {{svg "octicon-x"}} - {{$.locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .Issue.PullRequest.ProtectedBranch.RequiredApprovals}} + {{$.locale.Tr "repo.pulls.blocked_by_approvals" .GrantedApprovals .ProtectedBranch.RequiredApprovals}} </div> {{else if .IsBlockedByRejection}} <div class="item text red"> diff --git a/templates/repo/settings/branches.tmpl b/templates/repo/settings/branches.tmpl index cc8fc60426..ad3b3275e8 100644 --- a/templates/repo/settings/branches.tmpl +++ b/templates/repo/settings/branches.tmpl @@ -43,31 +43,24 @@ <h4 class="ui top attached header"> {{.locale.Tr "repo.settings.protected_branch"}} + <div class="ui right"> + <a class="ui primary tiny button" href="{{$.Repository.Link}}/settings/branches/edit">{{$.locale.Tr "repo.settings.branches.add_new_rule"}}</a> + </div> </h4> <div class="ui attached table segment"> <div class="ui grid padded"> - <div class="eight wide column"> - <div class="ui fluid dropdown selection" tabindex="0"> - {{svg "octicon-triangle-down" 14 "dropdown icon"}} - <div class="default text">{{.locale.Tr "repo.settings.choose_branch"}}</div> - <div class="menu transition hidden" tabindex="-1" style="display: block !important;"> - {{range .LeftBranches}} - <a class="item" href="{{$.Repository.Link}}/settings/branches/{{. | PathEscapeSegments}}">{{.}}</a> - {{end}} - </div> - </div> - </div> - </div> - - <div class="ui grid padded"> <div class="sixteen wide column"> <table class="ui single line table padded"> <tbody> {{range .ProtectedBranches}} <tr> - <td><div class="ui basic primary label">{{.BranchName}}</div></td> - <td class="right aligned"><a class="rm ui button" href="{{$.Repository.Link}}/settings/branches/{{.BranchName | PathEscapeSegments}}">{{$.locale.Tr "repo.settings.edit_protected_branch"}}</a></td> + <td><div class="ui basic primary label">{{.RuleName}}</div></td> + <td class="right aligned"> + <a class="rm ui button" href="{{$.Repository.Link}}/settings/branches/edit?rule_name={{.RuleName}}">{{$.locale.Tr "repo.settings.edit_protected_branch"}}</a> + <button class="ui red tiny button delete-button" data-url="{{$.Repository.Link}}/settings/branches/{{.ID}}/delete" data-id="{{.ID}}"> + {{$.locale.Tr "repo.settings.protected_branch.delete_rule"}}</button> + </td> </tr> {{else}} <tr class="center aligned"><td>{{.locale.Tr "repo.settings.no_protected_branch"}}</td></tr> @@ -102,4 +95,16 @@ {{end}} </div> </div> + +<div class="ui small basic delete modal"> + <div class="ui header"> + {{svg "octicon-trash" 16 "mr-2"}} + {{.locale.Tr "repo.settings.protected_branch_deletion"}} + </div> + <div class="content"> + <p>{{.locale.Tr "repo.settings.protected_branch_deletion_desc"}}</p> + </div> + {{template "base/delete_modal_actions" .}} +</div> + {{template "base/footer" .}} diff --git a/templates/repo/settings/protected_branch.tmpl b/templates/repo/settings/protected_branch.tmpl index ff93218b20..7a4405efb7 100644 --- a/templates/repo/settings/protected_branch.tmpl +++ b/templates/repo/settings/protected_branch.tmpl @@ -4,42 +4,43 @@ {{template "repo/settings/navbar" .}} <div class="ui container"> {{template "base/alert" .}} - <h4 class="ui top attached header"> - {{.locale.Tr "repo.settings.branch_protection" (.Branch.BranchName|Escape) | Str2html}} - </h4> - <div class="ui attached segment branch-protection"> - <form class="ui form" action="{{.Link}}" method="post"> - {{.CsrfTokenHtml}} - <div class="inline field"> - <div class="ui checkbox"> - <input class="enable-protection" name="protected" type="checkbox" data-target="#protection_box" {{if .Branch.IsProtected}}checked{{end}}> - <label>{{.locale.Tr "repo.settings.protect_this_branch"}}</label> - <p class="help">{{.locale.Tr "repo.settings.protect_this_branch_desc"}}</p> - </div> + <form class="ui form" action="{{.Link}}" method="post"> + <h4 class="ui top attached header"> + {{.locale.Tr "repo.settings.branch_protection" (.Rule.RuleName|Escape) | Str2html}} + </h4> + <div class="ui attached segment branch-protection"> + <div class="field"> + <label for="protected_file_patterns">{{.locale.Tr "repo.settings.protect_branch_name_pattern"}}</label> + <input name="rule_name" type="text" value="{{.Rule.RuleName}}"> + <input name="rule_id" type="hidden" value="{{.Rule.ID}}"> </div> - <div id="protection_box" class="fields {{if not .Branch.IsProtected}}disabled{{end}}"> + + <div class="ui divider"></div> + + {{.CsrfTokenHtml}} + <div id="protection_box" class="fields"> <div class="field"> <div class="ui radio checkbox"> - <input name="enable_push" type="radio" value="none" class="disable-whitelist" data-target="#whitelist_box" {{if not .Branch.CanPush}}checked{{end}}> + <input name="enable_push" type="radio" value="none" class="disable-whitelist" data-target="#whitelist_box" {{if not .Rule.CanPush}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_disable_push"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_disable_push_desc"}}</p> </div> </div> <div class="field"> <div class="ui radio checkbox"> - <input name="enable_push" type="radio" value="all" class="disable-whitelist" data-target="#whitelist_box" {{if and (.Branch.CanPush) (not .Branch.EnableWhitelist)}}checked{{end}}> + <input name="enable_push" type="radio" value="all" class="disable-whitelist" data-target="#whitelist_box" {{if and (.Rule.CanPush) (not .Rule.EnableWhitelist)}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_enable_push"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_enable_push_desc"}}</p> </div> </div> <div class="field"> <div class="ui radio checkbox"> - <input name="enable_push" type="radio" value="whitelist" class="enable-whitelist" data-target="#whitelist_box" {{if and (.Branch.CanPush) (.Branch.EnableWhitelist)}}checked{{end}}> + <input name="enable_push" type="radio" value="whitelist" class="enable-whitelist" data-target="#whitelist_box" {{if and (.Rule.CanPush) (.Rule.EnableWhitelist)}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_whitelist_committers"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_whitelist_committers_desc"}}</p> </div> </div> - <div id="whitelist_box" class="fields {{if not .Branch.EnableWhitelist}}disabled{{end}}"> + <div id="whitelist_box" class="fields {{if not .Rule.EnableWhitelist}}disabled{{end}}"> <div class="whitelist field"> <label>{{.locale.Tr "repo.settings.protect_whitelist_users"}}</label> <div class="ui multiple search selection dropdown"> @@ -76,20 +77,22 @@ <br> <div class="whitelist field"> <div class="ui checkbox"> - <input type="checkbox" name="whitelist_deploy_keys" {{if .Branch.WhitelistDeployKeys}}checked{{end}}> + <input type="checkbox" name="whitelist_deploy_keys" {{if .Rule.WhitelistDeployKeys}}checked{{end}}> <label for="whitelist_deploy_keys">{{.locale.Tr "repo.settings.protect_whitelist_deploy_keys"}}</label> </div> </div> </div> + <div class="ui divider"></div> + <div class="field"> <div class="ui checkbox"> - <input class="enable-whitelist" name="enable_merge_whitelist" type="checkbox" data-target="#merge_whitelist_box" {{if .Branch.EnableMergeWhitelist}}checked{{end}}> + <input class="enable-whitelist" name="enable_merge_whitelist" type="checkbox" data-target="#merge_whitelist_box" {{if .Rule.EnableMergeWhitelist}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_merge_whitelist_committers"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_merge_whitelist_committers_desc"}}</p> </div> </div> - <div id="merge_whitelist_box" class="fields {{if not .Branch.EnableMergeWhitelist}}disabled{{end}}"> + <div id="merge_whitelist_box" class="fields {{if not .Rule.EnableMergeWhitelist}}disabled{{end}}"> <div class="whitelist field"> <label>{{.locale.Tr "repo.settings.protect_merge_whitelist_users"}}</label> <div class="ui multiple search selection dropdown"> @@ -127,13 +130,13 @@ <div class="field"> <div class="ui checkbox"> - <input class="enable-statuscheck" name="enable_status_check" type="checkbox" data-target="#statuscheck_contexts_box" {{if eq (len .branch_status_check_contexts) 0}}disabled{{end}} {{if .Branch.EnableStatusCheck}}checked{{end}}> + <input class="enable-statuscheck" name="enable_status_check" type="checkbox" data-target="#statuscheck_contexts_box" {{if eq (len .branch_status_check_contexts) 0}}disabled{{end}} {{if .Rule.EnableStatusCheck}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_check_status_contexts"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_check_status_contexts_desc"}}</p> </div> </div> - <div id="statuscheck_contexts_box" class="fields {{if not .Branch.EnableStatusCheck}}disabled{{end}}"> + <div id="statuscheck_contexts_box" class="fields {{if not .Rule.EnableStatusCheck}}disabled{{end}}"> <div class="field"> <table class="ui celled table six column"> <thead> @@ -159,17 +162,17 @@ <div class="field"> <label for="required-approvals">{{.locale.Tr "repo.settings.protect_required_approvals"}}</label> - <input name="required_approvals" id="required-approvals" type="number" value="{{.Branch.RequiredApprovals}}"> + <input name="required_approvals" id="required-approvals" type="number" value="{{.Rule.RequiredApprovals}}"> <p class="help">{{.locale.Tr "repo.settings.protect_required_approvals_desc"}}</p> </div> <div class="field"> <div class="ui checkbox"> - <input class="enable-whitelist" name="enable_approvals_whitelist" type="checkbox" data-target="#approvals_whitelist_box" {{if .Branch.EnableApprovalsWhitelist}}checked{{end}}> + <input class="enable-whitelist" name="enable_approvals_whitelist" type="checkbox" data-target="#approvals_whitelist_box" {{if .Rule.EnableApprovalsWhitelist}}checked{{end}}> <label>{{.locale.Tr "repo.settings.protect_approvals_whitelist_enabled"}}</label> <p class="help">{{.locale.Tr "repo.settings.protect_approvals_whitelist_enabled_desc"}}</p> </div> </div> - <div id="approvals_whitelist_box" class="fields {{if not .Branch.EnableApprovalsWhitelist}}disabled{{end}}"> + <div id="approvals_whitelist_box" class="fields {{if not .Rule.EnableApprovalsWhitelist}}disabled{{end}}"> <div class="whitelist field"> <label>{{.locale.Tr "repo.settings.protect_approvals_whitelist_users"}}</label> <div class="ui multiple search selection dropdown"> @@ -206,59 +209,59 @@ </div> <div class="field"> <div class="ui checkbox"> - <input name="block_on_rejected_reviews" type="checkbox" {{if .Branch.BlockOnRejectedReviews}}checked{{end}}> + <input name="block_on_rejected_reviews" type="checkbox" {{if .Rule.BlockOnRejectedReviews}}checked{{end}}> <label for="block_on_rejected_reviews">{{.locale.Tr "repo.settings.block_rejected_reviews"}}</label> <p class="help">{{.locale.Tr "repo.settings.block_rejected_reviews_desc"}}</p> </div> </div> <div class="field"> <div class="ui checkbox"> - <input name="block_on_official_review_requests" type="checkbox" {{if .Branch.BlockOnOfficialReviewRequests}}checked{{end}}> + <input name="block_on_official_review_requests" type="checkbox" {{if .Rule.BlockOnOfficialReviewRequests}}checked{{end}}> <label for="block_on_official_review_requests">{{.locale.Tr "repo.settings.block_on_official_review_requests"}}</label> <p class="help">{{.locale.Tr "repo.settings.block_on_official_review_requests_desc"}}</p> </div> </div> <div class="field"> <div class="ui checkbox"> - <input name="dismiss_stale_approvals" type="checkbox" {{if .Branch.DismissStaleApprovals}}checked{{end}}> + <input name="dismiss_stale_approvals" type="checkbox" {{if .Rule.DismissStaleApprovals}}checked{{end}}> <label for="dismiss_stale_approvals">{{.locale.Tr "repo.settings.dismiss_stale_approvals"}}</label> <p class="help">{{.locale.Tr "repo.settings.dismiss_stale_approvals_desc"}}</p> </div> </div> <div class="field"> <div class="ui checkbox"> - <input name="require_signed_commits" type="checkbox" {{if .Branch.RequireSignedCommits}}checked{{end}}> + <input name="require_signed_commits" type="checkbox" {{if .Rule.RequireSignedCommits}}checked{{end}}> <label for="require_signed_commits">{{.locale.Tr "repo.settings.require_signed_commits"}}</label> <p class="help">{{.locale.Tr "repo.settings.require_signed_commits_desc"}}</p> </div> </div> <div class="field"> <div class="ui checkbox"> - <input name="block_on_outdated_branch" type="checkbox" {{if .Branch.BlockOnOutdatedBranch}}checked{{end}}> + <input name="block_on_outdated_branch" type="checkbox" {{if .Rule.BlockOnOutdatedBranch}}checked{{end}}> <label for="block_on_outdated_branch">{{.locale.Tr "repo.settings.block_outdated_branch"}}</label> <p class="help">{{.locale.Tr "repo.settings.block_outdated_branch_desc"}}</p> </div> </div> <div class="field"> <label for="protected_file_patterns">{{.locale.Tr "repo.settings.protect_protected_file_patterns"}}</label> - <input name="protected_file_patterns" id="protected_file_patterns" type="text" value="{{.Branch.ProtectedFilePatterns}}"> + <input name="protected_file_patterns" id="protected_file_patterns" type="text" value="{{.Rule.ProtectedFilePatterns}}"> <p class="help">{{.locale.Tr "repo.settings.protect_protected_file_patterns_desc" | Safe}}</p> </div> <div class="field"> <label for="unprotected_file_patterns">{{.locale.Tr "repo.settings.protect_unprotected_file_patterns"}}</label> - <input name="unprotected_file_patterns" id="unprotected_file_patterns" type="text" value="{{.Branch.UnprotectedFilePatterns}}"> + <input name="unprotected_file_patterns" id="unprotected_file_patterns" type="text" value="{{.Rule.UnprotectedFilePatterns}}"> <p class="help">{{.locale.Tr "repo.settings.protect_unprotected_file_patterns_desc" | Safe}}</p> </div> - </div> <div class="ui divider"></div> <div class="field"> - <button class="ui green button">{{$.locale.Tr "repo.settings.update_settings"}}</button> + <button class="ui green button">{{$.locale.Tr "repo.settings.protected_branch.save_rule"}}</button> + <button class="ui gray button">{{$.locale.Tr "cancel"}}</button> </div> - </form> - </div> + </div> + </form> </div> </div> {{template "base/footer" .}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index c223282596..76d02d825f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -14233,6 +14233,7 @@ "x-go-name": "BlockOnRejectedReviews" }, "branch_name": { + "description": "Deprecated: true", "type": "string", "x-go-name": "BranchName" }, @@ -14310,6 +14311,10 @@ "format": "int64", "x-go-name": "RequiredApprovals" }, + "rule_name": { + "type": "string", + "x-go-name": "RuleName" + }, "status_check_contexts": { "type": "array", "items": { @@ -14772,6 +14777,7 @@ "x-go-name": "BlockOnRejectedReviews" }, "branch_name": { + "description": "Deprecated: true", "type": "string", "x-go-name": "BranchName" }, @@ -14844,6 +14850,10 @@ "format": "int64", "x-go-name": "RequiredApprovals" }, + "rule_name": { + "type": "string", + "x-go-name": "RuleName" + }, "status_check_contexts": { "type": "array", "items": { |