From 6be75693912ffacabc8f22a563a5bfc7858b2433 Mon Sep 17 00:00:00 2001 From: dusk Date: Tue, 12 Aug 2025 18:02:21 +0300 Subject: [PATCH] appview: db: pulls: add method for getting any pulls on a repo Change-Id: vpswvtqqqqlkzmwtvkuotykmoooqmwou Signed-off-by: dusk --- appview/db/pulls.go | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index e993791..dd3512b 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -723,6 +723,60 @@ func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) { return &pull, nil } +func GetAnyPulls(e Execer, repoAt syntax.ATURI, count int) ([]Pull, error) { + pulls := make([]Pull, 0, count) + + rows, err := e.Query(` + select + p.owner_did, + p.repo_at, + p.pull_id, + p.created, + p.title, + p.state + from + pulls p + where + p.repo_at = ? + order by + p.created desc`, + repoAt) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var pull Pull + var pullCreatedAt string + err := rows.Scan( + &pull.OwnerDid, + &pull.RepoAt, + &pull.PullId, + &pullCreatedAt, + &pull.Title, + &pull.State, + ) + if err != nil { + return nil, err + } + + pullCreatedTime, err := time.Parse(time.RFC3339, pullCreatedAt) + if err != nil { + return nil, err + } + pull.Created = pullCreatedTime + + pulls = append(pulls, pull) + } + + if err := rows.Err(); err != nil { + return nil, err + } + + return pulls, nil +} + // timeframe here is directly passed into the sql query filter, and any // timeframe in the past should be negative; e.g.: "-3 months" func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) { -- 2.43.0