feat(runner): delete runner from admin html page

This commit is contained in:
fuxiaohei
2022-10-12 20:57:40 +08:00
committed by Jason Song
parent 5b989e2a11
commit fbb9f437a6
6 changed files with 58 additions and 24 deletions

View File

@ -97,10 +97,11 @@ func init() {
type FindRunnerOptions struct {
db.ListOptions
RepoID int64
OwnerID int64
Sort string
Filter string
RepoID int64
OwnerID int64
Sort string
Filter string
WithDeleted bool
}
func (opts FindRunnerOptions) toCond() builder.Cond {
@ -115,6 +116,9 @@ func (opts FindRunnerOptions) toCond() builder.Cond {
if opts.Filter != "" {
cond = cond.And(builder.Like{"name", opts.Filter})
}
if !opts.WithDeleted {
cond = cond.And(builder.IsNull{"deleted"})
}
return cond
}
@ -208,9 +212,9 @@ func GetRunnerByToken(token string) (*Runner, error) {
}
// UpdateRunner updates runner's information.
func UpdateRunner(ctx context.Context, r *Runner, cols ...string) (err error) {
func UpdateRunner(ctx context.Context, r *Runner, cols ...string) error {
e := db.GetEngine(ctx)
var err error
if len(cols) == 0 {
_, err = e.ID(r.ID).AllCols().Update(r)
} else {
@ -219,6 +223,12 @@ func UpdateRunner(ctx context.Context, r *Runner, cols ...string) (err error) {
return err
}
func DeleteRunner(ctx context.Context, r *Runner) error {
e := db.GetEngine(ctx)
_, err := e.Delete(r)
return err
}
// FindRunnersByRepoID returns all workers for the repository
func FindRunnersByRepoID(repoID int64) ([]*Runner, error) {
var runners []*Runner