summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorHesterG <hestergong@gmail.com>2023-06-21 12:25:14 +0800
committerGitHub <noreply@github.com>2023-06-21 04:25:14 +0000
commit1454f9dafc681875d8f6a429b80e27de62f4040e (patch)
treea450eb8e78cb5f7add2d2aee48b2841874b63647 /models
parente79ff5056043f25a77c50847a228826bc7cdaf61 (diff)
downloadgitea-1454f9dafc681875d8f6a429b80e27de62f4040e.tar.gz
gitea-1454f9dafc681875d8f6a429b80e27de62f4040e.zip
Add actor and status dropdowns to run list (#25118)
Part of #25042 1. Added actor and status dropdowns first in case something is offtrack and PR is too large. 2. Also added "No results matched." and "The workflow has no runs yet.", and "No results matched." will show if there is no filter results and there is no workflows (with [reference to github action](https://github.com/go-gitea/gitea/actions/workflows/files-changed.yml?query=actor%3AGiteaBot)) Demo: https://github.com/go-gitea/gitea/assets/17645053/6e76292c-4c1f-450d-8b48-99944cfc920c TODOs: - [x] Get available status (same as those in `aggregateJobStatus`) instead of getting from database - [x] Use `JOIN` to get actors, actors order by name - [x] Make self on top
Diffstat (limited to 'models')
-rw-r--r--models/actions/run_list.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/models/actions/run_list.go b/models/actions/run_list.go
index 56de8eb916..29ab193d57 100644
--- a/models/actions/run_list.go
+++ b/models/actions/run_list.go
@@ -71,6 +71,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 {
@@ -90,6 +91,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
}
@@ -106,3 +110,34 @@ func FindRuns(ctx context.Context, opts FindRunOptions) (RunList, int64, error)
func CountRuns(ctx context.Context, opts FindRunOptions) (int64, error) {
return db.GetEngine(ctx).Where(opts.toConds()).Count(new(ActionRun))
}
+
+type StatusInfo struct {
+ Status int
+ DisplayedStatus string
+}
+
+// GetStatusInfoList returns a slice of StatusInfo
+func GetStatusInfoList(ctx context.Context) []StatusInfo {
+ // same as those in aggregateJobStatus
+ allStatus := []Status{StatusSuccess, StatusFailure, StatusWaiting, StatusRunning}
+ statusInfoList := make([]StatusInfo, 0, 4)
+ for _, s := range allStatus {
+ statusInfoList = append(statusInfoList, StatusInfo{
+ Status: int(s),
+ DisplayedStatus: s.String(),
+ })
+ }
+ return statusInfoList
+}
+
+// GetActors returns a slice of Actors
+func GetActors(ctx context.Context, repoID int64) ([]*user_model.User, error) {
+ actors := make([]*user_model.User, 0, 10)
+
+ return actors, db.GetEngine(ctx).Where(builder.In("id", builder.Select("`action_run`.trigger_user_id").From("`action_run`").
+ GroupBy("`action_run`.trigger_user_id").
+ Where(builder.Eq{"`action_run`.repo_id": repoID}))).
+ Cols("id", "name", "full_name", "avatar", "avatar_email", "use_custom_avatar").
+ OrderBy(user_model.GetOrderByName()).
+ Find(&actors)
+}