Stream returns a list of pull requests for a repo.
(ctx context.Context, opts *types.PullReqFilter)
| 512 | |
| 513 | // Stream returns a list of pull requests for a repo. |
| 514 | func (s *PullReqStore) Stream(ctx context.Context, opts *types.PullReqFilter) (<-chan *types.PullReq, <-chan error) { |
| 515 | stmt := s.listQuery(opts) |
| 516 | |
| 517 | stmt = stmt.OrderBy("pullreq_updated desc") |
| 518 | |
| 519 | chPRs := make(chan *types.PullReq) |
| 520 | chErr := make(chan error, 1) |
| 521 | |
| 522 | go func() { |
| 523 | defer close(chPRs) |
| 524 | defer close(chErr) |
| 525 | |
| 526 | sql, args, err := stmt.ToSql() |
| 527 | if err != nil { |
| 528 | chErr <- fmt.Errorf("failed to convert query to sql: %w", err) |
| 529 | return |
| 530 | } |
| 531 | |
| 532 | db := dbtx.GetAccessor(ctx, s.db) |
| 533 | |
| 534 | rows, err := db.QueryxContext(ctx, sql, args...) |
| 535 | if err != nil { |
| 536 | chErr <- database.ProcessSQLErrorf(ctx, err, "Failed to execute stream query") |
| 537 | return |
| 538 | } |
| 539 | |
| 540 | defer func() { _ = rows.Close() }() |
| 541 | |
| 542 | for rows.Next() { |
| 543 | var prData pullReq |
| 544 | err = rows.StructScan(&prData) |
| 545 | if err != nil { |
| 546 | chErr <- fmt.Errorf("failed to scan pull request: %w", err) |
| 547 | return |
| 548 | } |
| 549 | |
| 550 | chPRs <- s.mapPullReq(ctx, &prData) |
| 551 | } |
| 552 | |
| 553 | if err := rows.Err(); err != nil { |
| 554 | chErr <- fmt.Errorf("failed to scan pull request: %w", err) |
| 555 | } |
| 556 | }() |
| 557 | |
| 558 | return chPRs, chErr |
| 559 | } |
| 560 | |
| 561 | func (s *PullReqStore) ListOpenByBranchName( |
| 562 | ctx context.Context, |
nothing calls this directly
no test coverage detected