diff --git a/models/bots/run_list.go b/models/bots/run_list.go index eb9bf7f9f0..348d778a3c 100644 --- a/models/bots/run_list.go +++ b/models/bots/run_list.go @@ -77,3 +77,7 @@ func FindRuns(ctx context.Context, opts FindRunOptions) (RunList, int64, error) total, err := e.Desc("id").FindAndCount(&runs) return runs, total, err } + +func CountRuns(ctx context.Context, opts FindRunOptions) (int64, error) { + return db.GetEngine(ctx).Where(opts.toConds()).Count(new(Run)) +} diff --git a/routers/web/repo/builds/builds.go b/routers/web/repo/builds/builds.go index fbcb5b099e..3d6b85b681 100644 --- a/routers/web/repo/builds/builds.go +++ b/routers/web/repo/builds/builds.go @@ -59,6 +59,7 @@ func List(ctx *context.Context) { } ctx.Data["workflows"] = workflows + ctx.Data["RepoLink"] = ctx.Repo.Repository.HTMLURL() page := ctx.FormInt("page") if page <= 0 { @@ -76,6 +77,26 @@ func List(ctx *context.Context) { RepoID: ctx.Repo.Repository.ID, WorkflowFileName: workflow, } + + // open counts + opts.IsClosed = util.OptionalBoolFalse + numOpenRuns, err := bots_model.CountRuns(ctx, opts) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + ctx.Data["NumOpenRuns"] = numOpenRuns + + // closed counts + opts.IsClosed = util.OptionalBoolTrue + numClosedRuns, err := bots_model.CountRuns(ctx, opts) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + ctx.Data["NumClosedRuns"] = numClosedRuns + + opts.IsClosed = util.OptionalBoolNone if ctx.FormString("state") == "closed" { opts.IsClosed = util.OptionalBoolTrue } else { diff --git a/templates/repo/builds/build_list.tmpl b/templates/repo/builds/build_list.tmpl index c24527f734..f1a7009a04 100644 --- a/templates/repo/builds/build_list.tmpl +++ b/templates/repo/builds/build_list.tmpl @@ -12,7 +12,7 @@