1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-03 04:48:25 +00:00

chore(runner): support fetch detail stage data

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-09-04 15:18:32 +08:00
committed by Jason Song
parent db02603882
commit fb738c4192
7 changed files with 125 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"strconv"
"code.gitea.io/gitea/core"
"code.gitea.io/gitea/models/db"
@@ -30,7 +31,7 @@ func init() {
// Build represnets bot build task
type Build struct {
ID int64
Title string
Name string
UUID string `xorm:"CHAR(36)"`
Index int64 `xorm:"index unique(repo_index)"`
RepoID int64 `xorm:"index unique(repo_index)"`
@@ -138,11 +139,20 @@ func UpdateBuild(t *Build, cols ...string) error {
type ErrBuildNotExist struct {
RepoID int64
Index int64
ID int64
UUID string
}
func (err ErrBuildNotExist) Error() string {
return fmt.Sprintf("Bot build [%s] is not exist", err.UUID)
uuid := ""
if err.UUID != "" {
uuid = err.UUID
}
if err.ID != 0 {
uuid = strconv.FormatInt(err.ID, 10)
}
return fmt.Sprintf("build [%s] is not exist", uuid)
}
// GetBuildByUUID gets bot build by uuid
@@ -159,6 +169,20 @@ func GetBuildByUUID(buildUUID string) (*Build, error) {
return &build, nil
}
func GetBuildByID(id int64) (*Build, error) {
var build Build
has, err := db.GetEngine(db.DefaultContext).Where("id=?", id).Get(&build)
if err != nil {
return nil, err
} else if !has {
return nil, ErrBuildNotExist{
ID: id,
}
}
return &build, nil
}
// GetCurBuildByID return the build for the bot
func GetCurBuildByID(runnerID int64) (*Build, error) {
var builds []Build