| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | -- name: ListBranchProtectionRules :many |
| 4 | SELECT id, repo_id, pattern, |
| 5 | prevent_force_push, prevent_deletion, require_pr_for_push, |
| 6 | allowed_pusher_user_ids, |
| 7 | require_signed_commits, status_checks_required, |
| 8 | created_at, updated_at, created_by_user_id, |
| 9 | required_review_count, dismiss_stale_reviews_on_push, require_code_owner_review, |
| 10 | dismiss_stale_status_checks_on_push |
| 11 | FROM branch_protection_rules |
| 12 | WHERE repo_id = $1 |
| 13 | ORDER BY pattern; |
| 14 | |
| 15 | -- name: GetBranchProtectionRule :one |
| 16 | SELECT id, repo_id, pattern, |
| 17 | prevent_force_push, prevent_deletion, require_pr_for_push, |
| 18 | allowed_pusher_user_ids, |
| 19 | require_signed_commits, status_checks_required, |
| 20 | created_at, updated_at, created_by_user_id, |
| 21 | required_review_count, dismiss_stale_reviews_on_push, require_code_owner_review, |
| 22 | dismiss_stale_status_checks_on_push |
| 23 | FROM branch_protection_rules |
| 24 | WHERE id = $1; |
| 25 | |
| 26 | -- name: UpsertBranchProtectionRule :one |
| 27 | INSERT INTO branch_protection_rules ( |
| 28 | repo_id, pattern, |
| 29 | prevent_force_push, prevent_deletion, require_pr_for_push, |
| 30 | require_signed_commits, |
| 31 | allowed_pusher_user_ids, created_by_user_id |
| 32 | ) VALUES ( |
| 33 | $1, $2, $3, $4, $5, sqlc.arg(require_signed_commits)::boolean, $6, sqlc.narg(created_by_user_id)::bigint |
| 34 | ) |
| 35 | RETURNING id; |
| 36 | |
| 37 | -- name: UpdateBranchProtectionRule :exec |
| 38 | UPDATE branch_protection_rules |
| 39 | SET pattern = $2, |
| 40 | prevent_force_push = $3, |
| 41 | prevent_deletion = $4, |
| 42 | require_pr_for_push = $5, |
| 43 | require_signed_commits = sqlc.arg(require_signed_commits)::boolean, |
| 44 | allowed_pusher_user_ids = $6 |
| 45 | WHERE id = $1; |
| 46 | |
| 47 | -- name: UpdateBranchProtectionReviewSettings :exec |
| 48 | -- S23 surface for the review-related knobs. Branch-protection edit |
| 49 | -- handler calls this alongside UpdateBranchProtectionRule. |
| 50 | UPDATE branch_protection_rules |
| 51 | SET required_review_count = $2, |
| 52 | dismiss_stale_reviews_on_push = $3, |
| 53 | require_code_owner_review = $4 |
| 54 | WHERE id = $1; |
| 55 | |
| 56 | -- name: UpdateBranchProtectionCheckSettings :exec |
| 57 | -- S24 surface for the required-status-check knobs. Branch-protection |
| 58 | -- edit handler calls this alongside UpdateBranchProtectionRule. |
| 59 | UPDATE branch_protection_rules |
| 60 | SET status_checks_required = $2, |
| 61 | dismiss_stale_status_checks_on_push = $3 |
| 62 | WHERE id = $1; |
| 63 | |
| 64 | -- name: DeleteBranchProtectionRule :exec |
| 65 | DELETE FROM branch_protection_rules WHERE id = $1; |
| 66 | |
| 67 | -- name: UpdateRepoDefaultBranch :exec |
| 68 | -- Used by the default-branch settings handler. The on-disk HEAD update |
| 69 | -- is a separate step done via `git symbolic-ref` from the orchestrator. |
| 70 | UPDATE repos SET default_branch = $2, updated_at = now() WHERE id = $1; |
| 71 |