@@ -63,6 +63,44 @@ func (q *Queries) CompleteWorkflowRun(ctx context.Context, db DBTX, arg Complete |
| 63 | 63 | return i, err |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | +const countWorkflowRunsForRepo = `-- name: CountWorkflowRunsForRepo :one |
| 67 | +SELECT COUNT(*)::bigint |
| 68 | +FROM workflow_runs r |
| 69 | +LEFT JOIN users u ON u.id = r.actor_user_id |
| 70 | +WHERE r.repo_id = $1::bigint |
| 71 | + AND ($2::text IS NULL OR r.workflow_file = $2::text) |
| 72 | + AND ($3::text IS NULL OR r.head_ref = $3::text) |
| 73 | + AND ($4::workflow_run_event IS NULL OR r.event = $4::workflow_run_event) |
| 74 | + AND ($5::workflow_run_status IS NULL OR r.status = $5::workflow_run_status) |
| 75 | + AND ($6::check_conclusion IS NULL OR r.conclusion = $6::check_conclusion) |
| 76 | + AND ($7::text IS NULL OR u.username = $7::citext) |
| 77 | +` |
| 78 | + |
| 79 | +type CountWorkflowRunsForRepoParams struct { |
| 80 | + RepoID int64 |
| 81 | + WorkflowFile pgtype.Text |
| 82 | + HeadRef pgtype.Text |
| 83 | + Event NullWorkflowRunEvent |
| 84 | + Status NullWorkflowRunStatus |
| 85 | + Conclusion NullCheckConclusion |
| 86 | + ActorUsername pgtype.Text |
| 87 | +} |
| 88 | + |
| 89 | +func (q *Queries) CountWorkflowRunsForRepo(ctx context.Context, db DBTX, arg CountWorkflowRunsForRepoParams) (int64, error) { |
| 90 | + row := db.QueryRow(ctx, countWorkflowRunsForRepo, |
| 91 | + arg.RepoID, |
| 92 | + arg.WorkflowFile, |
| 93 | + arg.HeadRef, |
| 94 | + arg.Event, |
| 95 | + arg.Status, |
| 96 | + arg.Conclusion, |
| 97 | + arg.ActorUsername, |
| 98 | + ) |
| 99 | + var column_1 int64 |
| 100 | + err := row.Scan(&column_1) |
| 101 | + return column_1, err |
| 102 | +} |
| 103 | + |
| 66 | 104 | const enqueueWorkflowRun = `-- name: EnqueueWorkflowRun :one |
| 67 | 105 | INSERT INTO workflow_runs ( |
| 68 | 106 | repo_id, run_index, workflow_file, workflow_name, |
@@ -268,41 +306,110 @@ func (q *Queries) InsertWorkflowRun(ctx context.Context, db DBTX, arg InsertWork |
| 268 | 306 | return i, err |
| 269 | 307 | } |
| 270 | 308 | |
| 309 | +const listWorkflowRunWorkflowsForRepo = `-- name: ListWorkflowRunWorkflowsForRepo :many |
| 310 | +WITH ranked AS ( |
| 311 | + SELECT workflow_file, |
| 312 | + workflow_name, |
| 313 | + (COUNT(*) OVER (PARTITION BY workflow_file))::bigint AS run_count, |
| 314 | + ROW_NUMBER() OVER (PARTITION BY workflow_file ORDER BY created_at DESC, id DESC) AS rn |
| 315 | + FROM workflow_runs |
| 316 | + WHERE repo_id = $1 |
| 317 | +) |
| 318 | +SELECT workflow_file, |
| 319 | + COALESCE(NULLIF(workflow_name, ''), workflow_file) AS workflow_name, |
| 320 | + run_count |
| 321 | +FROM ranked |
| 322 | +WHERE rn = 1 |
| 323 | +ORDER BY lower(COALESCE(NULLIF(workflow_name, ''), workflow_file)), workflow_file |
| 324 | +` |
| 325 | + |
| 326 | +type ListWorkflowRunWorkflowsForRepoRow struct { |
| 327 | + WorkflowFile string |
| 328 | + WorkflowName string |
| 329 | + RunCount int64 |
| 330 | +} |
| 331 | + |
| 332 | +func (q *Queries) ListWorkflowRunWorkflowsForRepo(ctx context.Context, db DBTX, repoID int64) ([]ListWorkflowRunWorkflowsForRepoRow, error) { |
| 333 | + rows, err := db.Query(ctx, listWorkflowRunWorkflowsForRepo, repoID) |
| 334 | + if err != nil { |
| 335 | + return nil, err |
| 336 | + } |
| 337 | + defer rows.Close() |
| 338 | + items := []ListWorkflowRunWorkflowsForRepoRow{} |
| 339 | + for rows.Next() { |
| 340 | + var i ListWorkflowRunWorkflowsForRepoRow |
| 341 | + if err := rows.Scan(&i.WorkflowFile, &i.WorkflowName, &i.RunCount); err != nil { |
| 342 | + return nil, err |
| 343 | + } |
| 344 | + items = append(items, i) |
| 345 | + } |
| 346 | + if err := rows.Err(); err != nil { |
| 347 | + return nil, err |
| 348 | + } |
| 349 | + return items, nil |
| 350 | +} |
| 351 | + |
| 271 | 352 | const listWorkflowRunsForRepo = `-- name: ListWorkflowRunsForRepo :many |
| 272 | | -SELECT id, repo_id, run_index, workflow_file, workflow_name, |
| 273 | | - head_sha, head_ref, event, status, conclusion, |
| 274 | | - actor_user_id, started_at, completed_at, created_at |
| 275 | | -FROM workflow_runs |
| 276 | | -WHERE repo_id = $1 |
| 277 | | -ORDER BY created_at DESC |
| 278 | | -LIMIT $2 OFFSET $3 |
| 353 | +SELECT r.id, r.repo_id, r.run_index, r.workflow_file, r.workflow_name, |
| 354 | + r.head_sha, r.head_ref, r.event, r.status, r.conclusion, |
| 355 | + r.actor_user_id, COALESCE(u.username::text, '')::text AS actor_username, |
| 356 | + r.started_at, r.completed_at, r.created_at, r.updated_at |
| 357 | +FROM workflow_runs r |
| 358 | +LEFT JOIN users u ON u.id = r.actor_user_id |
| 359 | +WHERE r.repo_id = $1::bigint |
| 360 | + AND ($2::text IS NULL OR r.workflow_file = $2::text) |
| 361 | + AND ($3::text IS NULL OR r.head_ref = $3::text) |
| 362 | + AND ($4::workflow_run_event IS NULL OR r.event = $4::workflow_run_event) |
| 363 | + AND ($5::workflow_run_status IS NULL OR r.status = $5::workflow_run_status) |
| 364 | + AND ($6::check_conclusion IS NULL OR r.conclusion = $6::check_conclusion) |
| 365 | + AND ($7::text IS NULL OR u.username = $7::citext) |
| 366 | +ORDER BY r.created_at DESC, r.id DESC |
| 367 | +LIMIT $9 OFFSET $8 |
| 279 | 368 | ` |
| 280 | 369 | |
| 281 | 370 | type ListWorkflowRunsForRepoParams struct { |
| 282 | | - RepoID int64 |
| 283 | | - Limit int32 |
| 284 | | - Offset int32 |
| 371 | + RepoID int64 |
| 372 | + WorkflowFile pgtype.Text |
| 373 | + HeadRef pgtype.Text |
| 374 | + Event NullWorkflowRunEvent |
| 375 | + Status NullWorkflowRunStatus |
| 376 | + Conclusion NullCheckConclusion |
| 377 | + ActorUsername pgtype.Text |
| 378 | + PageOffset int32 |
| 379 | + PageLimit int32 |
| 285 | 380 | } |
| 286 | 381 | |
| 287 | 382 | type ListWorkflowRunsForRepoRow struct { |
| 288 | | - ID int64 |
| 289 | | - RepoID int64 |
| 290 | | - RunIndex int64 |
| 291 | | - WorkflowFile string |
| 292 | | - WorkflowName string |
| 293 | | - HeadSha string |
| 294 | | - HeadRef string |
| 295 | | - Event WorkflowRunEvent |
| 296 | | - Status WorkflowRunStatus |
| 297 | | - Conclusion NullCheckConclusion |
| 298 | | - ActorUserID pgtype.Int8 |
| 299 | | - StartedAt pgtype.Timestamptz |
| 300 | | - CompletedAt pgtype.Timestamptz |
| 301 | | - CreatedAt pgtype.Timestamptz |
| 383 | + ID int64 |
| 384 | + RepoID int64 |
| 385 | + RunIndex int64 |
| 386 | + WorkflowFile string |
| 387 | + WorkflowName string |
| 388 | + HeadSha string |
| 389 | + HeadRef string |
| 390 | + Event WorkflowRunEvent |
| 391 | + Status WorkflowRunStatus |
| 392 | + Conclusion NullCheckConclusion |
| 393 | + ActorUserID pgtype.Int8 |
| 394 | + ActorUsername string |
| 395 | + StartedAt pgtype.Timestamptz |
| 396 | + CompletedAt pgtype.Timestamptz |
| 397 | + CreatedAt pgtype.Timestamptz |
| 398 | + UpdatedAt pgtype.Timestamptz |
| 302 | 399 | } |
| 303 | 400 | |
| 304 | 401 | func (q *Queries) ListWorkflowRunsForRepo(ctx context.Context, db DBTX, arg ListWorkflowRunsForRepoParams) ([]ListWorkflowRunsForRepoRow, error) { |
| 305 | | - rows, err := db.Query(ctx, listWorkflowRunsForRepo, arg.RepoID, arg.Limit, arg.Offset) |
| 402 | + rows, err := db.Query(ctx, listWorkflowRunsForRepo, |
| 403 | + arg.RepoID, |
| 404 | + arg.WorkflowFile, |
| 405 | + arg.HeadRef, |
| 406 | + arg.Event, |
| 407 | + arg.Status, |
| 408 | + arg.Conclusion, |
| 409 | + arg.ActorUsername, |
| 410 | + arg.PageOffset, |
| 411 | + arg.PageLimit, |
| 412 | + ) |
| 306 | 413 | if err != nil { |
| 307 | 414 | return nil, err |
| 308 | 415 | } |
@@ -322,9 +429,11 @@ func (q *Queries) ListWorkflowRunsForRepo(ctx context.Context, db DBTX, arg List |
| 322 | 429 | &i.Status, |
| 323 | 430 | &i.Conclusion, |
| 324 | 431 | &i.ActorUserID, |
| 432 | + &i.ActorUsername, |
| 325 | 433 | &i.StartedAt, |
| 326 | 434 | &i.CompletedAt, |
| 327 | 435 | &i.CreatedAt, |
| 436 | + &i.UpdatedAt, |
| 328 | 437 | ); err != nil { |
| 329 | 438 | return nil, err |
| 330 | 439 | } |