From 494d833273db453d46850a8a3966598bdc4912be Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 23 Oct 2025 22:29:21 +0900 Subject: [PATCH] appview/pulls: add search endpoint Change-Id: vsqwxpkpopsnurrqxnuykssylyxkvmzx Signed-off-by: Seongmin Lee --- appview/db/pulls.go | 61 +++++++++++++++++++ appview/pages/pages.go | 1 + appview/pages/templates/repo/pulls/pulls.html | 7 +++ appview/pulls/pulls.go | 37 ++++++++++- appview/state/router.go | 1 + 5 files changed, 105 insertions(+), 2 deletions(-) diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 0d0007f7..99b0a7c0 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -281,6 +281,67 @@ func GetPulls(e Execer, filters ...filter) ([]*models.Pull, error) { return GetPullsWithLimit(e, 0, filters...) } +func GetPullIDs(e Execer, opts models.PullSearchOptions) ([]int64, error) { + var ids []int64 + + var filters []filter + filters = append(filters, FilterEq("state", opts.State)) + if opts.RepoAt != "" { + filters = append(filters, FilterEq("repo_at", opts.RepoAt)) + } + + var conditions []string + var args []any + + for _, filter := range filters { + conditions = append(conditions, filter.Condition()) + args = append(args, filter.Arg()...) + } + + whereClause := "" + if conditions != nil { + whereClause = " where " + strings.Join(conditions, " and ") + } + pageClause := "" + if opts.Page.Limit != 0 { + pageClause = fmt.Sprintf( + " limit %d offset %d ", + opts.Page.Limit, + opts.Page.Offset, + ) + } + + query := fmt.Sprintf( + ` + select + id + from + pulls + %s + %s`, + whereClause, + pageClause, + ) + args = append(args, opts.Page.Limit, opts.Page.Offset) + rows, err := e.Query(query, args...) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var id int64 + err := rows.Scan(&id) + if err != nil { + return nil, err + } + + ids = append(ids, id) + } + + return ids, nil +} + func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*models.Pull, error) { pulls, err := GetPullsWithLimit(e, 1, FilterEq("repo_at", repoAt), FilterEq("pull_id", pullId)) if err != nil { diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 9e2e2a56..9608ff2e 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1102,6 +1102,7 @@ type RepoPullsParams struct { Pulls []*models.Pull Active string FilteringBy models.PullState + FilterQuery string Stacks map[string]models.Stack Pipelines map[string]models.Pipeline LabelDefs map[string]*models.LabelDefinition diff --git a/appview/pages/templates/repo/pulls/pulls.html b/appview/pages/templates/repo/pulls/pulls.html index 6541a54c..f2c557d3 100644 --- a/appview/pages/templates/repo/pulls/pulls.html +++ b/appview/pages/templates/repo/pulls/pulls.html @@ -31,6 +31,13 @@ {{ i "ban" "w-4 h-4" }} {{ .RepoInfo.Stats.PullCount.Closed }} closed +
+ + + +