| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: issues.sql |
| 5 | |
| 6 | package issuesdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const addIssueLabel = `-- name: AddIssueLabel :exec |
| 15 | |
| 16 | INSERT INTO issue_labels (issue_id, label_id, applied_by_user_id) |
| 17 | VALUES ($1, $2, $3::bigint) |
| 18 | ON CONFLICT (issue_id, label_id) DO NOTHING |
| 19 | ` |
| 20 | |
| 21 | type AddIssueLabelParams struct { |
| 22 | IssueID int64 |
| 23 | LabelID int64 |
| 24 | AppliedByUserID pgtype.Int8 |
| 25 | } |
| 26 | |
| 27 | // ─── issue ↔ label ─────────────────────────────────────────────────── |
| 28 | func (q *Queries) AddIssueLabel(ctx context.Context, db DBTX, arg AddIssueLabelParams) error { |
| 29 | _, err := db.Exec(ctx, addIssueLabel, arg.IssueID, arg.LabelID, arg.AppliedByUserID) |
| 30 | return err |
| 31 | } |
| 32 | |
| 33 | const allocateIssueNumber = `-- name: AllocateIssueNumber :one |
| 34 | UPDATE repo_issue_counter |
| 35 | SET next_number = next_number + 1 |
| 36 | WHERE repo_id = $1 |
| 37 | RETURNING (next_number - 1)::bigint AS allocated |
| 38 | ` |
| 39 | |
| 40 | // UPDATE … RETURNING is concurrency-safe: each row update is |
| 41 | // serialized by the row lock; concurrent transactions see different |
| 42 | // values. The caller wraps this in the same tx as the issue insert. |
| 43 | func (q *Queries) AllocateIssueNumber(ctx context.Context, db DBTX, repoID int64) (int64, error) { |
| 44 | row := db.QueryRow(ctx, allocateIssueNumber, repoID) |
| 45 | var allocated int64 |
| 46 | err := row.Scan(&allocated) |
| 47 | return allocated, err |
| 48 | } |
| 49 | |
| 50 | const assignUserToIssue = `-- name: AssignUserToIssue :exec |
| 51 | |
| 52 | INSERT INTO issue_assignees (issue_id, user_id, assigned_by_user_id) |
| 53 | VALUES ($1, $2, $3::bigint) |
| 54 | ON CONFLICT (issue_id, user_id) DO NOTHING |
| 55 | ` |
| 56 | |
| 57 | type AssignUserToIssueParams struct { |
| 58 | IssueID int64 |
| 59 | UserID int64 |
| 60 | AssignedByUserID pgtype.Int8 |
| 61 | } |
| 62 | |
| 63 | // ─── assignees ─────────────────────────────────────────────────────── |
| 64 | func (q *Queries) AssignUserToIssue(ctx context.Context, db DBTX, arg AssignUserToIssueParams) error { |
| 65 | _, err := db.Exec(ctx, assignUserToIssue, arg.IssueID, arg.UserID, arg.AssignedByUserID) |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | const countIssues = `-- name: CountIssues :one |
| 70 | SELECT count(*)::bigint FROM issues |
| 71 | WHERE repo_id = $1 |
| 72 | AND ($2::text IS NULL OR state::text = $2::text) |
| 73 | AND kind = COALESCE($3::issue_kind, 'issue') |
| 74 | ` |
| 75 | |
| 76 | type CountIssuesParams struct { |
| 77 | RepoID int64 |
| 78 | StateFilter pgtype.Text |
| 79 | Kind NullIssueKind |
| 80 | } |
| 81 | |
| 82 | func (q *Queries) CountIssues(ctx context.Context, db DBTX, arg CountIssuesParams) (int64, error) { |
| 83 | row := db.QueryRow(ctx, countIssues, arg.RepoID, arg.StateFilter, arg.Kind) |
| 84 | var column_1 int64 |
| 85 | err := row.Scan(&column_1) |
| 86 | return column_1, err |
| 87 | } |
| 88 | |
| 89 | const createIssue = `-- name: CreateIssue :one |
| 90 | |
| 91 | INSERT INTO issues ( |
| 92 | repo_id, number, kind, title, body, author_user_id |
| 93 | ) VALUES ( |
| 94 | $1, $2, $3, $4, $5, $6::bigint |
| 95 | ) |
| 96 | RETURNING id, repo_id, number, kind, title, body, body_html_cached, md_pipeline_version, author_user_id, state, state_reason, locked, lock_reason, milestone_id, created_at, updated_at, edited_at, closed_at, closed_by_user_id |
| 97 | ` |
| 98 | |
| 99 | type CreateIssueParams struct { |
| 100 | RepoID int64 |
| 101 | Number int64 |
| 102 | Kind IssueKind |
| 103 | Title string |
| 104 | Body string |
| 105 | AuthorUserID pgtype.Int8 |
| 106 | } |
| 107 | |
| 108 | // ─── issues ────────────────────────────────────────────────────────── |
| 109 | func (q *Queries) CreateIssue(ctx context.Context, db DBTX, arg CreateIssueParams) (Issue, error) { |
| 110 | row := db.QueryRow(ctx, createIssue, |
| 111 | arg.RepoID, |
| 112 | arg.Number, |
| 113 | arg.Kind, |
| 114 | arg.Title, |
| 115 | arg.Body, |
| 116 | arg.AuthorUserID, |
| 117 | ) |
| 118 | var i Issue |
| 119 | err := row.Scan( |
| 120 | &i.ID, |
| 121 | &i.RepoID, |
| 122 | &i.Number, |
| 123 | &i.Kind, |
| 124 | &i.Title, |
| 125 | &i.Body, |
| 126 | &i.BodyHtmlCached, |
| 127 | &i.MdPipelineVersion, |
| 128 | &i.AuthorUserID, |
| 129 | &i.State, |
| 130 | &i.StateReason, |
| 131 | &i.Locked, |
| 132 | &i.LockReason, |
| 133 | &i.MilestoneID, |
| 134 | &i.CreatedAt, |
| 135 | &i.UpdatedAt, |
| 136 | &i.EditedAt, |
| 137 | &i.ClosedAt, |
| 138 | &i.ClosedByUserID, |
| 139 | ) |
| 140 | return i, err |
| 141 | } |
| 142 | |
| 143 | const createIssueComment = `-- name: CreateIssueComment :one |
| 144 | |
| 145 | INSERT INTO issue_comments (issue_id, author_user_id, body, body_html_cached) |
| 146 | VALUES ($1, $4::bigint, $2, $3) |
| 147 | RETURNING id, issue_id, author_user_id, body, body_html_cached, md_pipeline_version, created_at, updated_at, edited_at |
| 148 | ` |
| 149 | |
| 150 | type CreateIssueCommentParams struct { |
| 151 | IssueID int64 |
| 152 | Body string |
| 153 | BodyHtmlCached pgtype.Text |
| 154 | AuthorUserID pgtype.Int8 |
| 155 | } |
| 156 | |
| 157 | // ─── comments ──────────────────────────────────────────────────────── |
| 158 | func (q *Queries) CreateIssueComment(ctx context.Context, db DBTX, arg CreateIssueCommentParams) (IssueComment, error) { |
| 159 | row := db.QueryRow(ctx, createIssueComment, |
| 160 | arg.IssueID, |
| 161 | arg.Body, |
| 162 | arg.BodyHtmlCached, |
| 163 | arg.AuthorUserID, |
| 164 | ) |
| 165 | var i IssueComment |
| 166 | err := row.Scan( |
| 167 | &i.ID, |
| 168 | &i.IssueID, |
| 169 | &i.AuthorUserID, |
| 170 | &i.Body, |
| 171 | &i.BodyHtmlCached, |
| 172 | &i.MdPipelineVersion, |
| 173 | &i.CreatedAt, |
| 174 | &i.UpdatedAt, |
| 175 | &i.EditedAt, |
| 176 | ) |
| 177 | return i, err |
| 178 | } |
| 179 | |
| 180 | const createLabel = `-- name: CreateLabel :one |
| 181 | |
| 182 | INSERT INTO labels (repo_id, name, color, description) |
| 183 | VALUES ($1, $2, $3, $4) |
| 184 | RETURNING id, repo_id, name, color, description, created_at |
| 185 | ` |
| 186 | |
| 187 | type CreateLabelParams struct { |
| 188 | RepoID int64 |
| 189 | Name string |
| 190 | Color string |
| 191 | Description string |
| 192 | } |
| 193 | |
| 194 | // ─── labels ────────────────────────────────────────────────────────── |
| 195 | func (q *Queries) CreateLabel(ctx context.Context, db DBTX, arg CreateLabelParams) (Label, error) { |
| 196 | row := db.QueryRow(ctx, createLabel, |
| 197 | arg.RepoID, |
| 198 | arg.Name, |
| 199 | arg.Color, |
| 200 | arg.Description, |
| 201 | ) |
| 202 | var i Label |
| 203 | err := row.Scan( |
| 204 | &i.ID, |
| 205 | &i.RepoID, |
| 206 | &i.Name, |
| 207 | &i.Color, |
| 208 | &i.Description, |
| 209 | &i.CreatedAt, |
| 210 | ) |
| 211 | return i, err |
| 212 | } |
| 213 | |
| 214 | const createMilestone = `-- name: CreateMilestone :one |
| 215 | |
| 216 | INSERT INTO milestones (repo_id, title, description, due_on) |
| 217 | VALUES ($1, $2, $3, $4::timestamptz) |
| 218 | RETURNING id, repo_id, title, description, state, due_on, created_at, closed_at |
| 219 | ` |
| 220 | |
| 221 | type CreateMilestoneParams struct { |
| 222 | RepoID int64 |
| 223 | Title string |
| 224 | Description string |
| 225 | DueOn pgtype.Timestamptz |
| 226 | } |
| 227 | |
| 228 | // ─── milestones ────────────────────────────────────────────────────── |
| 229 | func (q *Queries) CreateMilestone(ctx context.Context, db DBTX, arg CreateMilestoneParams) (Milestone, error) { |
| 230 | row := db.QueryRow(ctx, createMilestone, |
| 231 | arg.RepoID, |
| 232 | arg.Title, |
| 233 | arg.Description, |
| 234 | arg.DueOn, |
| 235 | ) |
| 236 | var i Milestone |
| 237 | err := row.Scan( |
| 238 | &i.ID, |
| 239 | &i.RepoID, |
| 240 | &i.Title, |
| 241 | &i.Description, |
| 242 | &i.State, |
| 243 | &i.DueOn, |
| 244 | &i.CreatedAt, |
| 245 | &i.ClosedAt, |
| 246 | ) |
| 247 | return i, err |
| 248 | } |
| 249 | |
| 250 | const deleteIssueComment = `-- name: DeleteIssueComment :exec |
| 251 | DELETE FROM issue_comments WHERE id = $1 |
| 252 | ` |
| 253 | |
| 254 | func (q *Queries) DeleteIssueComment(ctx context.Context, db DBTX, id int64) error { |
| 255 | _, err := db.Exec(ctx, deleteIssueComment, id) |
| 256 | return err |
| 257 | } |
| 258 | |
| 259 | const deleteLabel = `-- name: DeleteLabel :exec |
| 260 | DELETE FROM labels WHERE id = $1 |
| 261 | ` |
| 262 | |
| 263 | func (q *Queries) DeleteLabel(ctx context.Context, db DBTX, id int64) error { |
| 264 | _, err := db.Exec(ctx, deleteLabel, id) |
| 265 | return err |
| 266 | } |
| 267 | |
| 268 | const deleteMilestone = `-- name: DeleteMilestone :exec |
| 269 | DELETE FROM milestones WHERE id = $1 |
| 270 | ` |
| 271 | |
| 272 | func (q *Queries) DeleteMilestone(ctx context.Context, db DBTX, id int64) error { |
| 273 | _, err := db.Exec(ctx, deleteMilestone, id) |
| 274 | return err |
| 275 | } |
| 276 | |
| 277 | const ensureRepoIssueCounter = `-- name: EnsureRepoIssueCounter :exec |
| 278 | |
| 279 | |
| 280 | INSERT INTO repo_issue_counter (repo_id, next_number) |
| 281 | VALUES ($1, 1) |
| 282 | ON CONFLICT (repo_id) DO NOTHING |
| 283 | ` |
| 284 | |
| 285 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 286 | // ─── per-repo numbering ─────────────────────────────────────────────── |
| 287 | // Lazy-initialize the counter row. Idempotent — invoked from repo |
| 288 | // create AND from the first issue insert (defensive in case someone |
| 289 | // migrates an old repo that predates S21). |
| 290 | func (q *Queries) EnsureRepoIssueCounter(ctx context.Context, db DBTX, repoID int64) error { |
| 291 | _, err := db.Exec(ctx, ensureRepoIssueCounter, repoID) |
| 292 | return err |
| 293 | } |
| 294 | |
| 295 | const getIssueByID = `-- name: GetIssueByID :one |
| 296 | SELECT id, repo_id, number, kind, title, body, body_html_cached, md_pipeline_version, author_user_id, state, state_reason, locked, lock_reason, milestone_id, created_at, updated_at, edited_at, closed_at, closed_by_user_id FROM issues WHERE id = $1 |
| 297 | ` |
| 298 | |
| 299 | func (q *Queries) GetIssueByID(ctx context.Context, db DBTX, id int64) (Issue, error) { |
| 300 | row := db.QueryRow(ctx, getIssueByID, id) |
| 301 | var i Issue |
| 302 | err := row.Scan( |
| 303 | &i.ID, |
| 304 | &i.RepoID, |
| 305 | &i.Number, |
| 306 | &i.Kind, |
| 307 | &i.Title, |
| 308 | &i.Body, |
| 309 | &i.BodyHtmlCached, |
| 310 | &i.MdPipelineVersion, |
| 311 | &i.AuthorUserID, |
| 312 | &i.State, |
| 313 | &i.StateReason, |
| 314 | &i.Locked, |
| 315 | &i.LockReason, |
| 316 | &i.MilestoneID, |
| 317 | &i.CreatedAt, |
| 318 | &i.UpdatedAt, |
| 319 | &i.EditedAt, |
| 320 | &i.ClosedAt, |
| 321 | &i.ClosedByUserID, |
| 322 | ) |
| 323 | return i, err |
| 324 | } |
| 325 | |
| 326 | const getIssueByNumber = `-- name: GetIssueByNumber :one |
| 327 | SELECT id, repo_id, number, kind, title, body, body_html_cached, md_pipeline_version, author_user_id, state, state_reason, locked, lock_reason, milestone_id, created_at, updated_at, edited_at, closed_at, closed_by_user_id FROM issues |
| 328 | WHERE repo_id = $1 AND number = $2 |
| 329 | ` |
| 330 | |
| 331 | type GetIssueByNumberParams struct { |
| 332 | RepoID int64 |
| 333 | Number int64 |
| 334 | } |
| 335 | |
| 336 | func (q *Queries) GetIssueByNumber(ctx context.Context, db DBTX, arg GetIssueByNumberParams) (Issue, error) { |
| 337 | row := db.QueryRow(ctx, getIssueByNumber, arg.RepoID, arg.Number) |
| 338 | var i Issue |
| 339 | err := row.Scan( |
| 340 | &i.ID, |
| 341 | &i.RepoID, |
| 342 | &i.Number, |
| 343 | &i.Kind, |
| 344 | &i.Title, |
| 345 | &i.Body, |
| 346 | &i.BodyHtmlCached, |
| 347 | &i.MdPipelineVersion, |
| 348 | &i.AuthorUserID, |
| 349 | &i.State, |
| 350 | &i.StateReason, |
| 351 | &i.Locked, |
| 352 | &i.LockReason, |
| 353 | &i.MilestoneID, |
| 354 | &i.CreatedAt, |
| 355 | &i.UpdatedAt, |
| 356 | &i.EditedAt, |
| 357 | &i.ClosedAt, |
| 358 | &i.ClosedByUserID, |
| 359 | ) |
| 360 | return i, err |
| 361 | } |
| 362 | |
| 363 | const getIssueComment = `-- name: GetIssueComment :one |
| 364 | SELECT id, issue_id, author_user_id, body, body_html_cached, md_pipeline_version, created_at, updated_at, edited_at FROM issue_comments WHERE id = $1 |
| 365 | ` |
| 366 | |
| 367 | func (q *Queries) GetIssueComment(ctx context.Context, db DBTX, id int64) (IssueComment, error) { |
| 368 | row := db.QueryRow(ctx, getIssueComment, id) |
| 369 | var i IssueComment |
| 370 | err := row.Scan( |
| 371 | &i.ID, |
| 372 | &i.IssueID, |
| 373 | &i.AuthorUserID, |
| 374 | &i.Body, |
| 375 | &i.BodyHtmlCached, |
| 376 | &i.MdPipelineVersion, |
| 377 | &i.CreatedAt, |
| 378 | &i.UpdatedAt, |
| 379 | &i.EditedAt, |
| 380 | ) |
| 381 | return i, err |
| 382 | } |
| 383 | |
| 384 | const getLabelByName = `-- name: GetLabelByName :one |
| 385 | SELECT id, repo_id, name, color, description, created_at FROM labels WHERE repo_id = $1 AND name = $2 |
| 386 | ` |
| 387 | |
| 388 | type GetLabelByNameParams struct { |
| 389 | RepoID int64 |
| 390 | Name string |
| 391 | } |
| 392 | |
| 393 | func (q *Queries) GetLabelByName(ctx context.Context, db DBTX, arg GetLabelByNameParams) (Label, error) { |
| 394 | row := db.QueryRow(ctx, getLabelByName, arg.RepoID, arg.Name) |
| 395 | var i Label |
| 396 | err := row.Scan( |
| 397 | &i.ID, |
| 398 | &i.RepoID, |
| 399 | &i.Name, |
| 400 | &i.Color, |
| 401 | &i.Description, |
| 402 | &i.CreatedAt, |
| 403 | ) |
| 404 | return i, err |
| 405 | } |
| 406 | |
| 407 | const getMilestone = `-- name: GetMilestone :one |
| 408 | SELECT id, repo_id, title, description, state, due_on, created_at, closed_at FROM milestones WHERE id = $1 |
| 409 | ` |
| 410 | |
| 411 | func (q *Queries) GetMilestone(ctx context.Context, db DBTX, id int64) (Milestone, error) { |
| 412 | row := db.QueryRow(ctx, getMilestone, id) |
| 413 | var i Milestone |
| 414 | err := row.Scan( |
| 415 | &i.ID, |
| 416 | &i.RepoID, |
| 417 | &i.Title, |
| 418 | &i.Description, |
| 419 | &i.State, |
| 420 | &i.DueOn, |
| 421 | &i.CreatedAt, |
| 422 | &i.ClosedAt, |
| 423 | ) |
| 424 | return i, err |
| 425 | } |
| 426 | |
| 427 | const insertIssueEvent = `-- name: InsertIssueEvent :one |
| 428 | |
| 429 | INSERT INTO issue_events (issue_id, actor_user_id, kind, meta, ref_target_id) |
| 430 | VALUES ($1, $4::bigint, $2, $3, $5::bigint) |
| 431 | RETURNING id, issue_id, actor_user_id, kind, meta, ref_target_id, created_at |
| 432 | ` |
| 433 | |
| 434 | type InsertIssueEventParams struct { |
| 435 | IssueID int64 |
| 436 | Kind string |
| 437 | Meta []byte |
| 438 | ActorUserID pgtype.Int8 |
| 439 | RefTargetID pgtype.Int8 |
| 440 | } |
| 441 | |
| 442 | // ─── events + references ───────────────────────────────────────────── |
| 443 | func (q *Queries) InsertIssueEvent(ctx context.Context, db DBTX, arg InsertIssueEventParams) (IssueEvent, error) { |
| 444 | row := db.QueryRow(ctx, insertIssueEvent, |
| 445 | arg.IssueID, |
| 446 | arg.Kind, |
| 447 | arg.Meta, |
| 448 | arg.ActorUserID, |
| 449 | arg.RefTargetID, |
| 450 | ) |
| 451 | var i IssueEvent |
| 452 | err := row.Scan( |
| 453 | &i.ID, |
| 454 | &i.IssueID, |
| 455 | &i.ActorUserID, |
| 456 | &i.Kind, |
| 457 | &i.Meta, |
| 458 | &i.RefTargetID, |
| 459 | &i.CreatedAt, |
| 460 | ) |
| 461 | return i, err |
| 462 | } |
| 463 | |
| 464 | const insertIssueReference = `-- name: InsertIssueReference :exec |
| 465 | INSERT INTO issue_references ( |
| 466 | source_issue_id, target_issue_id, source_kind, source_object_id |
| 467 | ) VALUES ( |
| 468 | $3::bigint, $1, $2, $4::bigint |
| 469 | ) |
| 470 | ` |
| 471 | |
| 472 | type InsertIssueReferenceParams struct { |
| 473 | TargetIssueID int64 |
| 474 | SourceKind IssueRefSource |
| 475 | SourceIssueID pgtype.Int8 |
| 476 | SourceObjectID pgtype.Int8 |
| 477 | } |
| 478 | |
| 479 | func (q *Queries) InsertIssueReference(ctx context.Context, db DBTX, arg InsertIssueReferenceParams) error { |
| 480 | _, err := db.Exec(ctx, insertIssueReference, |
| 481 | arg.TargetIssueID, |
| 482 | arg.SourceKind, |
| 483 | arg.SourceIssueID, |
| 484 | arg.SourceObjectID, |
| 485 | ) |
| 486 | return err |
| 487 | } |
| 488 | |
| 489 | const listIssueAssignees = `-- name: ListIssueAssignees :many |
| 490 | SELECT a.issue_id, a.user_id, a.assigned_at, u.username, u.display_name |
| 491 | FROM issue_assignees a |
| 492 | JOIN users u ON u.id = a.user_id |
| 493 | WHERE a.issue_id = $1 |
| 494 | ORDER BY a.assigned_at |
| 495 | ` |
| 496 | |
| 497 | type ListIssueAssigneesRow struct { |
| 498 | IssueID int64 |
| 499 | UserID int64 |
| 500 | AssignedAt pgtype.Timestamptz |
| 501 | Username string |
| 502 | DisplayName string |
| 503 | } |
| 504 | |
| 505 | func (q *Queries) ListIssueAssignees(ctx context.Context, db DBTX, issueID int64) ([]ListIssueAssigneesRow, error) { |
| 506 | rows, err := db.Query(ctx, listIssueAssignees, issueID) |
| 507 | if err != nil { |
| 508 | return nil, err |
| 509 | } |
| 510 | defer rows.Close() |
| 511 | items := []ListIssueAssigneesRow{} |
| 512 | for rows.Next() { |
| 513 | var i ListIssueAssigneesRow |
| 514 | if err := rows.Scan( |
| 515 | &i.IssueID, |
| 516 | &i.UserID, |
| 517 | &i.AssignedAt, |
| 518 | &i.Username, |
| 519 | &i.DisplayName, |
| 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 listIssueComments = `-- name: ListIssueComments :many |
| 532 | SELECT id, issue_id, author_user_id, body, body_html_cached, md_pipeline_version, created_at, updated_at, edited_at FROM issue_comments |
| 533 | WHERE issue_id = $1 |
| 534 | ORDER BY created_at ASC |
| 535 | ` |
| 536 | |
| 537 | func (q *Queries) ListIssueComments(ctx context.Context, db DBTX, issueID int64) ([]IssueComment, error) { |
| 538 | rows, err := db.Query(ctx, listIssueComments, issueID) |
| 539 | if err != nil { |
| 540 | return nil, err |
| 541 | } |
| 542 | defer rows.Close() |
| 543 | items := []IssueComment{} |
| 544 | for rows.Next() { |
| 545 | var i IssueComment |
| 546 | if err := rows.Scan( |
| 547 | &i.ID, |
| 548 | &i.IssueID, |
| 549 | &i.AuthorUserID, |
| 550 | &i.Body, |
| 551 | &i.BodyHtmlCached, |
| 552 | &i.MdPipelineVersion, |
| 553 | &i.CreatedAt, |
| 554 | &i.UpdatedAt, |
| 555 | &i.EditedAt, |
| 556 | ); err != nil { |
| 557 | return nil, err |
| 558 | } |
| 559 | items = append(items, i) |
| 560 | } |
| 561 | if err := rows.Err(); err != nil { |
| 562 | return nil, err |
| 563 | } |
| 564 | return items, nil |
| 565 | } |
| 566 | |
| 567 | const listIssueEvents = `-- name: ListIssueEvents :many |
| 568 | SELECT id, issue_id, actor_user_id, kind, meta, ref_target_id, created_at FROM issue_events |
| 569 | WHERE issue_id = $1 |
| 570 | ORDER BY created_at ASC |
| 571 | ` |
| 572 | |
| 573 | func (q *Queries) ListIssueEvents(ctx context.Context, db DBTX, issueID int64) ([]IssueEvent, error) { |
| 574 | rows, err := db.Query(ctx, listIssueEvents, issueID) |
| 575 | if err != nil { |
| 576 | return nil, err |
| 577 | } |
| 578 | defer rows.Close() |
| 579 | items := []IssueEvent{} |
| 580 | for rows.Next() { |
| 581 | var i IssueEvent |
| 582 | if err := rows.Scan( |
| 583 | &i.ID, |
| 584 | &i.IssueID, |
| 585 | &i.ActorUserID, |
| 586 | &i.Kind, |
| 587 | &i.Meta, |
| 588 | &i.RefTargetID, |
| 589 | &i.CreatedAt, |
| 590 | ); err != nil { |
| 591 | return nil, err |
| 592 | } |
| 593 | items = append(items, i) |
| 594 | } |
| 595 | if err := rows.Err(); err != nil { |
| 596 | return nil, err |
| 597 | } |
| 598 | return items, nil |
| 599 | } |
| 600 | |
| 601 | const listIssues = `-- name: ListIssues :many |
| 602 | SELECT id, repo_id, number, kind, title, body, body_html_cached, md_pipeline_version, author_user_id, state, state_reason, locked, lock_reason, milestone_id, created_at, updated_at, edited_at, closed_at, closed_by_user_id FROM issues |
| 603 | WHERE repo_id = $1 |
| 604 | AND ($4::text IS NULL OR state::text = $4::text) |
| 605 | AND kind = COALESCE($5::issue_kind, 'issue') |
| 606 | ORDER BY updated_at DESC |
| 607 | LIMIT $2 OFFSET $3 |
| 608 | ` |
| 609 | |
| 610 | type ListIssuesParams struct { |
| 611 | RepoID int64 |
| 612 | Limit int32 |
| 613 | Offset int32 |
| 614 | StateFilter pgtype.Text |
| 615 | Kind NullIssueKind |
| 616 | } |
| 617 | |
| 618 | // Filterable list. Caller passes a state filter (open/closed/all |
| 619 | // where 'all' is encoded as NULL); label/assignee/author/milestone |
| 620 | // filtering happens after this query in Go for v1 — see the |
| 621 | // internal/issues/list.go composer. Per-page hardcoded at 25 in the |
| 622 | // handler; offset is the (page-1)*25. |
| 623 | func (q *Queries) ListIssues(ctx context.Context, db DBTX, arg ListIssuesParams) ([]Issue, error) { |
| 624 | rows, err := db.Query(ctx, listIssues, |
| 625 | arg.RepoID, |
| 626 | arg.Limit, |
| 627 | arg.Offset, |
| 628 | arg.StateFilter, |
| 629 | arg.Kind, |
| 630 | ) |
| 631 | if err != nil { |
| 632 | return nil, err |
| 633 | } |
| 634 | defer rows.Close() |
| 635 | items := []Issue{} |
| 636 | for rows.Next() { |
| 637 | var i Issue |
| 638 | if err := rows.Scan( |
| 639 | &i.ID, |
| 640 | &i.RepoID, |
| 641 | &i.Number, |
| 642 | &i.Kind, |
| 643 | &i.Title, |
| 644 | &i.Body, |
| 645 | &i.BodyHtmlCached, |
| 646 | &i.MdPipelineVersion, |
| 647 | &i.AuthorUserID, |
| 648 | &i.State, |
| 649 | &i.StateReason, |
| 650 | &i.Locked, |
| 651 | &i.LockReason, |
| 652 | &i.MilestoneID, |
| 653 | &i.CreatedAt, |
| 654 | &i.UpdatedAt, |
| 655 | &i.EditedAt, |
| 656 | &i.ClosedAt, |
| 657 | &i.ClosedByUserID, |
| 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 listLabels = `-- name: ListLabels :many |
| 670 | SELECT id, repo_id, name, color, description, created_at FROM labels WHERE repo_id = $1 ORDER BY name |
| 671 | ` |
| 672 | |
| 673 | func (q *Queries) ListLabels(ctx context.Context, db DBTX, repoID int64) ([]Label, error) { |
| 674 | rows, err := db.Query(ctx, listLabels, repoID) |
| 675 | if err != nil { |
| 676 | return nil, err |
| 677 | } |
| 678 | defer rows.Close() |
| 679 | items := []Label{} |
| 680 | for rows.Next() { |
| 681 | var i Label |
| 682 | if err := rows.Scan( |
| 683 | &i.ID, |
| 684 | &i.RepoID, |
| 685 | &i.Name, |
| 686 | &i.Color, |
| 687 | &i.Description, |
| 688 | &i.CreatedAt, |
| 689 | ); err != nil { |
| 690 | return nil, err |
| 691 | } |
| 692 | items = append(items, i) |
| 693 | } |
| 694 | if err := rows.Err(); err != nil { |
| 695 | return nil, err |
| 696 | } |
| 697 | return items, nil |
| 698 | } |
| 699 | |
| 700 | const listLabelsOnIssue = `-- name: ListLabelsOnIssue :many |
| 701 | SELECT l.id, l.repo_id, l.name, l.color, l.description, l.created_at |
| 702 | FROM issue_labels il |
| 703 | JOIN labels l ON l.id = il.label_id |
| 704 | WHERE il.issue_id = $1 |
| 705 | ORDER BY l.name |
| 706 | ` |
| 707 | |
| 708 | func (q *Queries) ListLabelsOnIssue(ctx context.Context, db DBTX, issueID int64) ([]Label, error) { |
| 709 | rows, err := db.Query(ctx, listLabelsOnIssue, issueID) |
| 710 | if err != nil { |
| 711 | return nil, err |
| 712 | } |
| 713 | defer rows.Close() |
| 714 | items := []Label{} |
| 715 | for rows.Next() { |
| 716 | var i Label |
| 717 | if err := rows.Scan( |
| 718 | &i.ID, |
| 719 | &i.RepoID, |
| 720 | &i.Name, |
| 721 | &i.Color, |
| 722 | &i.Description, |
| 723 | &i.CreatedAt, |
| 724 | ); err != nil { |
| 725 | return nil, err |
| 726 | } |
| 727 | items = append(items, i) |
| 728 | } |
| 729 | if err := rows.Err(); err != nil { |
| 730 | return nil, err |
| 731 | } |
| 732 | return items, nil |
| 733 | } |
| 734 | |
| 735 | const listMilestones = `-- name: ListMilestones :many |
| 736 | SELECT id, repo_id, title, description, state, due_on, created_at, closed_at FROM milestones WHERE repo_id = $1 ORDER BY state, due_on NULLS LAST, title |
| 737 | ` |
| 738 | |
| 739 | func (q *Queries) ListMilestones(ctx context.Context, db DBTX, repoID int64) ([]Milestone, error) { |
| 740 | rows, err := db.Query(ctx, listMilestones, repoID) |
| 741 | if err != nil { |
| 742 | return nil, err |
| 743 | } |
| 744 | defer rows.Close() |
| 745 | items := []Milestone{} |
| 746 | for rows.Next() { |
| 747 | var i Milestone |
| 748 | if err := rows.Scan( |
| 749 | &i.ID, |
| 750 | &i.RepoID, |
| 751 | &i.Title, |
| 752 | &i.Description, |
| 753 | &i.State, |
| 754 | &i.DueOn, |
| 755 | &i.CreatedAt, |
| 756 | &i.ClosedAt, |
| 757 | ); err != nil { |
| 758 | return nil, err |
| 759 | } |
| 760 | items = append(items, i) |
| 761 | } |
| 762 | if err := rows.Err(); err != nil { |
| 763 | return nil, err |
| 764 | } |
| 765 | return items, nil |
| 766 | } |
| 767 | |
| 768 | const milestoneIssueCounts = `-- name: MilestoneIssueCounts :one |
| 769 | SELECT |
| 770 | count(*) FILTER (WHERE state = 'open')::int AS open_count, |
| 771 | count(*) FILTER (WHERE state = 'closed')::int AS closed_count |
| 772 | FROM issues |
| 773 | WHERE milestone_id = $1 |
| 774 | ` |
| 775 | |
| 776 | type MilestoneIssueCountsRow struct { |
| 777 | OpenCount int32 |
| 778 | ClosedCount int32 |
| 779 | } |
| 780 | |
| 781 | // Open + closed counts for the milestone progress bar. |
| 782 | func (q *Queries) MilestoneIssueCounts(ctx context.Context, db DBTX, milestoneID pgtype.Int8) (MilestoneIssueCountsRow, error) { |
| 783 | row := db.QueryRow(ctx, milestoneIssueCounts, milestoneID) |
| 784 | var i MilestoneIssueCountsRow |
| 785 | err := row.Scan(&i.OpenCount, &i.ClosedCount) |
| 786 | return i, err |
| 787 | } |
| 788 | |
| 789 | const removeIssueLabel = `-- name: RemoveIssueLabel :exec |
| 790 | DELETE FROM issue_labels WHERE issue_id = $1 AND label_id = $2 |
| 791 | ` |
| 792 | |
| 793 | type RemoveIssueLabelParams struct { |
| 794 | IssueID int64 |
| 795 | LabelID int64 |
| 796 | } |
| 797 | |
| 798 | func (q *Queries) RemoveIssueLabel(ctx context.Context, db DBTX, arg RemoveIssueLabelParams) error { |
| 799 | _, err := db.Exec(ctx, removeIssueLabel, arg.IssueID, arg.LabelID) |
| 800 | return err |
| 801 | } |
| 802 | |
| 803 | const setIssueLock = `-- name: SetIssueLock :exec |
| 804 | UPDATE issues |
| 805 | SET locked = $2, lock_reason = $3::text, updated_at = now() |
| 806 | WHERE id = $1 |
| 807 | ` |
| 808 | |
| 809 | type SetIssueLockParams struct { |
| 810 | ID int64 |
| 811 | Locked bool |
| 812 | LockReason pgtype.Text |
| 813 | } |
| 814 | |
| 815 | func (q *Queries) SetIssueLock(ctx context.Context, db DBTX, arg SetIssueLockParams) error { |
| 816 | _, err := db.Exec(ctx, setIssueLock, arg.ID, arg.Locked, arg.LockReason) |
| 817 | return err |
| 818 | } |
| 819 | |
| 820 | const setIssueMilestone = `-- name: SetIssueMilestone :exec |
| 821 | UPDATE issues |
| 822 | SET milestone_id = $2::bigint, updated_at = now() |
| 823 | WHERE id = $1 |
| 824 | ` |
| 825 | |
| 826 | type SetIssueMilestoneParams struct { |
| 827 | ID int64 |
| 828 | MilestoneID pgtype.Int8 |
| 829 | } |
| 830 | |
| 831 | func (q *Queries) SetIssueMilestone(ctx context.Context, db DBTX, arg SetIssueMilestoneParams) error { |
| 832 | _, err := db.Exec(ctx, setIssueMilestone, arg.ID, arg.MilestoneID) |
| 833 | return err |
| 834 | } |
| 835 | |
| 836 | const setIssueState = `-- name: SetIssueState :exec |
| 837 | UPDATE issues |
| 838 | SET state = $2, |
| 839 | state_reason = $3::issue_state_reason, |
| 840 | closed_at = CASE WHEN $2::issue_state = 'closed' THEN now() ELSE NULL END, |
| 841 | closed_by_user_id = $4::bigint, |
| 842 | updated_at = now() |
| 843 | WHERE id = $1 |
| 844 | ` |
| 845 | |
| 846 | type SetIssueStateParams struct { |
| 847 | ID int64 |
| 848 | State IssueState |
| 849 | StateReason NullIssueStateReason |
| 850 | ClosedByUserID pgtype.Int8 |
| 851 | } |
| 852 | |
| 853 | func (q *Queries) SetIssueState(ctx context.Context, db DBTX, arg SetIssueStateParams) error { |
| 854 | _, err := db.Exec(ctx, setIssueState, |
| 855 | arg.ID, |
| 856 | arg.State, |
| 857 | arg.StateReason, |
| 858 | arg.ClosedByUserID, |
| 859 | ) |
| 860 | return err |
| 861 | } |
| 862 | |
| 863 | const setMilestoneState = `-- name: SetMilestoneState :exec |
| 864 | UPDATE milestones SET state = $2, closed_at = CASE WHEN $2::milestone_state = 'closed' THEN now() ELSE NULL END WHERE id = $1 |
| 865 | ` |
| 866 | |
| 867 | type SetMilestoneStateParams struct { |
| 868 | ID int64 |
| 869 | State MilestoneState |
| 870 | } |
| 871 | |
| 872 | func (q *Queries) SetMilestoneState(ctx context.Context, db DBTX, arg SetMilestoneStateParams) error { |
| 873 | _, err := db.Exec(ctx, setMilestoneState, arg.ID, arg.State) |
| 874 | return err |
| 875 | } |
| 876 | |
| 877 | const unassignUserFromIssue = `-- name: UnassignUserFromIssue :exec |
| 878 | DELETE FROM issue_assignees WHERE issue_id = $1 AND user_id = $2 |
| 879 | ` |
| 880 | |
| 881 | type UnassignUserFromIssueParams struct { |
| 882 | IssueID int64 |
| 883 | UserID int64 |
| 884 | } |
| 885 | |
| 886 | func (q *Queries) UnassignUserFromIssue(ctx context.Context, db DBTX, arg UnassignUserFromIssueParams) error { |
| 887 | _, err := db.Exec(ctx, unassignUserFromIssue, arg.IssueID, arg.UserID) |
| 888 | return err |
| 889 | } |
| 890 | |
| 891 | const updateIssueCommentBody = `-- name: UpdateIssueCommentBody :exec |
| 892 | UPDATE issue_comments |
| 893 | SET body = $2, body_html_cached = $3, edited_at = now(), updated_at = now() |
| 894 | WHERE id = $1 |
| 895 | ` |
| 896 | |
| 897 | type UpdateIssueCommentBodyParams struct { |
| 898 | ID int64 |
| 899 | Body string |
| 900 | BodyHtmlCached pgtype.Text |
| 901 | } |
| 902 | |
| 903 | func (q *Queries) UpdateIssueCommentBody(ctx context.Context, db DBTX, arg UpdateIssueCommentBodyParams) error { |
| 904 | _, err := db.Exec(ctx, updateIssueCommentBody, arg.ID, arg.Body, arg.BodyHtmlCached) |
| 905 | return err |
| 906 | } |
| 907 | |
| 908 | const updateIssueTitleBody = `-- name: UpdateIssueTitleBody :exec |
| 909 | UPDATE issues |
| 910 | SET title = $2, body = $3, body_html_cached = $4, edited_at = now(), updated_at = now() |
| 911 | WHERE id = $1 |
| 912 | ` |
| 913 | |
| 914 | type UpdateIssueTitleBodyParams struct { |
| 915 | ID int64 |
| 916 | Title string |
| 917 | Body string |
| 918 | BodyHtmlCached pgtype.Text |
| 919 | } |
| 920 | |
| 921 | func (q *Queries) UpdateIssueTitleBody(ctx context.Context, db DBTX, arg UpdateIssueTitleBodyParams) error { |
| 922 | _, err := db.Exec(ctx, updateIssueTitleBody, |
| 923 | arg.ID, |
| 924 | arg.Title, |
| 925 | arg.Body, |
| 926 | arg.BodyHtmlCached, |
| 927 | ) |
| 928 | return err |
| 929 | } |
| 930 | |
| 931 | const updateLabel = `-- name: UpdateLabel :exec |
| 932 | UPDATE labels |
| 933 | SET name = $2, color = $3, description = $4 |
| 934 | WHERE id = $1 |
| 935 | ` |
| 936 | |
| 937 | type UpdateLabelParams struct { |
| 938 | ID int64 |
| 939 | Name string |
| 940 | Color string |
| 941 | Description string |
| 942 | } |
| 943 | |
| 944 | func (q *Queries) UpdateLabel(ctx context.Context, db DBTX, arg UpdateLabelParams) error { |
| 945 | _, err := db.Exec(ctx, updateLabel, |
| 946 | arg.ID, |
| 947 | arg.Name, |
| 948 | arg.Color, |
| 949 | arg.Description, |
| 950 | ) |
| 951 | return err |
| 952 | } |
| 953 | |
| 954 | const updateMilestone = `-- name: UpdateMilestone :exec |
| 955 | UPDATE milestones SET title = $2, description = $3, due_on = $4::timestamptz WHERE id = $1 |
| 956 | ` |
| 957 | |
| 958 | type UpdateMilestoneParams struct { |
| 959 | ID int64 |
| 960 | Title string |
| 961 | Description string |
| 962 | DueOn pgtype.Timestamptz |
| 963 | } |
| 964 | |
| 965 | func (q *Queries) UpdateMilestone(ctx context.Context, db DBTX, arg UpdateMilestoneParams) error { |
| 966 | _, err := db.Exec(ctx, updateMilestone, |
| 967 | arg.ID, |
| 968 | arg.Title, |
| 969 | arg.Description, |
| 970 | arg.DueOn, |
| 971 | ) |
| 972 | return err |
| 973 | } |
| 974 |