@@ -163,6 +163,75 @@ func (q *Queries) GetCheckSuite(ctx context.Context, db DBTX, id int64) (CheckSu |
| 163 | 163 | return i, err |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | +const getCheckSuiteForRepo = `-- name: GetCheckSuiteForRepo :one |
| 167 | +SELECT |
| 168 | + cs.id, cs.repo_id, cs.head_sha, cs.app_slug, cs.status, cs.conclusion, cs.created_at, cs.updated_at, |
| 169 | + COALESCE(pr_meta.number, 0)::bigint AS pull_number, |
| 170 | + COALESCE(pr_meta.title, '')::text AS pull_title, |
| 171 | + COALESCE(pr_meta.author_username, '')::text AS pull_author_username, |
| 172 | + COALESCE(pr_meta.head_ref, '')::text AS head_ref, |
| 173 | + COALESCE(pr_meta.base_ref, '')::text AS base_ref |
| 174 | +FROM check_suites cs |
| 175 | +LEFT JOIN LATERAL ( |
| 176 | + SELECT |
| 177 | + i.number, |
| 178 | + i.title, |
| 179 | + COALESCE(u.username, '') AS author_username, |
| 180 | + pr.head_ref, |
| 181 | + pr.base_ref |
| 182 | + FROM pull_requests pr |
| 183 | + JOIN issues i ON i.id = pr.issue_id AND i.kind = 'pr' |
| 184 | + LEFT JOIN users u ON u.id = i.author_user_id |
| 185 | + WHERE pr.head_repo_id = cs.repo_id |
| 186 | + AND pr.head_oid = cs.head_sha |
| 187 | + ORDER BY i.updated_at DESC, i.number DESC |
| 188 | + LIMIT 1 |
| 189 | +) pr_meta ON true |
| 190 | +WHERE cs.repo_id = $1 AND cs.id = $2 |
| 191 | +` |
| 192 | + |
| 193 | +type GetCheckSuiteForRepoParams struct { |
| 194 | + RepoID int64 |
| 195 | + ID int64 |
| 196 | +} |
| 197 | + |
| 198 | +type GetCheckSuiteForRepoRow struct { |
| 199 | + ID int64 |
| 200 | + RepoID int64 |
| 201 | + HeadSha string |
| 202 | + AppSlug string |
| 203 | + Status CheckStatus |
| 204 | + Conclusion NullCheckConclusion |
| 205 | + CreatedAt pgtype.Timestamptz |
| 206 | + UpdatedAt pgtype.Timestamptz |
| 207 | + PullNumber int64 |
| 208 | + PullTitle string |
| 209 | + PullAuthorUsername string |
| 210 | + HeadRef string |
| 211 | + BaseRef string |
| 212 | +} |
| 213 | + |
| 214 | +func (q *Queries) GetCheckSuiteForRepo(ctx context.Context, db DBTX, arg GetCheckSuiteForRepoParams) (GetCheckSuiteForRepoRow, error) { |
| 215 | + row := db.QueryRow(ctx, getCheckSuiteForRepo, arg.RepoID, arg.ID) |
| 216 | + var i GetCheckSuiteForRepoRow |
| 217 | + err := row.Scan( |
| 218 | + &i.ID, |
| 219 | + &i.RepoID, |
| 220 | + &i.HeadSha, |
| 221 | + &i.AppSlug, |
| 222 | + &i.Status, |
| 223 | + &i.Conclusion, |
| 224 | + &i.CreatedAt, |
| 225 | + &i.UpdatedAt, |
| 226 | + &i.PullNumber, |
| 227 | + &i.PullTitle, |
| 228 | + &i.PullAuthorUsername, |
| 229 | + &i.HeadRef, |
| 230 | + &i.BaseRef, |
| 231 | + ) |
| 232 | + return i, err |
| 233 | +} |
| 234 | + |
| 166 | 235 | const getLatestCheckRunByName = `-- name: GetLatestCheckRunByName :one |
| 167 | 236 | 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 | 237 | WHERE repo_id = $1 AND head_sha = $2 AND name = $3 |
@@ -398,6 +467,91 @@ func (q *Queries) ListCheckSuitesForCommit(ctx context.Context, db DBTX, arg Lis |
| 398 | 467 | return items, nil |
| 399 | 468 | } |
| 400 | 469 | |
| 470 | +const listCheckSuitesForRepo = `-- name: ListCheckSuitesForRepo :many |
| 471 | +SELECT |
| 472 | + cs.id, cs.repo_id, cs.head_sha, cs.app_slug, cs.status, cs.conclusion, cs.created_at, cs.updated_at, |
| 473 | + COALESCE(pr_meta.number, 0)::bigint AS pull_number, |
| 474 | + COALESCE(pr_meta.title, '')::text AS pull_title, |
| 475 | + COALESCE(pr_meta.author_username, '')::text AS pull_author_username, |
| 476 | + COALESCE(pr_meta.head_ref, '')::text AS head_ref, |
| 477 | + COALESCE(pr_meta.base_ref, '')::text AS base_ref |
| 478 | +FROM check_suites cs |
| 479 | +LEFT JOIN LATERAL ( |
| 480 | + SELECT |
| 481 | + i.number, |
| 482 | + i.title, |
| 483 | + COALESCE(u.username, '') AS author_username, |
| 484 | + pr.head_ref, |
| 485 | + pr.base_ref |
| 486 | + FROM pull_requests pr |
| 487 | + JOIN issues i ON i.id = pr.issue_id AND i.kind = 'pr' |
| 488 | + LEFT JOIN users u ON u.id = i.author_user_id |
| 489 | + WHERE pr.head_repo_id = cs.repo_id |
| 490 | + AND pr.head_oid = cs.head_sha |
| 491 | + ORDER BY i.updated_at DESC, i.number DESC |
| 492 | + LIMIT 1 |
| 493 | +) pr_meta ON true |
| 494 | +WHERE cs.repo_id = $1 |
| 495 | +ORDER BY cs.updated_at DESC, cs.id DESC |
| 496 | +LIMIT $2 OFFSET $3 |
| 497 | +` |
| 498 | + |
| 499 | +type ListCheckSuitesForRepoParams struct { |
| 500 | + RepoID int64 |
| 501 | + Limit int32 |
| 502 | + Offset int32 |
| 503 | +} |
| 504 | + |
| 505 | +type ListCheckSuitesForRepoRow struct { |
| 506 | + ID int64 |
| 507 | + RepoID int64 |
| 508 | + HeadSha string |
| 509 | + AppSlug string |
| 510 | + Status CheckStatus |
| 511 | + Conclusion NullCheckConclusion |
| 512 | + CreatedAt pgtype.Timestamptz |
| 513 | + UpdatedAt pgtype.Timestamptz |
| 514 | + PullNumber int64 |
| 515 | + PullTitle string |
| 516 | + PullAuthorUsername string |
| 517 | + HeadRef string |
| 518 | + BaseRef string |
| 519 | +} |
| 520 | + |
| 521 | +func (q *Queries) ListCheckSuitesForRepo(ctx context.Context, db DBTX, arg ListCheckSuitesForRepoParams) ([]ListCheckSuitesForRepoRow, error) { |
| 522 | + rows, err := db.Query(ctx, listCheckSuitesForRepo, arg.RepoID, arg.Limit, arg.Offset) |
| 523 | + if err != nil { |
| 524 | + return nil, err |
| 525 | + } |
| 526 | + defer rows.Close() |
| 527 | + items := []ListCheckSuitesForRepoRow{} |
| 528 | + for rows.Next() { |
| 529 | + var i ListCheckSuitesForRepoRow |
| 530 | + if err := rows.Scan( |
| 531 | + &i.ID, |
| 532 | + &i.RepoID, |
| 533 | + &i.HeadSha, |
| 534 | + &i.AppSlug, |
| 535 | + &i.Status, |
| 536 | + &i.Conclusion, |
| 537 | + &i.CreatedAt, |
| 538 | + &i.UpdatedAt, |
| 539 | + &i.PullNumber, |
| 540 | + &i.PullTitle, |
| 541 | + &i.PullAuthorUsername, |
| 542 | + &i.HeadRef, |
| 543 | + &i.BaseRef, |
| 544 | + ); err != nil { |
| 545 | + return nil, err |
| 546 | + } |
| 547 | + items = append(items, i) |
| 548 | + } |
| 549 | + if err := rows.Err(); err != nil { |
| 550 | + return nil, err |
| 551 | + } |
| 552 | + return items, nil |
| 553 | +} |
| 554 | + |
| 401 | 555 | const markCheckSuiteStale = `-- name: MarkCheckSuiteStale :exec |
| 402 | 556 | UPDATE check_suites |
| 403 | 557 | SET status = 'completed', conclusion = 'stale' |