Go · 4813 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: branch_protection.sql
5
6 package reposdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const deleteBranchProtectionRule = `-- name: DeleteBranchProtectionRule :exec
15 DELETE FROM branch_protection_rules WHERE id = $1
16 `
17
18 func (q *Queries) DeleteBranchProtectionRule(ctx context.Context, db DBTX, id int64) error {
19 _, err := db.Exec(ctx, deleteBranchProtectionRule, id)
20 return err
21 }
22
23 const getBranchProtectionRule = `-- name: GetBranchProtectionRule :one
24 SELECT id, repo_id, pattern,
25 prevent_force_push, prevent_deletion, require_pr_for_push,
26 allowed_pusher_user_ids,
27 require_signed_commits, status_checks_required,
28 created_at, updated_at, created_by_user_id
29 FROM branch_protection_rules
30 WHERE id = $1
31 `
32
33 func (q *Queries) GetBranchProtectionRule(ctx context.Context, db DBTX, id int64) (BranchProtectionRule, error) {
34 row := db.QueryRow(ctx, getBranchProtectionRule, id)
35 var i BranchProtectionRule
36 err := row.Scan(
37 &i.ID,
38 &i.RepoID,
39 &i.Pattern,
40 &i.PreventForcePush,
41 &i.PreventDeletion,
42 &i.RequirePrForPush,
43 &i.AllowedPusherUserIds,
44 &i.RequireSignedCommits,
45 &i.StatusChecksRequired,
46 &i.CreatedAt,
47 &i.UpdatedAt,
48 &i.CreatedByUserID,
49 )
50 return i, err
51 }
52
53 const listBranchProtectionRules = `-- name: ListBranchProtectionRules :many
54
55 SELECT id, repo_id, pattern,
56 prevent_force_push, prevent_deletion, require_pr_for_push,
57 allowed_pusher_user_ids,
58 require_signed_commits, status_checks_required,
59 created_at, updated_at, created_by_user_id
60 FROM branch_protection_rules
61 WHERE repo_id = $1
62 ORDER BY pattern
63 `
64
65 // SPDX-License-Identifier: AGPL-3.0-or-later
66 func (q *Queries) ListBranchProtectionRules(ctx context.Context, db DBTX, repoID int64) ([]BranchProtectionRule, error) {
67 rows, err := db.Query(ctx, listBranchProtectionRules, repoID)
68 if err != nil {
69 return nil, err
70 }
71 defer rows.Close()
72 items := []BranchProtectionRule{}
73 for rows.Next() {
74 var i BranchProtectionRule
75 if err := rows.Scan(
76 &i.ID,
77 &i.RepoID,
78 &i.Pattern,
79 &i.PreventForcePush,
80 &i.PreventDeletion,
81 &i.RequirePrForPush,
82 &i.AllowedPusherUserIds,
83 &i.RequireSignedCommits,
84 &i.StatusChecksRequired,
85 &i.CreatedAt,
86 &i.UpdatedAt,
87 &i.CreatedByUserID,
88 ); err != nil {
89 return nil, err
90 }
91 items = append(items, i)
92 }
93 if err := rows.Err(); err != nil {
94 return nil, err
95 }
96 return items, nil
97 }
98
99 const updateBranchProtectionRule = `-- name: UpdateBranchProtectionRule :exec
100 UPDATE branch_protection_rules
101 SET pattern = $2,
102 prevent_force_push = $3,
103 prevent_deletion = $4,
104 require_pr_for_push = $5,
105 allowed_pusher_user_ids = $6
106 WHERE id = $1
107 `
108
109 type UpdateBranchProtectionRuleParams struct {
110 ID int64
111 Pattern string
112 PreventForcePush bool
113 PreventDeletion bool
114 RequirePrForPush bool
115 AllowedPusherUserIds []int64
116 }
117
118 func (q *Queries) UpdateBranchProtectionRule(ctx context.Context, db DBTX, arg UpdateBranchProtectionRuleParams) error {
119 _, err := db.Exec(ctx, updateBranchProtectionRule,
120 arg.ID,
121 arg.Pattern,
122 arg.PreventForcePush,
123 arg.PreventDeletion,
124 arg.RequirePrForPush,
125 arg.AllowedPusherUserIds,
126 )
127 return err
128 }
129
130 const updateRepoDefaultBranch = `-- name: UpdateRepoDefaultBranch :exec
131 UPDATE repos SET default_branch = $2, updated_at = now() WHERE id = $1
132 `
133
134 type UpdateRepoDefaultBranchParams struct {
135 ID int64
136 DefaultBranch string
137 }
138
139 // Used by the default-branch settings handler. The on-disk HEAD update
140 // is a separate step done via `git symbolic-ref` from the orchestrator.
141 func (q *Queries) UpdateRepoDefaultBranch(ctx context.Context, db DBTX, arg UpdateRepoDefaultBranchParams) error {
142 _, err := db.Exec(ctx, updateRepoDefaultBranch, arg.ID, arg.DefaultBranch)
143 return err
144 }
145
146 const upsertBranchProtectionRule = `-- name: UpsertBranchProtectionRule :one
147 INSERT INTO branch_protection_rules (
148 repo_id, pattern,
149 prevent_force_push, prevent_deletion, require_pr_for_push,
150 allowed_pusher_user_ids, created_by_user_id
151 ) VALUES (
152 $1, $2, $3, $4, $5, $6, $7::bigint
153 )
154 RETURNING id
155 `
156
157 type UpsertBranchProtectionRuleParams struct {
158 RepoID int64
159 Pattern string
160 PreventForcePush bool
161 PreventDeletion bool
162 RequirePrForPush bool
163 AllowedPusherUserIds []int64
164 CreatedByUserID pgtype.Int8
165 }
166
167 func (q *Queries) UpsertBranchProtectionRule(ctx context.Context, db DBTX, arg UpsertBranchProtectionRuleParams) (int64, error) {
168 row := db.QueryRow(ctx, upsertBranchProtectionRule,
169 arg.RepoID,
170 arg.Pattern,
171 arg.PreventForcePush,
172 arg.PreventDeletion,
173 arg.RequirePrForPush,
174 arg.AllowedPusherUserIds,
175 arg.CreatedByUserID,
176 )
177 var id int64
178 err := row.Scan(&id)
179 return id, err
180 }
181