@@ -0,0 +1,463 @@ |
| 1 | +// Code generated by sqlc. DO NOT EDIT. |
| 2 | +// versions: |
| 3 | +// sqlc v1.31.1 |
| 4 | +// source: checks.sql |
| 5 | + |
| 6 | +package checksdb |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + |
| 11 | + "github.com/jackc/pgx/v5/pgtype" |
| 12 | +) |
| 13 | + |
| 14 | +const createCheckRun = `-- name: CreateCheckRun :one |
| 15 | +INSERT INTO check_runs ( |
| 16 | + suite_id, repo_id, head_sha, name, |
| 17 | + status, conclusion, |
| 18 | + started_at, completed_at, |
| 19 | + details_url, output, external_id |
| 20 | +) VALUES ( |
| 21 | + $1, $2, $3, $4, |
| 22 | + $5, $8::check_conclusion, |
| 23 | + $9::timestamptz, $10::timestamptz, |
| 24 | + $6, $7, $11::text |
| 25 | +) |
| 26 | +RETURNING id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at |
| 27 | +` |
| 28 | + |
| 29 | +type CreateCheckRunParams struct { |
| 30 | + SuiteID int64 |
| 31 | + RepoID int64 |
| 32 | + HeadSha string |
| 33 | + Name string |
| 34 | + Status CheckStatus |
| 35 | + DetailsUrl string |
| 36 | + Output []byte |
| 37 | + Conclusion NullCheckConclusion |
| 38 | + StartedAt pgtype.Timestamptz |
| 39 | + CompletedAt pgtype.Timestamptz |
| 40 | + ExternalID pgtype.Text |
| 41 | +} |
| 42 | + |
| 43 | +func (q *Queries) CreateCheckRun(ctx context.Context, db DBTX, arg CreateCheckRunParams) (CheckRun, error) { |
| 44 | + row := db.QueryRow(ctx, createCheckRun, |
| 45 | + arg.SuiteID, |
| 46 | + arg.RepoID, |
| 47 | + arg.HeadSha, |
| 48 | + arg.Name, |
| 49 | + arg.Status, |
| 50 | + arg.DetailsUrl, |
| 51 | + arg.Output, |
| 52 | + arg.Conclusion, |
| 53 | + arg.StartedAt, |
| 54 | + arg.CompletedAt, |
| 55 | + arg.ExternalID, |
| 56 | + ) |
| 57 | + var i CheckRun |
| 58 | + err := row.Scan( |
| 59 | + &i.ID, |
| 60 | + &i.SuiteID, |
| 61 | + &i.RepoID, |
| 62 | + &i.HeadSha, |
| 63 | + &i.Name, |
| 64 | + &i.Status, |
| 65 | + &i.Conclusion, |
| 66 | + &i.StartedAt, |
| 67 | + &i.CompletedAt, |
| 68 | + &i.DetailsUrl, |
| 69 | + &i.Output, |
| 70 | + &i.ExternalID, |
| 71 | + &i.CreatedAt, |
| 72 | + &i.UpdatedAt, |
| 73 | + ) |
| 74 | + return i, err |
| 75 | +} |
| 76 | + |
| 77 | +const getCheckRun = `-- name: GetCheckRun :one |
| 78 | +SELECT id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at FROM check_runs WHERE id = $1 |
| 79 | +` |
| 80 | + |
| 81 | +func (q *Queries) GetCheckRun(ctx context.Context, db DBTX, id int64) (CheckRun, error) { |
| 82 | + row := db.QueryRow(ctx, getCheckRun, id) |
| 83 | + var i CheckRun |
| 84 | + err := row.Scan( |
| 85 | + &i.ID, |
| 86 | + &i.SuiteID, |
| 87 | + &i.RepoID, |
| 88 | + &i.HeadSha, |
| 89 | + &i.Name, |
| 90 | + &i.Status, |
| 91 | + &i.Conclusion, |
| 92 | + &i.StartedAt, |
| 93 | + &i.CompletedAt, |
| 94 | + &i.DetailsUrl, |
| 95 | + &i.Output, |
| 96 | + &i.ExternalID, |
| 97 | + &i.CreatedAt, |
| 98 | + &i.UpdatedAt, |
| 99 | + ) |
| 100 | + return i, err |
| 101 | +} |
| 102 | + |
| 103 | +const getCheckRunByExternalID = `-- name: GetCheckRunByExternalID :one |
| 104 | + |
| 105 | +SELECT id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at FROM check_runs |
| 106 | +WHERE repo_id = $1 AND head_sha = $2 AND name = $3 AND external_id = $4 |
| 107 | +` |
| 108 | + |
| 109 | +type GetCheckRunByExternalIDParams struct { |
| 110 | + RepoID int64 |
| 111 | + HeadSha string |
| 112 | + Name string |
| 113 | + ExternalID pgtype.Text |
| 114 | +} |
| 115 | + |
| 116 | +// ─── check_runs ────────────────────────────────────────────────────── |
| 117 | +// External-system create dedupe: lookup by (repo, head_sha, name, |
| 118 | +// external_id). NULL external_id never matches via this query. |
| 119 | +func (q *Queries) GetCheckRunByExternalID(ctx context.Context, db DBTX, arg GetCheckRunByExternalIDParams) (CheckRun, error) { |
| 120 | + row := db.QueryRow(ctx, getCheckRunByExternalID, |
| 121 | + arg.RepoID, |
| 122 | + arg.HeadSha, |
| 123 | + arg.Name, |
| 124 | + arg.ExternalID, |
| 125 | + ) |
| 126 | + var i CheckRun |
| 127 | + err := row.Scan( |
| 128 | + &i.ID, |
| 129 | + &i.SuiteID, |
| 130 | + &i.RepoID, |
| 131 | + &i.HeadSha, |
| 132 | + &i.Name, |
| 133 | + &i.Status, |
| 134 | + &i.Conclusion, |
| 135 | + &i.StartedAt, |
| 136 | + &i.CompletedAt, |
| 137 | + &i.DetailsUrl, |
| 138 | + &i.Output, |
| 139 | + &i.ExternalID, |
| 140 | + &i.CreatedAt, |
| 141 | + &i.UpdatedAt, |
| 142 | + ) |
| 143 | + return i, err |
| 144 | +} |
| 145 | + |
| 146 | +const getCheckSuite = `-- name: GetCheckSuite :one |
| 147 | +SELECT id, repo_id, head_sha, app_slug, status, conclusion, created_at, updated_at FROM check_suites WHERE id = $1 |
| 148 | +` |
| 149 | + |
| 150 | +func (q *Queries) GetCheckSuite(ctx context.Context, db DBTX, id int64) (CheckSuite, error) { |
| 151 | + row := db.QueryRow(ctx, getCheckSuite, id) |
| 152 | + var i CheckSuite |
| 153 | + err := row.Scan( |
| 154 | + &i.ID, |
| 155 | + &i.RepoID, |
| 156 | + &i.HeadSha, |
| 157 | + &i.AppSlug, |
| 158 | + &i.Status, |
| 159 | + &i.Conclusion, |
| 160 | + &i.CreatedAt, |
| 161 | + &i.UpdatedAt, |
| 162 | + ) |
| 163 | + return i, err |
| 164 | +} |
| 165 | + |
| 166 | +const getLatestCheckRunByName = `-- name: GetLatestCheckRunByName :one |
| 167 | +SELECT id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at FROM check_runs |
| 168 | +WHERE repo_id = $1 AND head_sha = $2 AND name = $3 |
| 169 | +ORDER BY created_at DESC |
| 170 | +LIMIT 1 |
| 171 | +` |
| 172 | + |
| 173 | +type GetLatestCheckRunByNameParams struct { |
| 174 | + RepoID int64 |
| 175 | + HeadSha string |
| 176 | + Name string |
| 177 | +} |
| 178 | + |
| 179 | +// Required-check evaluator: most recent run with the given name on the |
| 180 | +// specified head_sha. |
| 181 | +func (q *Queries) GetLatestCheckRunByName(ctx context.Context, db DBTX, arg GetLatestCheckRunByNameParams) (CheckRun, error) { |
| 182 | + row := db.QueryRow(ctx, getLatestCheckRunByName, arg.RepoID, arg.HeadSha, arg.Name) |
| 183 | + var i CheckRun |
| 184 | + err := row.Scan( |
| 185 | + &i.ID, |
| 186 | + &i.SuiteID, |
| 187 | + &i.RepoID, |
| 188 | + &i.HeadSha, |
| 189 | + &i.Name, |
| 190 | + &i.Status, |
| 191 | + &i.Conclusion, |
| 192 | + &i.StartedAt, |
| 193 | + &i.CompletedAt, |
| 194 | + &i.DetailsUrl, |
| 195 | + &i.Output, |
| 196 | + &i.ExternalID, |
| 197 | + &i.CreatedAt, |
| 198 | + &i.UpdatedAt, |
| 199 | + ) |
| 200 | + return i, err |
| 201 | +} |
| 202 | + |
| 203 | +const getOrCreateCheckSuite = `-- name: GetOrCreateCheckSuite :one |
| 204 | + |
| 205 | + |
| 206 | +INSERT INTO check_suites (repo_id, head_sha, app_slug) |
| 207 | +VALUES ($1, $2, $3) |
| 208 | +ON CONFLICT (repo_id, head_sha, app_slug) DO UPDATE |
| 209 | + SET app_slug = EXCLUDED.app_slug |
| 210 | +RETURNING id, repo_id, head_sha, app_slug, status, conclusion, created_at, updated_at |
| 211 | +` |
| 212 | + |
| 213 | +type GetOrCreateCheckSuiteParams struct { |
| 214 | + RepoID int64 |
| 215 | + HeadSha string |
| 216 | + AppSlug string |
| 217 | +} |
| 218 | + |
| 219 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 220 | +// ─── check_suites ──────────────────────────────────────────────────── |
| 221 | +// Idempotent suite-by-(repo, head_sha, app_slug) lookup. Used by every |
| 222 | +// check-run create so consumers don't need to manage suite ids. ON |
| 223 | +// CONFLICT … DO UPDATE returns the existing row when the unique |
| 224 | +// (repo_id, head_sha, app_slug) already exists; otherwise returns the |
| 225 | +// freshly inserted one. |
| 226 | +func (q *Queries) GetOrCreateCheckSuite(ctx context.Context, db DBTX, arg GetOrCreateCheckSuiteParams) (CheckSuite, error) { |
| 227 | + row := db.QueryRow(ctx, getOrCreateCheckSuite, arg.RepoID, arg.HeadSha, arg.AppSlug) |
| 228 | + var i CheckSuite |
| 229 | + err := row.Scan( |
| 230 | + &i.ID, |
| 231 | + &i.RepoID, |
| 232 | + &i.HeadSha, |
| 233 | + &i.AppSlug, |
| 234 | + &i.Status, |
| 235 | + &i.Conclusion, |
| 236 | + &i.CreatedAt, |
| 237 | + &i.UpdatedAt, |
| 238 | + ) |
| 239 | + return i, err |
| 240 | +} |
| 241 | + |
| 242 | +const listCheckRunsBySuite = `-- name: ListCheckRunsBySuite :many |
| 243 | +SELECT id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at FROM check_runs |
| 244 | +WHERE suite_id = $1 |
| 245 | +ORDER BY name |
| 246 | +` |
| 247 | + |
| 248 | +func (q *Queries) ListCheckRunsBySuite(ctx context.Context, db DBTX, suiteID int64) ([]CheckRun, error) { |
| 249 | + rows, err := db.Query(ctx, listCheckRunsBySuite, suiteID) |
| 250 | + if err != nil { |
| 251 | + return nil, err |
| 252 | + } |
| 253 | + defer rows.Close() |
| 254 | + items := []CheckRun{} |
| 255 | + for rows.Next() { |
| 256 | + var i CheckRun |
| 257 | + if err := rows.Scan( |
| 258 | + &i.ID, |
| 259 | + &i.SuiteID, |
| 260 | + &i.RepoID, |
| 261 | + &i.HeadSha, |
| 262 | + &i.Name, |
| 263 | + &i.Status, |
| 264 | + &i.Conclusion, |
| 265 | + &i.StartedAt, |
| 266 | + &i.CompletedAt, |
| 267 | + &i.DetailsUrl, |
| 268 | + &i.Output, |
| 269 | + &i.ExternalID, |
| 270 | + &i.CreatedAt, |
| 271 | + &i.UpdatedAt, |
| 272 | + ); err != nil { |
| 273 | + return nil, err |
| 274 | + } |
| 275 | + items = append(items, i) |
| 276 | + } |
| 277 | + if err := rows.Err(); err != nil { |
| 278 | + return nil, err |
| 279 | + } |
| 280 | + return items, nil |
| 281 | +} |
| 282 | + |
| 283 | +const listCheckRunsForCommit = `-- name: ListCheckRunsForCommit :many |
| 284 | +SELECT id, suite_id, repo_id, head_sha, name, status, conclusion, started_at, completed_at, details_url, output, external_id, created_at, updated_at FROM check_runs |
| 285 | +WHERE repo_id = $1 AND head_sha = $2 |
| 286 | +ORDER BY name |
| 287 | +` |
| 288 | + |
| 289 | +type ListCheckRunsForCommitParams struct { |
| 290 | + RepoID int64 |
| 291 | + HeadSha string |
| 292 | +} |
| 293 | + |
| 294 | +func (q *Queries) ListCheckRunsForCommit(ctx context.Context, db DBTX, arg ListCheckRunsForCommitParams) ([]CheckRun, error) { |
| 295 | + rows, err := db.Query(ctx, listCheckRunsForCommit, arg.RepoID, arg.HeadSha) |
| 296 | + if err != nil { |
| 297 | + return nil, err |
| 298 | + } |
| 299 | + defer rows.Close() |
| 300 | + items := []CheckRun{} |
| 301 | + for rows.Next() { |
| 302 | + var i CheckRun |
| 303 | + if err := rows.Scan( |
| 304 | + &i.ID, |
| 305 | + &i.SuiteID, |
| 306 | + &i.RepoID, |
| 307 | + &i.HeadSha, |
| 308 | + &i.Name, |
| 309 | + &i.Status, |
| 310 | + &i.Conclusion, |
| 311 | + &i.StartedAt, |
| 312 | + &i.CompletedAt, |
| 313 | + &i.DetailsUrl, |
| 314 | + &i.Output, |
| 315 | + &i.ExternalID, |
| 316 | + &i.CreatedAt, |
| 317 | + &i.UpdatedAt, |
| 318 | + ); err != nil { |
| 319 | + return nil, err |
| 320 | + } |
| 321 | + items = append(items, i) |
| 322 | + } |
| 323 | + if err := rows.Err(); err != nil { |
| 324 | + return nil, err |
| 325 | + } |
| 326 | + return items, nil |
| 327 | +} |
| 328 | + |
| 329 | +const listCheckSuiteIDsForHead = `-- name: ListCheckSuiteIDsForHead :many |
| 330 | +SELECT id FROM check_suites |
| 331 | +WHERE repo_id = $1 AND head_sha = $2 AND status <> 'completed' |
| 332 | +` |
| 333 | + |
| 334 | +type ListCheckSuiteIDsForHeadParams struct { |
| 335 | + RepoID int64 |
| 336 | + HeadSha string |
| 337 | +} |
| 338 | + |
| 339 | +// Used by the stale-on-push hook to flip queued/in_progress suites on |
| 340 | +// the previous head to conclusion='stale'. |
| 341 | +func (q *Queries) ListCheckSuiteIDsForHead(ctx context.Context, db DBTX, arg ListCheckSuiteIDsForHeadParams) ([]int64, error) { |
| 342 | + rows, err := db.Query(ctx, listCheckSuiteIDsForHead, arg.RepoID, arg.HeadSha) |
| 343 | + if err != nil { |
| 344 | + return nil, err |
| 345 | + } |
| 346 | + defer rows.Close() |
| 347 | + items := []int64{} |
| 348 | + for rows.Next() { |
| 349 | + var id int64 |
| 350 | + if err := rows.Scan(&id); err != nil { |
| 351 | + return nil, err |
| 352 | + } |
| 353 | + items = append(items, id) |
| 354 | + } |
| 355 | + if err := rows.Err(); err != nil { |
| 356 | + return nil, err |
| 357 | + } |
| 358 | + return items, nil |
| 359 | +} |
| 360 | + |
| 361 | +const listCheckSuitesForCommit = `-- name: ListCheckSuitesForCommit :many |
| 362 | +SELECT id, repo_id, head_sha, app_slug, status, conclusion, created_at, updated_at FROM check_suites |
| 363 | +WHERE repo_id = $1 AND head_sha = $2 |
| 364 | +ORDER BY app_slug |
| 365 | +` |
| 366 | + |
| 367 | +type ListCheckSuitesForCommitParams struct { |
| 368 | + RepoID int64 |
| 369 | + HeadSha string |
| 370 | +} |
| 371 | + |
| 372 | +func (q *Queries) ListCheckSuitesForCommit(ctx context.Context, db DBTX, arg ListCheckSuitesForCommitParams) ([]CheckSuite, error) { |
| 373 | + rows, err := db.Query(ctx, listCheckSuitesForCommit, arg.RepoID, arg.HeadSha) |
| 374 | + if err != nil { |
| 375 | + return nil, err |
| 376 | + } |
| 377 | + defer rows.Close() |
| 378 | + items := []CheckSuite{} |
| 379 | + for rows.Next() { |
| 380 | + var i CheckSuite |
| 381 | + if err := rows.Scan( |
| 382 | + &i.ID, |
| 383 | + &i.RepoID, |
| 384 | + &i.HeadSha, |
| 385 | + &i.AppSlug, |
| 386 | + &i.Status, |
| 387 | + &i.Conclusion, |
| 388 | + &i.CreatedAt, |
| 389 | + &i.UpdatedAt, |
| 390 | + ); err != nil { |
| 391 | + return nil, err |
| 392 | + } |
| 393 | + items = append(items, i) |
| 394 | + } |
| 395 | + if err := rows.Err(); err != nil { |
| 396 | + return nil, err |
| 397 | + } |
| 398 | + return items, nil |
| 399 | +} |
| 400 | + |
| 401 | +const markCheckSuiteStale = `-- name: MarkCheckSuiteStale :exec |
| 402 | +UPDATE check_suites |
| 403 | +SET status = 'completed', conclusion = 'stale' |
| 404 | +WHERE id = $1 |
| 405 | +` |
| 406 | + |
| 407 | +func (q *Queries) MarkCheckSuiteStale(ctx context.Context, db DBTX, id int64) error { |
| 408 | + _, err := db.Exec(ctx, markCheckSuiteStale, id) |
| 409 | + return err |
| 410 | +} |
| 411 | + |
| 412 | +const updateCheckRun = `-- name: UpdateCheckRun :exec |
| 413 | +UPDATE check_runs |
| 414 | +SET status = $2, |
| 415 | + conclusion = $5::check_conclusion, |
| 416 | + started_at = $6::timestamptz, |
| 417 | + completed_at = $7::timestamptz, |
| 418 | + details_url = $3, |
| 419 | + output = $4 |
| 420 | +WHERE id = $1 |
| 421 | +` |
| 422 | + |
| 423 | +type UpdateCheckRunParams struct { |
| 424 | + ID int64 |
| 425 | + Status CheckStatus |
| 426 | + DetailsUrl string |
| 427 | + Output []byte |
| 428 | + Conclusion NullCheckConclusion |
| 429 | + StartedAt pgtype.Timestamptz |
| 430 | + CompletedAt pgtype.Timestamptz |
| 431 | +} |
| 432 | + |
| 433 | +func (q *Queries) UpdateCheckRun(ctx context.Context, db DBTX, arg UpdateCheckRunParams) error { |
| 434 | + _, err := db.Exec(ctx, updateCheckRun, |
| 435 | + arg.ID, |
| 436 | + arg.Status, |
| 437 | + arg.DetailsUrl, |
| 438 | + arg.Output, |
| 439 | + arg.Conclusion, |
| 440 | + arg.StartedAt, |
| 441 | + arg.CompletedAt, |
| 442 | + ) |
| 443 | + return err |
| 444 | +} |
| 445 | + |
| 446 | +const updateCheckSuiteRollup = `-- name: UpdateCheckSuiteRollup :exec |
| 447 | +UPDATE check_suites |
| 448 | +SET status = $2, |
| 449 | + conclusion = $3::check_conclusion |
| 450 | +WHERE id = $1 |
| 451 | +` |
| 452 | + |
| 453 | +type UpdateCheckSuiteRollupParams struct { |
| 454 | + ID int64 |
| 455 | + Status CheckStatus |
| 456 | + Conclusion NullCheckConclusion |
| 457 | +} |
| 458 | + |
| 459 | +// Persists the rollup result computed in Go (suite_rollup.go). |
| 460 | +func (q *Queries) UpdateCheckSuiteRollup(ctx context.Context, db DBTX, arg UpdateCheckSuiteRollupParams) error { |
| 461 | + _, err := db.Exec(ctx, updateCheckSuiteRollup, arg.ID, arg.Status, arg.Conclusion) |
| 462 | + return err |
| 463 | +} |