diff --git a/appview/db/pipeline.go b/appview/db/pipeline.go index bd5e19c3..b643628c 100644 --- a/appview/db/pipeline.go +++ b/appview/db/pipeline.go @@ -170,11 +170,13 @@ func AddPipelineStatus(e Execer, status models.PipelineStatus) error { // this is a mega query, but the most useful one: // get N pipelines, for each one get the latest status of its N workflows +// +// the pipelines table is aliased to `p` +// the triggers table is aliased to `t` func GetPipelineStatuses(e Execer, limit int, filters ...orm.Filter) ([]models.Pipeline, error) { var conditions []string var args []any for _, filter := range filters { - filter.Key = "p." + filter.Key // the table is aliased in the query to `p` conditions = append(conditions, filter.Condition()) args = append(args, filter.Arg()...) } @@ -366,3 +368,48 @@ func GetPipelineStatuses(e Execer, limit int, filters ...orm.Filter) ([]models.P return all, nil } + +// the pipelines table is aliased to `p` +// the triggers table is aliased to `t` +func GetTotalPipelineStatuses(e Execer, filters ...orm.Filter) (int64, error) { + 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 ") + } + + query := fmt.Sprintf(` + select + count(1) + from + pipelines p + join + triggers t ON p.trigger_id = t.id + %s + `, whereClause) + + rows, err := e.Query(query, args...) + if err != nil { + return 0, err + } + defer rows.Close() + + for rows.Next() { + var count int64 + err := rows.Scan(&count) + if err != nil { + return 0, err + } + + return count, nil + } + + // unreachable + return 0, nil +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index c7fa9ff9..0b758f31 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -1348,12 +1348,12 @@ func (p *Pages) EditLabelPanel(w io.Writer, params EditLabelPanelParams) error { } type PipelinesParams struct { - LoggedInUser *oauth.MultiAccountUser - RepoInfo repoinfo.RepoInfo - Pipelines []models.Pipeline - Active string - FilteringByPush bool - FilteringByPR bool + LoggedInUser *oauth.MultiAccountUser + RepoInfo repoinfo.RepoInfo + Pipelines []models.Pipeline + Active string + FilterKind string + Total int64 } func (p *Pages) Pipelines(w io.Writer, params PipelinesParams) error { diff --git a/appview/pages/templates/repo/pipelines/pipelines.html b/appview/pages/templates/repo/pipelines/pipelines.html index 5d02564d..0a51048f 100644 --- a/appview/pages/templates/repo/pipelines/pipelines.html +++ b/appview/pages/templates/repo/pipelines/pipelines.html @@ -7,12 +7,7 @@ {{ end }} {{ define "repoContent" }} - {{ $active := "all" }} - {{ if .FilteringByPush }} - {{ $active = "push" }} - {{ else if .FilteringByPR }} - {{ $active = "pr" }} - {{ end }} + {{ $active := .FilterKind }} {{ $all := (dict @@ -28,7 +23,7 @@ "Meta" "") }} {{ $pr := (dict - "Key" "pr" + "Key" "pull_request" "Value" "pull request" "Icon" "git-pull-request" "Meta" "") }} @@ -36,10 +31,10 @@