MySQL · 4432 bytes Raw Blame History
1 -- SPDX-License-Identifier: AGPL-3.0-or-later
2
3 -- name: GetEffectiveActionsPolicyForRepo :one
4 SELECT
5 r.id AS repo_id,
6 COALESCE(sp.actions_enabled, true)::boolean AS site_actions_enabled,
7 COALESCE(op.actions_enabled, 'inherit'::actions_policy_state)::actions_policy_state AS org_actions_enabled,
8 COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state)::actions_policy_state AS repo_actions_enabled,
9 CASE
10 WHEN COALESCE(sp.actions_enabled, true) = false THEN false
11 WHEN COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state) = 'enabled' THEN true
12 WHEN COALESCE(rp.actions_enabled, 'inherit'::actions_policy_state) = 'disabled' THEN false
13 WHEN COALESCE(op.actions_enabled, 'inherit'::actions_policy_state) = 'enabled' THEN true
14 WHEN COALESCE(op.actions_enabled, 'inherit'::actions_policy_state) = 'disabled' THEN false
15 ELSE COALESCE(sp.actions_enabled, true)
16 END::boolean AS actions_enabled,
17 COALESCE(rp.require_pr_approval, op.require_pr_approval, sp.require_pr_approval, true)::boolean AS require_pr_approval,
18 COALESCE(rp.max_repo_queued_runs, op.max_repo_queued_runs, sp.max_repo_queued_runs, 50)::integer AS max_repo_queued_runs,
19 COALESCE(rp.max_repo_concurrent_jobs, op.max_repo_concurrent_jobs, sp.max_repo_concurrent_jobs, 20)::integer AS max_repo_concurrent_jobs,
20 COALESCE(rp.max_owner_concurrent_jobs, op.max_owner_concurrent_jobs, sp.max_owner_concurrent_jobs, 100)::integer AS max_owner_concurrent_jobs,
21 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
22 FROM repos r
23 LEFT JOIN actions_site_policy sp ON sp.id = true
24 LEFT JOIN actions_org_policies op ON op.org_id = r.owner_org_id
25 LEFT JOIN actions_repo_policies rp ON rp.repo_id = r.id
26 WHERE r.id = $1;
27
28 -- name: GetActionsRepoPolicy :one
29 SELECT repo_id, actions_enabled, require_pr_approval,
30 max_repo_queued_runs, max_repo_concurrent_jobs,
31 max_owner_concurrent_jobs, actor_trigger_limit_per_hour,
32 updated_by_user_id, created_at, updated_at
33 FROM actions_repo_policies
34 WHERE repo_id = $1;
35
36 -- name: UpsertActionsRepoPolicy :one
37 INSERT INTO actions_repo_policies (
38 repo_id, actions_enabled, require_pr_approval,
39 max_repo_queued_runs, max_repo_concurrent_jobs,
40 max_owner_concurrent_jobs, actor_trigger_limit_per_hour,
41 updated_by_user_id
42 ) VALUES (
43 $1, $2, sqlc.narg(require_pr_approval)::boolean,
44 sqlc.narg(max_repo_queued_runs)::integer,
45 sqlc.narg(max_repo_concurrent_jobs)::integer,
46 sqlc.narg(max_owner_concurrent_jobs)::integer,
47 sqlc.narg(actor_trigger_limit_per_hour)::integer,
48 sqlc.narg(updated_by_user_id)::bigint
49 )
50 ON CONFLICT (repo_id) DO UPDATE SET
51 actions_enabled = EXCLUDED.actions_enabled,
52 require_pr_approval = EXCLUDED.require_pr_approval,
53 max_repo_queued_runs = EXCLUDED.max_repo_queued_runs,
54 max_repo_concurrent_jobs = EXCLUDED.max_repo_concurrent_jobs,
55 max_owner_concurrent_jobs = EXCLUDED.max_owner_concurrent_jobs,
56 actor_trigger_limit_per_hour = EXCLUDED.actor_trigger_limit_per_hour,
57 updated_by_user_id = EXCLUDED.updated_by_user_id,
58 updated_at = now()
59 RETURNING repo_id, actions_enabled, require_pr_approval,
60 max_repo_queued_runs, max_repo_concurrent_jobs,
61 max_owner_concurrent_jobs, actor_trigger_limit_per_hour,
62 updated_by_user_id, created_at, updated_at;
63
64 -- name: CountQueuedWorkflowRunsForRepo :one
65 SELECT COUNT(*)::bigint
66 FROM workflow_runs
67 WHERE repo_id = $1 AND status = 'queued';
68
69 -- name: CountRecentWorkflowRunsForActor :one
70 SELECT COUNT(*)::bigint
71 FROM workflow_runs
72 WHERE actor_user_id = $1 AND created_at >= sqlc.arg(since)::timestamptz;
73
74 -- name: CountRunningWorkflowJobsForRepo :one
75 SELECT COUNT(*)::bigint
76 FROM workflow_jobs j
77 JOIN workflow_runs r ON r.id = j.run_id
78 WHERE r.repo_id = $1 AND j.status = 'running';
79
80 -- name: CountRunningWorkflowJobsForOwner :one
81 SELECT COUNT(*)::bigint
82 FROM workflow_jobs j
83 JOIN workflow_runs wr ON wr.id = j.run_id
84 JOIN repos run_repo ON run_repo.id = wr.repo_id
85 JOIN repos anchor_repo ON anchor_repo.id = sqlc.arg(repo_id)::bigint
86 WHERE j.status = 'running'
87 AND (
88 (anchor_repo.owner_user_id IS NOT NULL AND run_repo.owner_user_id = anchor_repo.owner_user_id)
89 OR (anchor_repo.owner_org_id IS NOT NULL AND run_repo.owner_org_id = anchor_repo.owner_org_id)
90 );
91