chore(gRPC): handle requesut for stage data

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-09-03 15:58:58 +08:00
committed by Jason Song
parent eac6425b2f
commit ea0cf8515e
7 changed files with 289 additions and 2 deletions

View File

@ -5,8 +5,12 @@
package bots
import (
"context"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder"
)
type BuildStage struct {
@ -16,6 +20,9 @@ type BuildStage struct {
Name string
Kind string
Type string
Machine string
OS string
Arch string
Filename string
Status BuildStatus
Started timeutil.TimeStamp
@ -32,6 +39,35 @@ func init() {
db.RegisterModel(new(BuildStage))
}
type FindStageOptions struct {
db.ListOptions
BuildID int64
IsClosed util.OptionalBool
}
func (opts FindStageOptions) toConds() builder.Cond {
cond := builder.NewCond()
if opts.BuildID > 0 {
cond = cond.And(builder.Eq{"build_id": opts.BuildID})
}
if opts.IsClosed.IsTrue() {
cond = cond.And(builder.Expr("status IN (?,?,?,?)", StatusError, StatusFailing, StatusPassing))
} else if opts.IsClosed.IsFalse() {
cond = cond.And(builder.Expr("status IN (?,?,?)", StatusPending, StatusRunning))
}
return cond
}
func FindStages(ctx context.Context, opts FindStageOptions) (BuildStageList, error) {
sess := db.GetEngine(ctx).Where(opts.toConds())
if opts.ListOptions.PageSize > 0 {
skip, take := opts.GetSkipTake()
sess.Limit(take, skip)
}
var rows []*BuildStage
return rows, sess.Find(&rows)
}
func GetBuildWorkflows(buildID int64) (map[string]map[string]*BuildStage, error) {
jobs := make(map[string]map[string]*BuildStage)
err := db.GetEngine(db.DefaultContext).Iterate(new(BuildStage), func(idx int, bean interface{}) error {

View File

@ -0,0 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
type BuildStageList []*BuildStage