@@ -0,0 +1,743 @@ |
| 1 | +// Code generated by sqlc. DO NOT EDIT. |
| 2 | +// versions: |
| 3 | +// sqlc v1.31.1 |
| 4 | +// source: reviews.sql |
| 5 | + |
| 6 | +package pullsdb |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + |
| 11 | + "github.com/jackc/pgx/v5/pgtype" |
| 12 | +) |
| 13 | + |
| 14 | +const attachPendingCommentsToReview = `-- name: AttachPendingCommentsToReview :exec |
| 15 | +UPDATE pr_review_comments |
| 16 | +SET review_id = $3, pending = false, updated_at = now() |
| 17 | +WHERE pr_issue_id = $1 |
| 18 | + AND author_user_id = $2 |
| 19 | + AND pending = true |
| 20 | +` |
| 21 | + |
| 22 | +type AttachPendingCommentsToReviewParams struct { |
| 23 | + PrIssueID int64 |
| 24 | + AuthorUserID pgtype.Int8 |
| 25 | + ReviewID pgtype.Int8 |
| 26 | +} |
| 27 | + |
| 28 | +// One-shot UPDATE that flips a user's pending draft comments on a PR |
| 29 | +// into the just-submitted review. Runs inside the submit-review tx. |
| 30 | +func (q *Queries) AttachPendingCommentsToReview(ctx context.Context, db DBTX, arg AttachPendingCommentsToReviewParams) error { |
| 31 | + _, err := db.Exec(ctx, attachPendingCommentsToReview, arg.PrIssueID, arg.AuthorUserID, arg.ReviewID) |
| 32 | + return err |
| 33 | +} |
| 34 | + |
| 35 | +const countActivePRReviewRequests = `-- name: CountActivePRReviewRequests :one |
| 36 | +SELECT count(*)::int FROM pr_review_requests |
| 37 | +WHERE pr_issue_id = $1 |
| 38 | + AND dismissed_at IS NULL |
| 39 | +` |
| 40 | + |
| 41 | +// Used by the rate-limit gate (max 20 reviewers per PR per the spec |
| 42 | +// pitfall section). |
| 43 | +func (q *Queries) CountActivePRReviewRequests(ctx context.Context, db DBTX, prIssueID int64) (int32, error) { |
| 44 | + row := db.QueryRow(ctx, countActivePRReviewRequests, prIssueID) |
| 45 | + var column_1 int32 |
| 46 | + err := row.Scan(&column_1) |
| 47 | + return column_1, err |
| 48 | +} |
| 49 | + |
| 50 | +const countPRReviewsForGate = `-- name: CountPRReviewsForGate :one |
| 51 | +SELECT |
| 52 | + count(*) FILTER (WHERE state = 'approve' AND dismissed_at IS NULL)::int AS approves, |
| 53 | + count(*) FILTER (WHERE state = 'request_changes' AND dismissed_at IS NULL)::int AS request_changes |
| 54 | +FROM pr_reviews |
| 55 | +WHERE pr_issue_id = $1 |
| 56 | +` |
| 57 | + |
| 58 | +type CountPRReviewsForGateRow struct { |
| 59 | + Approves int32 |
| 60 | + RequestChanges int32 |
| 61 | +} |
| 62 | + |
| 63 | +// Returns the counts the merge gate cares about. `approves` excludes |
| 64 | +// dismissed reviews; `request_changes` includes only undismissed and |
| 65 | +// unsuperseded-by-same-author reviews. The "unsuperseded" semantics |
| 66 | +// (a later review by the same author wins) is computed in Go on the |
| 67 | +// caller side; this query only returns the raw rows it needs. |
| 68 | +func (q *Queries) CountPRReviewsForGate(ctx context.Context, db DBTX, prIssueID int64) (CountPRReviewsForGateRow, error) { |
| 69 | + row := db.QueryRow(ctx, countPRReviewsForGate, prIssueID) |
| 70 | + var i CountPRReviewsForGateRow |
| 71 | + err := row.Scan(&i.Approves, &i.RequestChanges) |
| 72 | + return i, err |
| 73 | +} |
| 74 | + |
| 75 | +const createPRReview = `-- name: CreatePRReview :one |
| 76 | + |
| 77 | + |
| 78 | +INSERT INTO pr_reviews ( |
| 79 | + pr_issue_id, author_user_id, state, body, body_html_cached |
| 80 | +) VALUES ( |
| 81 | + $1, $4::bigint, $2, $3, $5::text |
| 82 | +) |
| 83 | +RETURNING id, pr_issue_id, author_user_id, state, body, body_html_cached, submitted_at, dismissed_at, dismissed_by_user_id, dismissal_reason |
| 84 | +` |
| 85 | + |
| 86 | +type CreatePRReviewParams struct { |
| 87 | + PrIssueID int64 |
| 88 | + State PrReviewState |
| 89 | + Body string |
| 90 | + AuthorUserID pgtype.Int8 |
| 91 | + BodyHtmlCached pgtype.Text |
| 92 | +} |
| 93 | + |
| 94 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 95 | +// ─── pr_reviews ────────────────────────────────────────────────────── |
| 96 | +func (q *Queries) CreatePRReview(ctx context.Context, db DBTX, arg CreatePRReviewParams) (PrReview, error) { |
| 97 | + row := db.QueryRow(ctx, createPRReview, |
| 98 | + arg.PrIssueID, |
| 99 | + arg.State, |
| 100 | + arg.Body, |
| 101 | + arg.AuthorUserID, |
| 102 | + arg.BodyHtmlCached, |
| 103 | + ) |
| 104 | + var i PrReview |
| 105 | + err := row.Scan( |
| 106 | + &i.ID, |
| 107 | + &i.PrIssueID, |
| 108 | + &i.AuthorUserID, |
| 109 | + &i.State, |
| 110 | + &i.Body, |
| 111 | + &i.BodyHtmlCached, |
| 112 | + &i.SubmittedAt, |
| 113 | + &i.DismissedAt, |
| 114 | + &i.DismissedByUserID, |
| 115 | + &i.DismissalReason, |
| 116 | + ) |
| 117 | + return i, err |
| 118 | +} |
| 119 | + |
| 120 | +const createPRReviewComment = `-- name: CreatePRReviewComment :one |
| 121 | + |
| 122 | +INSERT INTO pr_review_comments ( |
| 123 | + pr_issue_id, review_id, author_user_id, file_path, side, |
| 124 | + original_commit_sha, original_line, original_position, current_position, |
| 125 | + body, body_html_cached, in_reply_to_id, pending |
| 126 | +) VALUES ( |
| 127 | + $1, $10::bigint, $11::bigint, $2, $3, |
| 128 | + $4, $5, $6, $7, |
| 129 | + $8, $12::text, $13::bigint, $9 |
| 130 | +) |
| 131 | +RETURNING id, pr_issue_id, review_id, author_user_id, file_path, side, original_commit_sha, original_line, original_position, current_position, body, body_html_cached, in_reply_to_id, pending, resolved_at, resolved_by_user_id, created_at, updated_at, edited_at |
| 132 | +` |
| 133 | + |
| 134 | +type CreatePRReviewCommentParams struct { |
| 135 | + PrIssueID int64 |
| 136 | + FilePath string |
| 137 | + Side PrReviewSide |
| 138 | + OriginalCommitSha string |
| 139 | + OriginalLine int32 |
| 140 | + OriginalPosition int32 |
| 141 | + CurrentPosition pgtype.Int4 |
| 142 | + Body string |
| 143 | + Pending bool |
| 144 | + ReviewID pgtype.Int8 |
| 145 | + AuthorUserID pgtype.Int8 |
| 146 | + BodyHtmlCached pgtype.Text |
| 147 | + InReplyToID pgtype.Int8 |
| 148 | +} |
| 149 | + |
| 150 | +// ─── pr_review_comments ────────────────────────────────────────────── |
| 151 | +func (q *Queries) CreatePRReviewComment(ctx context.Context, db DBTX, arg CreatePRReviewCommentParams) (PrReviewComment, error) { |
| 152 | + row := db.QueryRow(ctx, createPRReviewComment, |
| 153 | + arg.PrIssueID, |
| 154 | + arg.FilePath, |
| 155 | + arg.Side, |
| 156 | + arg.OriginalCommitSha, |
| 157 | + arg.OriginalLine, |
| 158 | + arg.OriginalPosition, |
| 159 | + arg.CurrentPosition, |
| 160 | + arg.Body, |
| 161 | + arg.Pending, |
| 162 | + arg.ReviewID, |
| 163 | + arg.AuthorUserID, |
| 164 | + arg.BodyHtmlCached, |
| 165 | + arg.InReplyToID, |
| 166 | + ) |
| 167 | + var i PrReviewComment |
| 168 | + err := row.Scan( |
| 169 | + &i.ID, |
| 170 | + &i.PrIssueID, |
| 171 | + &i.ReviewID, |
| 172 | + &i.AuthorUserID, |
| 173 | + &i.FilePath, |
| 174 | + &i.Side, |
| 175 | + &i.OriginalCommitSha, |
| 176 | + &i.OriginalLine, |
| 177 | + &i.OriginalPosition, |
| 178 | + &i.CurrentPosition, |
| 179 | + &i.Body, |
| 180 | + &i.BodyHtmlCached, |
| 181 | + &i.InReplyToID, |
| 182 | + &i.Pending, |
| 183 | + &i.ResolvedAt, |
| 184 | + &i.ResolvedByUserID, |
| 185 | + &i.CreatedAt, |
| 186 | + &i.UpdatedAt, |
| 187 | + &i.EditedAt, |
| 188 | + ) |
| 189 | + return i, err |
| 190 | +} |
| 191 | + |
| 192 | +const createPRReviewRequest = `-- name: CreatePRReviewRequest :one |
| 193 | + |
| 194 | +INSERT INTO pr_review_requests ( |
| 195 | + pr_issue_id, requested_user_id, requested_team_id, requested_by_user_id |
| 196 | +) VALUES ( |
| 197 | + $1, $2::bigint, $3::bigint, $4::bigint |
| 198 | +) |
| 199 | +RETURNING id, pr_issue_id, requested_user_id, requested_team_id, requested_by_user_id, requested_at, dismissed_at, satisfied_by_review_id |
| 200 | +` |
| 201 | + |
| 202 | +type CreatePRReviewRequestParams struct { |
| 203 | + PrIssueID int64 |
| 204 | + RequestedUserID pgtype.Int8 |
| 205 | + RequestedTeamID pgtype.Int8 |
| 206 | + RequestedByUserID pgtype.Int8 |
| 207 | +} |
| 208 | + |
| 209 | +// ─── pr_review_requests ────────────────────────────────────────────── |
| 210 | +func (q *Queries) CreatePRReviewRequest(ctx context.Context, db DBTX, arg CreatePRReviewRequestParams) (PrReviewRequest, error) { |
| 211 | + row := db.QueryRow(ctx, createPRReviewRequest, |
| 212 | + arg.PrIssueID, |
| 213 | + arg.RequestedUserID, |
| 214 | + arg.RequestedTeamID, |
| 215 | + arg.RequestedByUserID, |
| 216 | + ) |
| 217 | + var i PrReviewRequest |
| 218 | + err := row.Scan( |
| 219 | + &i.ID, |
| 220 | + &i.PrIssueID, |
| 221 | + &i.RequestedUserID, |
| 222 | + &i.RequestedTeamID, |
| 223 | + &i.RequestedByUserID, |
| 224 | + &i.RequestedAt, |
| 225 | + &i.DismissedAt, |
| 226 | + &i.SatisfiedByReviewID, |
| 227 | + ) |
| 228 | + return i, err |
| 229 | +} |
| 230 | + |
| 231 | +const dismissPRReview = `-- name: DismissPRReview :exec |
| 232 | +UPDATE pr_reviews |
| 233 | +SET dismissed_at = now(), |
| 234 | + dismissed_by_user_id = $3::bigint, |
| 235 | + dismissal_reason = $2 |
| 236 | +WHERE id = $1 |
| 237 | +` |
| 238 | + |
| 239 | +type DismissPRReviewParams struct { |
| 240 | + ID int64 |
| 241 | + DismissalReason string |
| 242 | + DismissedByUserID pgtype.Int8 |
| 243 | +} |
| 244 | + |
| 245 | +func (q *Queries) DismissPRReview(ctx context.Context, db DBTX, arg DismissPRReviewParams) error { |
| 246 | + _, err := db.Exec(ctx, dismissPRReview, arg.ID, arg.DismissalReason, arg.DismissedByUserID) |
| 247 | + return err |
| 248 | +} |
| 249 | + |
| 250 | +const dismissPRReviewRequest = `-- name: DismissPRReviewRequest :exec |
| 251 | +UPDATE pr_review_requests |
| 252 | +SET dismissed_at = now() |
| 253 | +WHERE id = $1 |
| 254 | +` |
| 255 | + |
| 256 | +func (q *Queries) DismissPRReviewRequest(ctx context.Context, db DBTX, id int64) error { |
| 257 | + _, err := db.Exec(ctx, dismissPRReviewRequest, id) |
| 258 | + return err |
| 259 | +} |
| 260 | + |
| 261 | +const getPRReviewByID = `-- name: GetPRReviewByID :one |
| 262 | +SELECT id, pr_issue_id, author_user_id, state, body, body_html_cached, submitted_at, dismissed_at, dismissed_by_user_id, dismissal_reason FROM pr_reviews WHERE id = $1 |
| 263 | +` |
| 264 | + |
| 265 | +func (q *Queries) GetPRReviewByID(ctx context.Context, db DBTX, id int64) (PrReview, error) { |
| 266 | + row := db.QueryRow(ctx, getPRReviewByID, id) |
| 267 | + var i PrReview |
| 268 | + err := row.Scan( |
| 269 | + &i.ID, |
| 270 | + &i.PrIssueID, |
| 271 | + &i.AuthorUserID, |
| 272 | + &i.State, |
| 273 | + &i.Body, |
| 274 | + &i.BodyHtmlCached, |
| 275 | + &i.SubmittedAt, |
| 276 | + &i.DismissedAt, |
| 277 | + &i.DismissedByUserID, |
| 278 | + &i.DismissalReason, |
| 279 | + ) |
| 280 | + return i, err |
| 281 | +} |
| 282 | + |
| 283 | +const getPRReviewComment = `-- name: GetPRReviewComment :one |
| 284 | +SELECT id, pr_issue_id, review_id, author_user_id, file_path, side, original_commit_sha, original_line, original_position, current_position, body, body_html_cached, in_reply_to_id, pending, resolved_at, resolved_by_user_id, created_at, updated_at, edited_at FROM pr_review_comments WHERE id = $1 |
| 285 | +` |
| 286 | + |
| 287 | +func (q *Queries) GetPRReviewComment(ctx context.Context, db DBTX, id int64) (PrReviewComment, error) { |
| 288 | + row := db.QueryRow(ctx, getPRReviewComment, id) |
| 289 | + var i PrReviewComment |
| 290 | + err := row.Scan( |
| 291 | + &i.ID, |
| 292 | + &i.PrIssueID, |
| 293 | + &i.ReviewID, |
| 294 | + &i.AuthorUserID, |
| 295 | + &i.FilePath, |
| 296 | + &i.Side, |
| 297 | + &i.OriginalCommitSha, |
| 298 | + &i.OriginalLine, |
| 299 | + &i.OriginalPosition, |
| 300 | + &i.CurrentPosition, |
| 301 | + &i.Body, |
| 302 | + &i.BodyHtmlCached, |
| 303 | + &i.InReplyToID, |
| 304 | + &i.Pending, |
| 305 | + &i.ResolvedAt, |
| 306 | + &i.ResolvedByUserID, |
| 307 | + &i.CreatedAt, |
| 308 | + &i.UpdatedAt, |
| 309 | + &i.EditedAt, |
| 310 | + ) |
| 311 | + return i, err |
| 312 | +} |
| 313 | + |
| 314 | +const listNonDraftCommentsForPositionMap = `-- name: ListNonDraftCommentsForPositionMap :many |
| 315 | +SELECT id, file_path, side, original_commit_sha, original_line, original_position |
| 316 | +FROM pr_review_comments |
| 317 | +WHERE pr_issue_id = $1 |
| 318 | + AND pending = false |
| 319 | +` |
| 320 | + |
| 321 | +type ListNonDraftCommentsForPositionMapRow struct { |
| 322 | + ID int64 |
| 323 | + FilePath string |
| 324 | + Side PrReviewSide |
| 325 | + OriginalCommitSha string |
| 326 | + OriginalLine int32 |
| 327 | + OriginalPosition int32 |
| 328 | +} |
| 329 | + |
| 330 | +// Position-mapping reads only submitted comments (drafts re-anchor |
| 331 | +// when the user resumes the diff view). |
| 332 | +func (q *Queries) ListNonDraftCommentsForPositionMap(ctx context.Context, db DBTX, prIssueID int64) ([]ListNonDraftCommentsForPositionMapRow, error) { |
| 333 | + rows, err := db.Query(ctx, listNonDraftCommentsForPositionMap, prIssueID) |
| 334 | + if err != nil { |
| 335 | + return nil, err |
| 336 | + } |
| 337 | + defer rows.Close() |
| 338 | + items := []ListNonDraftCommentsForPositionMapRow{} |
| 339 | + for rows.Next() { |
| 340 | + var i ListNonDraftCommentsForPositionMapRow |
| 341 | + if err := rows.Scan( |
| 342 | + &i.ID, |
| 343 | + &i.FilePath, |
| 344 | + &i.Side, |
| 345 | + &i.OriginalCommitSha, |
| 346 | + &i.OriginalLine, |
| 347 | + &i.OriginalPosition, |
| 348 | + ); err != nil { |
| 349 | + return nil, err |
| 350 | + } |
| 351 | + items = append(items, i) |
| 352 | + } |
| 353 | + if err := rows.Err(); err != nil { |
| 354 | + return nil, err |
| 355 | + } |
| 356 | + return items, nil |
| 357 | +} |
| 358 | + |
| 359 | +const listPRReviewComments = `-- name: ListPRReviewComments :many |
| 360 | +SELECT id, pr_issue_id, review_id, author_user_id, file_path, side, original_commit_sha, original_line, original_position, current_position, body, body_html_cached, in_reply_to_id, pending, resolved_at, resolved_by_user_id, created_at, updated_at, edited_at FROM pr_review_comments |
| 361 | +WHERE pr_issue_id = $1 |
| 362 | +ORDER BY created_at |
| 363 | +` |
| 364 | + |
| 365 | +func (q *Queries) ListPRReviewComments(ctx context.Context, db DBTX, prIssueID int64) ([]PrReviewComment, error) { |
| 366 | + rows, err := db.Query(ctx, listPRReviewComments, prIssueID) |
| 367 | + if err != nil { |
| 368 | + return nil, err |
| 369 | + } |
| 370 | + defer rows.Close() |
| 371 | + items := []PrReviewComment{} |
| 372 | + for rows.Next() { |
| 373 | + var i PrReviewComment |
| 374 | + if err := rows.Scan( |
| 375 | + &i.ID, |
| 376 | + &i.PrIssueID, |
| 377 | + &i.ReviewID, |
| 378 | + &i.AuthorUserID, |
| 379 | + &i.FilePath, |
| 380 | + &i.Side, |
| 381 | + &i.OriginalCommitSha, |
| 382 | + &i.OriginalLine, |
| 383 | + &i.OriginalPosition, |
| 384 | + &i.CurrentPosition, |
| 385 | + &i.Body, |
| 386 | + &i.BodyHtmlCached, |
| 387 | + &i.InReplyToID, |
| 388 | + &i.Pending, |
| 389 | + &i.ResolvedAt, |
| 390 | + &i.ResolvedByUserID, |
| 391 | + &i.CreatedAt, |
| 392 | + &i.UpdatedAt, |
| 393 | + &i.EditedAt, |
| 394 | + ); err != nil { |
| 395 | + return nil, err |
| 396 | + } |
| 397 | + items = append(items, i) |
| 398 | + } |
| 399 | + if err := rows.Err(); err != nil { |
| 400 | + return nil, err |
| 401 | + } |
| 402 | + return items, nil |
| 403 | +} |
| 404 | + |
| 405 | +const listPRReviewCommentsForFile = `-- name: ListPRReviewCommentsForFile :many |
| 406 | +SELECT id, pr_issue_id, review_id, author_user_id, file_path, side, original_commit_sha, original_line, original_position, current_position, body, body_html_cached, in_reply_to_id, pending, resolved_at, resolved_by_user_id, created_at, updated_at, edited_at FROM pr_review_comments |
| 407 | +WHERE pr_issue_id = $1 |
| 408 | + AND file_path = $2 |
| 409 | + AND pending = false |
| 410 | +ORDER BY created_at |
| 411 | +` |
| 412 | + |
| 413 | +type ListPRReviewCommentsForFileParams struct { |
| 414 | + PrIssueID int64 |
| 415 | + FilePath string |
| 416 | +} |
| 417 | + |
| 418 | +// Files-tab fetch: comments anchored to a single file path, oldest first. |
| 419 | +func (q *Queries) ListPRReviewCommentsForFile(ctx context.Context, db DBTX, arg ListPRReviewCommentsForFileParams) ([]PrReviewComment, error) { |
| 420 | + rows, err := db.Query(ctx, listPRReviewCommentsForFile, arg.PrIssueID, arg.FilePath) |
| 421 | + if err != nil { |
| 422 | + return nil, err |
| 423 | + } |
| 424 | + defer rows.Close() |
| 425 | + items := []PrReviewComment{} |
| 426 | + for rows.Next() { |
| 427 | + var i PrReviewComment |
| 428 | + if err := rows.Scan( |
| 429 | + &i.ID, |
| 430 | + &i.PrIssueID, |
| 431 | + &i.ReviewID, |
| 432 | + &i.AuthorUserID, |
| 433 | + &i.FilePath, |
| 434 | + &i.Side, |
| 435 | + &i.OriginalCommitSha, |
| 436 | + &i.OriginalLine, |
| 437 | + &i.OriginalPosition, |
| 438 | + &i.CurrentPosition, |
| 439 | + &i.Body, |
| 440 | + &i.BodyHtmlCached, |
| 441 | + &i.InReplyToID, |
| 442 | + &i.Pending, |
| 443 | + &i.ResolvedAt, |
| 444 | + &i.ResolvedByUserID, |
| 445 | + &i.CreatedAt, |
| 446 | + &i.UpdatedAt, |
| 447 | + &i.EditedAt, |
| 448 | + ); err != nil { |
| 449 | + return nil, err |
| 450 | + } |
| 451 | + items = append(items, i) |
| 452 | + } |
| 453 | + if err := rows.Err(); err != nil { |
| 454 | + return nil, err |
| 455 | + } |
| 456 | + return items, nil |
| 457 | +} |
| 458 | + |
| 459 | +const listPRReviewRequests = `-- name: ListPRReviewRequests :many |
| 460 | +SELECT id, pr_issue_id, requested_user_id, requested_team_id, requested_by_user_id, requested_at, dismissed_at, satisfied_by_review_id FROM pr_review_requests |
| 461 | +WHERE pr_issue_id = $1 |
| 462 | +ORDER BY requested_at |
| 463 | +` |
| 464 | + |
| 465 | +func (q *Queries) ListPRReviewRequests(ctx context.Context, db DBTX, prIssueID int64) ([]PrReviewRequest, error) { |
| 466 | + rows, err := db.Query(ctx, listPRReviewRequests, prIssueID) |
| 467 | + if err != nil { |
| 468 | + return nil, err |
| 469 | + } |
| 470 | + defer rows.Close() |
| 471 | + items := []PrReviewRequest{} |
| 472 | + for rows.Next() { |
| 473 | + var i PrReviewRequest |
| 474 | + if err := rows.Scan( |
| 475 | + &i.ID, |
| 476 | + &i.PrIssueID, |
| 477 | + &i.RequestedUserID, |
| 478 | + &i.RequestedTeamID, |
| 479 | + &i.RequestedByUserID, |
| 480 | + &i.RequestedAt, |
| 481 | + &i.DismissedAt, |
| 482 | + &i.SatisfiedByReviewID, |
| 483 | + ); err != nil { |
| 484 | + return nil, err |
| 485 | + } |
| 486 | + items = append(items, i) |
| 487 | + } |
| 488 | + if err := rows.Err(); err != nil { |
| 489 | + return nil, err |
| 490 | + } |
| 491 | + return items, nil |
| 492 | +} |
| 493 | + |
| 494 | +const listPRReviews = `-- name: ListPRReviews :many |
| 495 | +SELECT id, pr_issue_id, author_user_id, state, body, body_html_cached, submitted_at, dismissed_at, dismissed_by_user_id, dismissal_reason FROM pr_reviews |
| 496 | +WHERE pr_issue_id = $1 |
| 497 | +ORDER BY submitted_at |
| 498 | +` |
| 499 | + |
| 500 | +func (q *Queries) ListPRReviews(ctx context.Context, db DBTX, prIssueID int64) ([]PrReview, error) { |
| 501 | + rows, err := db.Query(ctx, listPRReviews, prIssueID) |
| 502 | + if err != nil { |
| 503 | + return nil, err |
| 504 | + } |
| 505 | + defer rows.Close() |
| 506 | + items := []PrReview{} |
| 507 | + for rows.Next() { |
| 508 | + var i PrReview |
| 509 | + if err := rows.Scan( |
| 510 | + &i.ID, |
| 511 | + &i.PrIssueID, |
| 512 | + &i.AuthorUserID, |
| 513 | + &i.State, |
| 514 | + &i.Body, |
| 515 | + &i.BodyHtmlCached, |
| 516 | + &i.SubmittedAt, |
| 517 | + &i.DismissedAt, |
| 518 | + &i.DismissedByUserID, |
| 519 | + &i.DismissalReason, |
| 520 | + ); err != nil { |
| 521 | + return nil, err |
| 522 | + } |
| 523 | + items = append(items, i) |
| 524 | + } |
| 525 | + if err := rows.Err(); err != nil { |
| 526 | + return nil, err |
| 527 | + } |
| 528 | + return items, nil |
| 529 | +} |
| 530 | + |
| 531 | +const listPendingDraftCommentsForUser = `-- name: ListPendingDraftCommentsForUser :many |
| 532 | +SELECT id, pr_issue_id, review_id, author_user_id, file_path, side, original_commit_sha, original_line, original_position, current_position, body, body_html_cached, in_reply_to_id, pending, resolved_at, resolved_by_user_id, created_at, updated_at, edited_at FROM pr_review_comments |
| 533 | +WHERE pr_issue_id = $1 |
| 534 | + AND author_user_id = $2 |
| 535 | + AND pending = true |
| 536 | +ORDER BY created_at |
| 537 | +` |
| 538 | + |
| 539 | +type ListPendingDraftCommentsForUserParams struct { |
| 540 | + PrIssueID int64 |
| 541 | + AuthorUserID pgtype.Int8 |
| 542 | +} |
| 543 | + |
| 544 | +// Server-side draft listing: rows with pending=true belonging to one |
| 545 | +// user. Ordered by creation so the submit step processes them in order. |
| 546 | +func (q *Queries) ListPendingDraftCommentsForUser(ctx context.Context, db DBTX, arg ListPendingDraftCommentsForUserParams) ([]PrReviewComment, error) { |
| 547 | + rows, err := db.Query(ctx, listPendingDraftCommentsForUser, arg.PrIssueID, arg.AuthorUserID) |
| 548 | + if err != nil { |
| 549 | + return nil, err |
| 550 | + } |
| 551 | + defer rows.Close() |
| 552 | + items := []PrReviewComment{} |
| 553 | + for rows.Next() { |
| 554 | + var i PrReviewComment |
| 555 | + if err := rows.Scan( |
| 556 | + &i.ID, |
| 557 | + &i.PrIssueID, |
| 558 | + &i.ReviewID, |
| 559 | + &i.AuthorUserID, |
| 560 | + &i.FilePath, |
| 561 | + &i.Side, |
| 562 | + &i.OriginalCommitSha, |
| 563 | + &i.OriginalLine, |
| 564 | + &i.OriginalPosition, |
| 565 | + &i.CurrentPosition, |
| 566 | + &i.Body, |
| 567 | + &i.BodyHtmlCached, |
| 568 | + &i.InReplyToID, |
| 569 | + &i.Pending, |
| 570 | + &i.ResolvedAt, |
| 571 | + &i.ResolvedByUserID, |
| 572 | + &i.CreatedAt, |
| 573 | + &i.UpdatedAt, |
| 574 | + &i.EditedAt, |
| 575 | + ); err != nil { |
| 576 | + return nil, err |
| 577 | + } |
| 578 | + items = append(items, i) |
| 579 | + } |
| 580 | + if err := rows.Err(); err != nil { |
| 581 | + return nil, err |
| 582 | + } |
| 583 | + return items, nil |
| 584 | +} |
| 585 | + |
| 586 | +const listPendingReviewRequestsForUser = `-- name: ListPendingReviewRequestsForUser :many |
| 587 | +SELECT pr.id, pr.pr_issue_id, pr.requested_user_id, pr.requested_team_id, pr.requested_by_user_id, pr.requested_at, pr.dismissed_at, pr.satisfied_by_review_id FROM pr_review_requests pr |
| 588 | +WHERE requested_user_id = $1 |
| 589 | + AND dismissed_at IS NULL |
| 590 | + AND satisfied_by_review_id IS NULL |
| 591 | +ORDER BY requested_at DESC |
| 592 | +` |
| 593 | + |
| 594 | +// Reviewer's inbox feed. Excludes dismissed + satisfied requests. |
| 595 | +func (q *Queries) ListPendingReviewRequestsForUser(ctx context.Context, db DBTX, requestedUserID pgtype.Int8) ([]PrReviewRequest, error) { |
| 596 | + rows, err := db.Query(ctx, listPendingReviewRequestsForUser, requestedUserID) |
| 597 | + if err != nil { |
| 598 | + return nil, err |
| 599 | + } |
| 600 | + defer rows.Close() |
| 601 | + items := []PrReviewRequest{} |
| 602 | + for rows.Next() { |
| 603 | + var i PrReviewRequest |
| 604 | + if err := rows.Scan( |
| 605 | + &i.ID, |
| 606 | + &i.PrIssueID, |
| 607 | + &i.RequestedUserID, |
| 608 | + &i.RequestedTeamID, |
| 609 | + &i.RequestedByUserID, |
| 610 | + &i.RequestedAt, |
| 611 | + &i.DismissedAt, |
| 612 | + &i.SatisfiedByReviewID, |
| 613 | + ); err != nil { |
| 614 | + return nil, err |
| 615 | + } |
| 616 | + items = append(items, i) |
| 617 | + } |
| 618 | + if err := rows.Err(); err != nil { |
| 619 | + return nil, err |
| 620 | + } |
| 621 | + return items, nil |
| 622 | +} |
| 623 | + |
| 624 | +const listUndismissedReviewsForGate = `-- name: ListUndismissedReviewsForGate :many |
| 625 | +SELECT id, pr_issue_id, author_user_id, state, submitted_at |
| 626 | +FROM pr_reviews |
| 627 | +WHERE pr_issue_id = $1 |
| 628 | + AND dismissed_at IS NULL |
| 629 | +ORDER BY author_user_id, submitted_at |
| 630 | +` |
| 631 | + |
| 632 | +type ListUndismissedReviewsForGateRow struct { |
| 633 | + ID int64 |
| 634 | + PrIssueID int64 |
| 635 | + AuthorUserID pgtype.Int8 |
| 636 | + State PrReviewState |
| 637 | + SubmittedAt pgtype.Timestamptz |
| 638 | +} |
| 639 | + |
| 640 | +// Used by the merge gate to compute "latest review per author" semantics |
| 641 | +// in Go. Ordered author + submitted_at so the caller can pick the last |
| 642 | +// per author cheaply. |
| 643 | +func (q *Queries) ListUndismissedReviewsForGate(ctx context.Context, db DBTX, prIssueID int64) ([]ListUndismissedReviewsForGateRow, error) { |
| 644 | + rows, err := db.Query(ctx, listUndismissedReviewsForGate, prIssueID) |
| 645 | + if err != nil { |
| 646 | + return nil, err |
| 647 | + } |
| 648 | + defer rows.Close() |
| 649 | + items := []ListUndismissedReviewsForGateRow{} |
| 650 | + for rows.Next() { |
| 651 | + var i ListUndismissedReviewsForGateRow |
| 652 | + if err := rows.Scan( |
| 653 | + &i.ID, |
| 654 | + &i.PrIssueID, |
| 655 | + &i.AuthorUserID, |
| 656 | + &i.State, |
| 657 | + &i.SubmittedAt, |
| 658 | + ); err != nil { |
| 659 | + return nil, err |
| 660 | + } |
| 661 | + items = append(items, i) |
| 662 | + } |
| 663 | + if err := rows.Err(); err != nil { |
| 664 | + return nil, err |
| 665 | + } |
| 666 | + return items, nil |
| 667 | +} |
| 668 | + |
| 669 | +const satisfyPRReviewRequest = `-- name: SatisfyPRReviewRequest :exec |
| 670 | +UPDATE pr_review_requests |
| 671 | +SET satisfied_by_review_id = $2 |
| 672 | +WHERE pr_issue_id = $1 |
| 673 | + AND requested_user_id = $3 |
| 674 | + AND dismissed_at IS NULL |
| 675 | + AND satisfied_by_review_id IS NULL |
| 676 | +` |
| 677 | + |
| 678 | +type SatisfyPRReviewRequestParams struct { |
| 679 | + PrIssueID int64 |
| 680 | + SatisfiedByReviewID pgtype.Int8 |
| 681 | + RequestedUserID pgtype.Int8 |
| 682 | +} |
| 683 | + |
| 684 | +func (q *Queries) SatisfyPRReviewRequest(ctx context.Context, db DBTX, arg SatisfyPRReviewRequestParams) error { |
| 685 | + _, err := db.Exec(ctx, satisfyPRReviewRequest, arg.PrIssueID, arg.SatisfiedByReviewID, arg.RequestedUserID) |
| 686 | + return err |
| 687 | +} |
| 688 | + |
| 689 | +const setPRReviewCommentCurrentPosition = `-- name: SetPRReviewCommentCurrentPosition :exec |
| 690 | +UPDATE pr_review_comments |
| 691 | +SET current_position = $2::int, |
| 692 | + updated_at = now() |
| 693 | +WHERE id = $1 |
| 694 | +` |
| 695 | + |
| 696 | +type SetPRReviewCommentCurrentPositionParams struct { |
| 697 | + ID int64 |
| 698 | + CurrentPosition pgtype.Int4 |
| 699 | +} |
| 700 | + |
| 701 | +// Position-mapping update emitted by pulls.Synchronize. NULL means |
| 702 | +// the comment has gone outdated. |
| 703 | +func (q *Queries) SetPRReviewCommentCurrentPosition(ctx context.Context, db DBTX, arg SetPRReviewCommentCurrentPositionParams) error { |
| 704 | + _, err := db.Exec(ctx, setPRReviewCommentCurrentPosition, arg.ID, arg.CurrentPosition) |
| 705 | + return err |
| 706 | +} |
| 707 | + |
| 708 | +const setPRReviewCommentResolved = `-- name: SetPRReviewCommentResolved :exec |
| 709 | +UPDATE pr_review_comments |
| 710 | +SET resolved_at = $2::timestamptz, |
| 711 | + resolved_by_user_id = $3::bigint, |
| 712 | + updated_at = now() |
| 713 | +WHERE id = $1 |
| 714 | +` |
| 715 | + |
| 716 | +type SetPRReviewCommentResolvedParams struct { |
| 717 | + ID int64 |
| 718 | + ResolvedAt pgtype.Timestamptz |
| 719 | + ResolvedByUserID pgtype.Int8 |
| 720 | +} |
| 721 | + |
| 722 | +func (q *Queries) SetPRReviewCommentResolved(ctx context.Context, db DBTX, arg SetPRReviewCommentResolvedParams) error { |
| 723 | + _, err := db.Exec(ctx, setPRReviewCommentResolved, arg.ID, arg.ResolvedAt, arg.ResolvedByUserID) |
| 724 | + return err |
| 725 | +} |
| 726 | + |
| 727 | +const updatePRReviewCommentBody = `-- name: UpdatePRReviewCommentBody :exec |
| 728 | +UPDATE pr_review_comments |
| 729 | +SET body = $2, body_html_cached = $3::text, |
| 730 | + edited_at = now(), updated_at = now() |
| 731 | +WHERE id = $1 |
| 732 | +` |
| 733 | + |
| 734 | +type UpdatePRReviewCommentBodyParams struct { |
| 735 | + ID int64 |
| 736 | + Body string |
| 737 | + BodyHtmlCached pgtype.Text |
| 738 | +} |
| 739 | + |
| 740 | +func (q *Queries) UpdatePRReviewCommentBody(ctx context.Context, db DBTX, arg UpdatePRReviewCommentBodyParams) error { |
| 741 | + _, err := db.Exec(ctx, updatePRReviewCommentBody, arg.ID, arg.Body, arg.BodyHtmlCached) |
| 742 | + return err |
| 743 | +} |