Skip to content

[bug] miners API: CLOSED pull requests filtered by created_at instead of closed_at #139

@kiannidev

Description

@kiannidev

Duplicate check

Item Relation
#71 (closed) Backfill GraphQL stops at created_at — ingestion layer, not miner query
#16 / #15 (closed) Backfill lookback window — not REST miners API
#100 (open) Pagination — orthogonal
No open/closed issue Miner /pulls CLOSED branch uses created_at

Description

GET/POST /api/v1/miners/:githubId/pulls applies inconsistent time windows across PR states. MERGED PRs correctly use merged_at >= since. CLOSED (unmerged) PRs use created_at >= since, while the sibling /issues endpoint uses closed_at >= since for closed issues. Old PRs closed inside the scoring window but opened before since are omitted from miner pull results.

Steps to Reproduce

  1. Mirror a repo with a miner-authored PR: created_at = 60 days ago, closed_at = 5 days ago, state = CLOSED (not merged).
  2. Call GET /api/v1/miners/{authorId}/pulls?since= (ISO timestamp 30 days ago).
  3. Call GET /api/v1/miners/{authorId}/issues?since= (same timestamp).
  4. The closed issue appears ( closed_at >= since ); the closed PR does not (created_at < since).
  5. Repeat with POST .../pulls and since_by_repo — same filter in getPullRequestsByRepo.

Expected Behavior

CLOSED PRs should enter the window when closed_at >= since, matching issues and matching how MERGED uses merged_at.

Actual Behavior

-- miners.service.ts (GET and POST variants)
(p.state = 'OPEN'   AND p.created_at >= $2)
OR (p.state = 'MERGED' AND p.merged_at >= $2)
OR (p.state = 'CLOSED' AND p.created_at >= $2)   -- should use closed_at

Issues endpoint for comparison:

(i.state = 'CLOSED' AND i.closed_at >= $2)

Environment

  • OS: Linux
  • Runtime/Node version: Node 20
  • Browser (if applicable): N/A

Additional Context

Files: packages/das/src/api/miners/miners.service.ts (lines ~186–190 and ~235–238)

Fix: Change CLOSED branch to p.closed_at >= $2 (and w.since in POST path); ensure closed_at is populated on webhook upsert (already stored in pull-request.handler.ts).

PR scope: ~5–15 lines + integration test or SQL fixture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions