diff --git a/models/actions/runner.go b/models/actions/runner.go index 3658e2bc09..7c4138c79e 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -51,14 +51,13 @@ type ActionRunner struct { } func (r *ActionRunner) OwnType() string { - if r.OwnerID == 0 { - return "Global" + if r.RepoID != 0 { + return fmt.Sprintf("Repo(%s)", r.Repo.FullName()) } - if r.RepoID == 0 { - return r.Owner.Name + if r.OwnerID != 0 { + return fmt.Sprintf("Org(%s)", r.Owner.Name) } - - return r.Repo.FullName() + return "Global" } func (r *ActionRunner) Status() runnerv1.RunnerStatus { @@ -135,35 +134,35 @@ func init() { type FindRunnerOptions struct { db.ListOptions - RepoID int64 - OwnerID int64 - Sort string - Filter string - WithDeleted bool + RepoID int64 + OwnerID int64 + Sort string + Filter string + WithAvailable bool // not only runners belong to, but also runners can be used } func (opts FindRunnerOptions) toCond() builder.Cond { cond := builder.NewCond() - withGlobal := false if opts.RepoID > 0 { - cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) - withGlobal = true + c := builder.NewCond().And(builder.Eq{"repo_id": opts.RepoID}) + if opts.WithAvailable { + c = c.Or(builder.Eq{"owner_id": builder.Select("owner_id").From("repository").Where(builder.Eq{"id": opts.RepoID})}) + c = c.Or(builder.Eq{"repo_id": 0, "owner_id": 0}) + } + cond = cond.And(c) } if opts.OwnerID > 0 { - cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) - withGlobal = true - } - if withGlobal { - cond = cond.Or(builder.Eq{"repo_id": 0, "owner_id": 0}) + c := builder.NewCond().And(builder.Eq{"owner_id": opts.OwnerID}) + if opts.WithAvailable { + c = c.Or(builder.Eq{"repo_id": 0, "owner_id": 0}) + } + cond = cond.And(c) } if opts.Filter != "" { cond = cond.And(builder.Like{"name", opts.Filter}) } - if !opts.WithDeleted { - cond = cond.And(builder.IsNull{"deleted"}) - } return cond } @@ -181,10 +180,8 @@ func (opts FindRunnerOptions) toOrder() string { func CountRunners(ctx context.Context, opts FindRunnerOptions) (int64, error) { return db.GetEngine(ctx). - Table(ActionRunner{}). Where(opts.toCond()). - OrderBy(opts.toOrder()). - Count() + Count(ActionRunner{}) } func FindRunners(ctx context.Context, opts FindRunnerOptions) (runners RunnerList, err error) { diff --git a/routers/web/admin/runners.go b/routers/web/admin/runners.go index 75b2b85ccb..6029862d97 100644 --- a/routers/web/admin/runners.go +++ b/routers/web/admin/runners.go @@ -36,11 +36,8 @@ func Runners(ctx *context.Context) { Page: page, PageSize: 100, }, - Sort: ctx.Req.URL.Query().Get("sort"), - Filter: ctx.Req.URL.Query().Get("q"), - WithDeleted: false, - RepoID: 0, - OwnerID: 0, + Sort: ctx.Req.URL.Query().Get("sort"), + Filter: ctx.Req.URL.Query().Get("q"), } common.RunnersList(ctx, tplRunners, opts) diff --git a/routers/web/org/org_runners.go b/routers/web/org/org_runners.go index 925b71529a..cd9b194baa 100644 --- a/routers/web/org/org_runners.go +++ b/routers/web/org/org_runners.go @@ -28,11 +28,10 @@ func Runners(ctx *context.Context) { Page: page, PageSize: 100, }, - Sort: ctx.Req.URL.Query().Get("sort"), - Filter: ctx.Req.URL.Query().Get("q"), - WithDeleted: false, - RepoID: 0, - OwnerID: ctx.Org.Organization.ID, + Sort: ctx.Req.URL.Query().Get("sort"), + Filter: ctx.Req.URL.Query().Get("q"), + OwnerID: ctx.Org.Organization.ID, + WithAvailable: true, } common.RunnersList(ctx, tplSettingsRunners, opts) diff --git a/routers/web/repo/runners.go b/routers/web/repo/runners.go index 24e974fe05..97bf9dd995 100644 --- a/routers/web/repo/runners.go +++ b/routers/web/repo/runners.go @@ -32,11 +32,10 @@ func Runners(ctx *context.Context) { Page: page, PageSize: 100, }, - Sort: ctx.Req.URL.Query().Get("sort"), - Filter: ctx.Req.URL.Query().Get("q"), - WithDeleted: false, - RepoID: ctx.Repo.Repository.ID, - OwnerID: 0, + Sort: ctx.Req.URL.Query().Get("sort"), + Filter: ctx.Req.URL.Query().Get("q"), + RepoID: ctx.Repo.Repository.ID, + WithAvailable: true, } common.RunnersList(ctx, tplRunners, opts) diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index a62af5e53d..c36f59a94f 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -434,7 +434,7 @@ {{if .EnableActions}} - {{$isActionsEnabled := .Repository.UnitEnabled $.UnitTypeActions}} + {{$isActionsEnabled := .Repository.UnitEnabled $.Context $.UnitTypeActions}}