chore(runner): register new runner

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-10-10 16:37:18 +08:00
committed by Jason Song
parent e21c07cc55
commit ade88b3a7b
3 changed files with 89 additions and 27 deletions

View File

@ -43,7 +43,7 @@ type Runner struct {
Description string `xorm:"TEXT"`
Base int // 0 native 1 docker 2 virtual machine
RepoRange string // glob match which repositories could use this runner
Token string
Token string `xorm:"CHAR(36) UNIQUE"`
// instance status (idle)
Status core.RunnerStatus
@ -148,7 +148,7 @@ func GetRunnerByToken(token string) (*Runner, error) {
return nil, err
} else if !has {
return nil, ErrRunnerNotExist{
UUID: "",
Token: token,
}
}
return &runner, nil
@ -177,3 +177,9 @@ func FindRunnersByRepoID(repoID int64) ([]*Runner, error) {
err = db.GetEngine(db.DefaultContext).Join("INNER", "repository", "repository.owner_id = bot_runner.owner_id").Find(&runners)
return runners, err
}
// NewRunner creates new runner.
func NewRunner(ctx context.Context, t *Runner) error {
_, err := db.GetEngine(ctx).Insert(t)
return err
}