| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: actions_policy.sql |
| 5 | |
| 6 | package actionsdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const countQueuedWorkflowRunsForRepo = `-- name: CountQueuedWorkflowRunsForRepo :one |
| 15 | SELECT COUNT(*)::bigint |
| 16 | FROM workflow_runs |
| 17 | WHERE repo_id = $1 AND status = 'queued' |
| 18 | ` |
| 19 | |
| 20 | func (q *Queries) CountQueuedWorkflowRunsForRepo(ctx context.Context, db DBTX, repoID int64) (int64, error) { |
| 21 | row := db.QueryRow(ctx, countQueuedWorkflowRunsForRepo, repoID) |
| 22 | var column_1 int64 |
| 23 | err := row.Scan(&column_1) |
| 24 | return column_1, err |
| 25 | } |
| 26 | |
| 27 | const countRecentWorkflowRunsForActor = `-- name: CountRecentWorkflowRunsForActor :one |
| 28 | SELECT COUNT(*)::bigint |
| 29 | FROM workflow_runs |
| 30 | WHERE actor_user_id = $1 AND created_at >= $2::timestamptz |
| 31 | ` |
| 32 | |
| 33 | type CountRecentWorkflowRunsForActorParams struct { |
| 34 | ActorUserID pgtype.Int8 |
| 35 | Since pgtype.Timestamptz |
| 36 | } |
| 37 | |
| 38 | func (q *Queries) CountRecentWorkflowRunsForActor(ctx context.Context, db DBTX, arg CountRecentWorkflowRunsForActorParams) (int64, error) { |
| 39 | row := db.QueryRow(ctx, countRecentWorkflowRunsForActor, arg.ActorUserID, arg.Since) |
| 40 | var column_1 int64 |
| 41 | err := row.Scan(&column_1) |
| 42 | return column_1, err |
| 43 | } |
| 44 | |
| 45 | const countRunningWorkflowJobsForOwner = `-- name: CountRunningWorkflowJobsForOwner :one |
| 46 | SELECT COUNT(*)::bigint |
| 47 | FROM workflow_jobs j |
| 48 | JOIN workflow_runs wr ON wr.id = j.run_id |
| 49 | JOIN repos run_repo ON run_repo.id = wr.repo_id |
| 50 | JOIN repos anchor_repo ON anchor_repo.id = $1::bigint |
| 51 | WHERE j.status = 'running' |
| 52 | AND ( |
| 53 | (anchor_repo.owner_user_id IS NOT NULL AND run_repo.owner_user_id = anchor_repo.owner_user_id) |
| 54 | OR (anchor_repo.owner_org_id IS NOT NULL AND run_repo.owner_org_id = anchor_repo.owner_org_id) |
| 55 | ) |
| 56 | ` |
| 57 | |
| 58 | func (q *Queries) CountRunningWorkflowJobsForOwner(ctx context.Context, db DBTX, repoID int64) (int64, error) { |
| 59 | row := db.QueryRow(ctx, countRunningWorkflowJobsForOwner, repoID) |
| 60 | var column_1 int64 |
| 61 | err := row.Scan(&column_1) |
| 62 | return column_1, err |
| 63 | } |
| 64 | |
| 65 | const countRunningWorkflowJobsForRepo = `-- name: CountRunningWorkflowJobsForRepo :one |
| 66 | SELECT COUNT(*)::bigint |
| 67 | FROM workflow_jobs j |
| 68 | JOIN workflow_runs r ON r.id = j.run_id |
| 69 | WHERE r.repo_id = $1 AND j.status = 'running' |
| 70 | ` |
| 71 | |
| 72 | func (q *Queries) CountRunningWorkflowJobsForRepo(ctx context.Context, db DBTX, repoID int64) (int64, error) { |
| 73 | row := db.QueryRow(ctx, countRunningWorkflowJobsForRepo, repoID) |
| 74 | var column_1 int64 |
| 75 | err := row.Scan(&column_1) |
| 76 | return column_1, err |
| 77 | } |
| 78 | |
| 79 | const getActionsRepoPolicy = `-- name: GetActionsRepoPolicy :one |
| 80 | SELECT repo_id, actions_enabled, require_pr_approval, |
| 81 | max_repo_queued_runs, max_repo_concurrent_jobs, |
| 82 | max_owner_concurrent_jobs, actor_trigger_limit_per_hour, |
| 83 | updated_by_user_id, created_at, updated_at |
| 84 | FROM actions_repo_policies |
| 85 | WHERE repo_id = $1 |
| 86 | ` |
| 87 | |
| 88 | func (q *Queries) GetActionsRepoPolicy(ctx context.Context, db DBTX, repoID int64) (ActionsRepoPolicy, error) { |
| 89 | row := db.QueryRow(ctx, getActionsRepoPolicy, repoID) |
| 90 | var i ActionsRepoPolicy |
| 91 | err := row.Scan( |
| 92 | &i.RepoID, |
| 93 | &i.ActionsEnabled, |
| 94 | &i.RequirePrApproval, |
| 95 | &i.MaxRepoQueuedRuns, |
| 96 | &i.MaxRepoConcurrentJobs, |
| 97 | &i.MaxOwnerConcurrentJobs, |
| 98 | &i.ActorTriggerLimitPerHour, |
| 99 | &i.UpdatedByUserID, |
| 100 | &i.CreatedAt, |
| 101 | &i.UpdatedAt, |
| 102 | ) |
| 103 | return i, err |
| 104 | } |
| 105 | |
| 106 | const getEffectiveActionsPolicyForRepo = `-- name: GetEffectiveActionsPolicyForRepo :one |
| 107 | |
| 108 | SELECT |
| 109 | r.id AS repo_id, |
| 110 | COALESCE(sp.actions_enabled, true)::boolean AS site_actions_enabled, |
| 111 | COALESCE(op.actions_enabled, 'inherit'::actions_policy_state)::actions_policy_state AS org_actions_enabled, |
| 112 | COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state)::actions_policy_state AS repo_actions_enabled, |
| 113 | CASE |
| 114 | WHEN COALESCE(sp.actions_enabled, true) = false THEN false |
| 115 | WHEN COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state) = 'enabled' THEN true |
| 116 | WHEN COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state) = 'disabled' THEN false |
| 117 | WHEN COALESCE(op.actions_enabled, 'inherit'::actions_policy_state) = 'enabled' THEN true |
| 118 | WHEN COALESCE(op.actions_enabled, 'inherit'::actions_policy_state) = 'disabled' THEN false |
| 119 | ELSE COALESCE(sp.actions_enabled, true) |
| 120 | END::boolean AS actions_enabled, |
| 121 | COALESCE(rp.require_pr_approval, op.require_pr_approval, sp.require_pr_approval, true)::boolean AS require_pr_approval, |
| 122 | COALESCE(rp.max_repo_queued_runs, op.max_repo_queued_runs, sp.max_repo_queued_runs, 50)::integer AS max_repo_queued_runs, |
| 123 | COALESCE(rp.max_repo_concurrent_jobs, op.max_repo_concurrent_jobs, sp.max_repo_concurrent_jobs, 20)::integer AS max_repo_concurrent_jobs, |
| 124 | COALESCE(rp.max_owner_concurrent_jobs, op.max_owner_concurrent_jobs, sp.max_owner_concurrent_jobs, 100)::integer AS max_owner_concurrent_jobs, |
| 125 | COALESCE(rp.actor_trigger_limit_per_hour, op.actor_trigger_limit_per_hour, sp.actor_trigger_limit_per_hour, 120)::integer AS actor_trigger_limit_per_hour |
| 126 | FROM repos r |
| 127 | LEFT JOIN actions_site_policy sp ON sp.id = true |
| 128 | LEFT JOIN actions_org_policies op ON op.org_id = r.owner_org_id |
| 129 | LEFT JOIN actions_repo_policies rp ON rp.repo_id = r.id |
| 130 | WHERE r.id = $1 |
| 131 | ` |
| 132 | |
| 133 | type GetEffectiveActionsPolicyForRepoRow struct { |
| 134 | RepoID int64 |
| 135 | SiteActionsEnabled bool |
| 136 | OrgActionsEnabled ActionsPolicyState |
| 137 | RepoActionsEnabled ActionsPolicyState |
| 138 | ActionsEnabled bool |
| 139 | RequirePrApproval bool |
| 140 | MaxRepoQueuedRuns int32 |
| 141 | MaxRepoConcurrentJobs int32 |
| 142 | MaxOwnerConcurrentJobs int32 |
| 143 | ActorTriggerLimitPerHour int32 |
| 144 | } |
| 145 | |
| 146 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 147 | func (q *Queries) GetEffectiveActionsPolicyForRepo(ctx context.Context, db DBTX, id int64) (GetEffectiveActionsPolicyForRepoRow, error) { |
| 148 | row := db.QueryRow(ctx, getEffectiveActionsPolicyForRepo, id) |
| 149 | var i GetEffectiveActionsPolicyForRepoRow |
| 150 | err := row.Scan( |
| 151 | &i.RepoID, |
| 152 | &i.SiteActionsEnabled, |
| 153 | &i.OrgActionsEnabled, |
| 154 | &i.RepoActionsEnabled, |
| 155 | &i.ActionsEnabled, |
| 156 | &i.RequirePrApproval, |
| 157 | &i.MaxRepoQueuedRuns, |
| 158 | &i.MaxRepoConcurrentJobs, |
| 159 | &i.MaxOwnerConcurrentJobs, |
| 160 | &i.ActorTriggerLimitPerHour, |
| 161 | ) |
| 162 | return i, err |
| 163 | } |
| 164 | |
| 165 | const upsertActionsRepoPolicy = `-- name: UpsertActionsRepoPolicy :one |
| 166 | INSERT INTO actions_repo_policies ( |
| 167 | repo_id, actions_enabled, require_pr_approval, |
| 168 | max_repo_queued_runs, max_repo_concurrent_jobs, |
| 169 | max_owner_concurrent_jobs, actor_trigger_limit_per_hour, |
| 170 | updated_by_user_id |
| 171 | ) VALUES ( |
| 172 | $1, $2, $3::boolean, |
| 173 | $4::integer, |
| 174 | $5::integer, |
| 175 | $6::integer, |
| 176 | $7::integer, |
| 177 | $8::bigint |
| 178 | ) |
| 179 | ON CONFLICT (repo_id) DO UPDATE SET |
| 180 | actions_enabled = EXCLUDED.actions_enabled, |
| 181 | require_pr_approval = EXCLUDED.require_pr_approval, |
| 182 | max_repo_queued_runs = EXCLUDED.max_repo_queued_runs, |
| 183 | max_repo_concurrent_jobs = EXCLUDED.max_repo_concurrent_jobs, |
| 184 | max_owner_concurrent_jobs = EXCLUDED.max_owner_concurrent_jobs, |
| 185 | actor_trigger_limit_per_hour = EXCLUDED.actor_trigger_limit_per_hour, |
| 186 | updated_by_user_id = EXCLUDED.updated_by_user_id, |
| 187 | updated_at = now() |
| 188 | RETURNING repo_id, actions_enabled, require_pr_approval, |
| 189 | max_repo_queued_runs, max_repo_concurrent_jobs, |
| 190 | max_owner_concurrent_jobs, actor_trigger_limit_per_hour, |
| 191 | updated_by_user_id, created_at, updated_at |
| 192 | ` |
| 193 | |
| 194 | type UpsertActionsRepoPolicyParams struct { |
| 195 | RepoID int64 |
| 196 | ActionsEnabled ActionsPolicyState |
| 197 | RequirePrApproval pgtype.Bool |
| 198 | MaxRepoQueuedRuns pgtype.Int4 |
| 199 | MaxRepoConcurrentJobs pgtype.Int4 |
| 200 | MaxOwnerConcurrentJobs pgtype.Int4 |
| 201 | ActorTriggerLimitPerHour pgtype.Int4 |
| 202 | UpdatedByUserID pgtype.Int8 |
| 203 | } |
| 204 | |
| 205 | func (q *Queries) UpsertActionsRepoPolicy(ctx context.Context, db DBTX, arg UpsertActionsRepoPolicyParams) (ActionsRepoPolicy, error) { |
| 206 | row := db.QueryRow(ctx, upsertActionsRepoPolicy, |
| 207 | arg.RepoID, |
| 208 | arg.ActionsEnabled, |
| 209 | arg.RequirePrApproval, |
| 210 | arg.MaxRepoQueuedRuns, |
| 211 | arg.MaxRepoConcurrentJobs, |
| 212 | arg.MaxOwnerConcurrentJobs, |
| 213 | arg.ActorTriggerLimitPerHour, |
| 214 | arg.UpdatedByUserID, |
| 215 | ) |
| 216 | var i ActionsRepoPolicy |
| 217 | err := row.Scan( |
| 218 | &i.RepoID, |
| 219 | &i.ActionsEnabled, |
| 220 | &i.RequirePrApproval, |
| 221 | &i.MaxRepoQueuedRuns, |
| 222 | &i.MaxRepoConcurrentJobs, |
| 223 | &i.MaxOwnerConcurrentJobs, |
| 224 | &i.ActorTriggerLimitPerHour, |
| 225 | &i.UpdatedByUserID, |
| 226 | &i.CreatedAt, |
| 227 | &i.UpdatedAt, |
| 228 | ) |
| 229 | return i, err |
| 230 | } |
| 231 |