From ce3b71a87f98f06c41e2afee32ee034edc6a0cfa Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 7 Jun 2023 13:50:02 +0800 Subject: [PATCH 01/25] add actors dropdown --- models/actions/run_list.go | 8 +++++++ options/locale/locale_en-US.ini | 4 ++++ routers/web/repo/actions/actions.go | 30 +++++++++++++++++++++++++-- templates/repo/actions/list.tmpl | 27 ++++++++++++++++++++++-- templates/repo/actions/runs_list.tmpl | 5 +++++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/models/actions/run_list.go b/models/actions/run_list.go index 56de8eb9169cf..e81d72c2194ac 100644 --- a/models/actions/run_list.go +++ b/models/actions/run_list.go @@ -25,6 +25,14 @@ func (runs RunList) GetUserIDs() []int64 { return ids.Values() } +// GetActors returns a slice of Actors +func (runs RunList) GetActors(ctx context.Context) (map[int64]*user_model.User, error) { + actorIDs := runs.GetUserIDs() + actors := make(map[int64]*user_model.User, len(actorIDs)) + err := db.GetEngine(ctx).In("id", actorIDs).Find(&actors) + return actors, err +} + func (runs RunList) GetRepoIDs() []int64 { ids := make(container.Set[int64], len(runs)) for _, run := range runs { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 25456d0493426..f93aecf8f248e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3457,6 +3457,10 @@ runs.commit = Commit runs.pushed_by = Pushed by runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s runs.no_matching_runner_helper = No matching runner: %s +runs.actor = Actor +runs.actors_no_select = All actors +runs.no_results = No results matched. +runs.no_runs = The workflow has no runs yet. need_approval_desc = Need approval to run workflows for fork pull request. diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 10acb468542ea..8a4ef322217b8 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -5,6 +5,7 @@ package actions import ( "bytes" + "fmt" "net/http" actions_model "code.gitea.io/gitea/models/actions" @@ -125,8 +126,12 @@ func List(ctx *context.Context) { } workflow := ctx.FormString("workflow") + actorID := ctx.FormInt64("actor") ctx.Data["CurWorkflow"] = workflow - + ctx.Data["CurActor"] = actorID + if actorID > 0 { + ctx.Data["IsFiltered"] = true + } opts := actions_model.FindRunOptions{ ListOptions: db.ListOptions{ Page: page, @@ -134,6 +139,7 @@ func List(ctx *context.Context) { }, RepoID: ctx.Repo.Repository.ID, WorkflowFileName: workflow, + TriggerUserID: actorID, } runs, total, err := actions_model.FindRuns(ctx, opts) @@ -151,11 +157,31 @@ func List(ctx *context.Context) { return } - ctx.Data["Runs"] = runs + allRunsOpts := actions_model.FindRunOptions{ + ListOptions: db.ListOptions{ + ListAll: true, + }, + RepoID: ctx.Repo.Repository.ID, + } + allRuns, _, err := actions_model.FindRuns(ctx, allRunsOpts) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + + actors, err := allRuns.GetActors(ctx) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + + ctx.Data["Runs"] = runs + ctx.Data["Actors"] = actors pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) pager.AddParamString("workflow", workflow) + pager.AddParamString("actor", fmt.Sprint(actorID)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplListActions) diff --git a/templates/repo/actions/list.tmpl b/templates/repo/actions/list.tmpl index ca97b67faaa07..36147e2b4d7b9 100644 --- a/templates/repo/actions/list.tmpl +++ b/templates/repo/actions/list.tmpl @@ -5,10 +5,10 @@
diff --git a/templates/repo/actions/runs_list.tmpl b/templates/repo/actions/runs_list.tmpl index 5f444f31f910b..5ba27f1817502 100644 --- a/templates/repo/actions/runs_list.tmpl +++ b/templates/repo/actions/runs_list.tmpl @@ -1,4 +1,9 @@
+ {{if and (eq (len .Runs) 0) $.IsFiltered }} +
{{.locale.Tr "actions.runs.no_results"}}
+ {{else if eq (len .Runs) 0}} +
{{.locale.Tr "actions.runs.no_runs"}}
+ {{end}} {{range .Runs}}
  • From 5b6e7f2fbf7b0f21129834c90c47164dec1af9f5 Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 7 Jun 2023 14:02:42 +0800 Subject: [PATCH 02/25] update --- routers/web/repo/actions/actions.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 8a4ef322217b8..3f511b0f3ab68 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -157,6 +157,8 @@ func List(ctx *context.Context) { return } + ctx.Data["Runs"] = runs + allRunsOpts := actions_model.FindRunOptions{ ListOptions: db.ListOptions{ ListAll: true, @@ -175,9 +177,8 @@ func List(ctx *context.Context) { ctx.Error(http.StatusInternalServerError, err.Error()) return } - - ctx.Data["Runs"] = runs ctx.Data["Actors"] = actors + pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) pager.AddParamString("workflow", workflow) From 2fe81fd5c54b05104bec033162380cd34d915e48 Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 7 Jun 2023 16:00:55 +0800 Subject: [PATCH 03/25] add status dropdown --- models/actions/run_list.go | 26 ++++++++++++++++++++++++ options/locale/locale_en-US.ini | 2 ++ routers/web/repo/actions/actions.go | 8 +++++++- templates/repo/actions/list.tmpl | 31 ++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/models/actions/run_list.go b/models/actions/run_list.go index e81d72c2194ac..c6a523534ef90 100644 --- a/models/actions/run_list.go +++ b/models/actions/run_list.go @@ -41,6 +41,28 @@ func (runs RunList) GetRepoIDs() []int64 { return ids.Values() } +type StatusInfo struct { + Status int + DisplayedStatus string +} + +// GetStatuses returns a slice of statuses +func (runs RunList) GetStatuses(ctx context.Context) []StatusInfo { + statuses := make(container.Set[int], len(runs)) + statusInfos := make([]StatusInfo, 0, len(runs)) + for _, run := range runs { + if statuses.Contains(int(run.Status)) { + continue + } + statuses.Add(int(run.Status)) + statusInfos = append(statusInfos, StatusInfo{ + Status: int(run.Status), + DisplayedStatus: run.Status.String(), + }) + } + return statusInfos +} + func (runs RunList) LoadTriggerUser(ctx context.Context) error { userIDs := runs.GetUserIDs() users := make(map[int64]*user_model.User, len(userIDs)) @@ -79,6 +101,7 @@ type FindRunOptions struct { WorkflowFileName string TriggerUserID int64 Approved bool // not util.OptionalBool, it works only when it's true + Status Status } func (opts FindRunOptions) toConds() builder.Cond { @@ -98,6 +121,9 @@ func (opts FindRunOptions) toConds() builder.Cond { if opts.Approved { cond = cond.And(builder.Gt{"approved_by": 0}) } + if opts.Status > StatusUnknown { + cond = cond.And(builder.Eq{"status": opts.Status}) + } return cond } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f93aecf8f248e..5f6c9a09b1d9c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3458,7 +3458,9 @@ runs.pushed_by = Pushed by runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s runs.no_matching_runner_helper = No matching runner: %s runs.actor = Actor +runs.status = Status runs.actors_no_select = All actors +runs.status_no_select = All status runs.no_results = No results matched. runs.no_runs = The workflow has no runs yet. diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 3f511b0f3ab68..bdefc3126af74 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -127,9 +127,11 @@ func List(ctx *context.Context) { workflow := ctx.FormString("workflow") actorID := ctx.FormInt64("actor") + status := ctx.FormInt("status") ctx.Data["CurWorkflow"] = workflow ctx.Data["CurActor"] = actorID - if actorID > 0 { + ctx.Data["CurStatus"] = status + if actorID > 0 || status > int(actions_model.StatusUnknown) { ctx.Data["IsFiltered"] = true } opts := actions_model.FindRunOptions{ @@ -140,6 +142,7 @@ func List(ctx *context.Context) { RepoID: ctx.Repo.Repository.ID, WorkflowFileName: workflow, TriggerUserID: actorID, + Status: actions_model.Status(status), } runs, total, err := actions_model.FindRuns(ctx, opts) @@ -178,11 +181,14 @@ func List(ctx *context.Context) { return } ctx.Data["Actors"] = actors + statusInfos := allRuns.GetStatuses(ctx) + ctx.Data["StatusInfos"] = statusInfos pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) pager.AddParamString("workflow", workflow) pager.AddParamString("actor", fmt.Sprint(actorID)) + pager.AddParamString("status", fmt.Sprint(status)) ctx.Data["Page"] = pager ctx.HTML(http.StatusOK, tplListActions) diff --git a/templates/repo/actions/list.tmpl b/templates/repo/actions/list.tmpl index 36147e2b4d7b9..809d53e6632c4 100644 --- a/templates/repo/actions/list.tmpl +++ b/templates/repo/actions/list.tmpl @@ -5,10 +5,10 @@ From 15b0681e5fdffa3d71975f68d4e87a0259ffde9b Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 7 Jun 2023 16:05:25 +0800 Subject: [PATCH 04/25] rename --- models/actions/run_list.go | 4 ++-- routers/web/repo/actions/actions.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/actions/run_list.go b/models/actions/run_list.go index c6a523534ef90..5b0f0b37a459c 100644 --- a/models/actions/run_list.go +++ b/models/actions/run_list.go @@ -46,8 +46,8 @@ type StatusInfo struct { DisplayedStatus string } -// GetStatuses returns a slice of statuses -func (runs RunList) GetStatuses(ctx context.Context) []StatusInfo { +// GetStatusInfos returns a slice of StatusInfo +func (runs RunList) GetStatusInfos(ctx context.Context) []StatusInfo { statuses := make(container.Set[int], len(runs)) statusInfos := make([]StatusInfo, 0, len(runs)) for _, run := range runs { diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index bdefc3126af74..6d31a6b65481e 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -181,7 +181,7 @@ func List(ctx *context.Context) { return } ctx.Data["Actors"] = actors - statusInfos := allRuns.GetStatuses(ctx) + statusInfos := allRuns.GetStatusInfos(ctx) ctx.Data["StatusInfos"] = statusInfos pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5) From 5e71a9ce8bbc7fcb6086afa5ac9a21b9ee8e9dfe Mon Sep 17 00:00:00 2001 From: HesterG Date: Wed, 7 Jun 2023 16:25:49 +0800 Subject: [PATCH 05/25] update styles --- templates/repo/actions/list.tmpl | 4 ++-- templates/repo/actions/runs_list.tmpl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/actions/list.tmpl b/templates/repo/actions/list.tmpl index 809d53e6632c4..ed0da28c48783 100644 --- a/templates/repo/actions/list.tmpl +++ b/templates/repo/actions/list.tmpl @@ -19,9 +19,9 @@
  • -