diff --git a/core/status.go b/core/status.go index 70aacb3747..371ad6b0b2 100644 --- a/core/status.go +++ b/core/status.go @@ -2,9 +2,11 @@ package core // BuildStatus represents a build status type BuildStatus string +type RunnerStatus string // enumerate all the statuses of bot build const ( + // Build status StatusSkipped BuildStatus = "skipped" StatusBlocked BuildStatus = "blocked" StatusDeclined BuildStatus = "declined" @@ -15,6 +17,11 @@ const ( StatusFailing BuildStatus = "failure" StatusKilled BuildStatus = "killed" StatusError BuildStatus = "error" + + // Runner status + StatusIdle RunnerStatus = "idle" + StatusActive RunnerStatus = "active" + StatusOffline RunnerStatus = "offline" ) func (status BuildStatus) IsPending() bool { diff --git a/models/bots/build_step.go b/models/bots/build_step.go deleted file mode 100644 index 4e3e3b12bf..0000000000 --- a/models/bots/build_step.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 - -import ( - "code.gitea.io/gitea/core" - "code.gitea.io/gitea/models/db" - "code.gitea.io/gitea/modules/timeutil" -) - -type BuildStep struct { - ID int64 - StageID int64 `xorm:"index"` - Number int64 - Name string - Kind string - Type string - Status core.BuildStatus - Started timeutil.TimeStamp - Stopped timeutil.TimeStamp - Created timeutil.TimeStamp `xorm:"created"` -} - -func (bj BuildStep) TableName() string { - return "bots_build_step" -} - -func init() { - db.RegisterModel(new(BuildStep)) -} diff --git a/models/bots/runner.go b/models/bots/runner.go index cba459e017..39de26830a 100644 --- a/models/bots/runner.go +++ b/models/bots/runner.go @@ -8,6 +8,7 @@ import ( "context" "fmt" + "code.gitea.io/gitea/core" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" @@ -44,6 +45,8 @@ type Runner struct { RepoRange string // glob match which repositories could use this runner Token string + // instance status (idle) + Status core.RunnerStatus // Store OS and Artch. AgentLabels []string // Store custom labes use defined. diff --git a/models/bots/runner_token.go b/models/bots/runner_token.go new file mode 100644 index 0000000000..234b396151 --- /dev/null +++ b/models/bots/runner_token.go @@ -0,0 +1,43 @@ +// 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 + +import ( + "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/timeutil" + + gouuid "github.com/google/uuid" +) + +// RunnerToken represents runner tokens +type RunnerToken struct { + ID int64 + Token string `xorm:"CHAR(36) UNIQUE"` + OwnerID int64 `xorm:"index"` // org level runner, 0 means system + Owner *user_model.User `xorm:"-"` + RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global + Repo *repo_model.Repository `xorm:"-"` + + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` +} + +func (RunnerToken) TableName() string { + return "bots_runner_token" +} + +func init() { + db.RegisterModel(new(RunnerToken)) +} + +// NewAccessToken creates new access token. +func NewRunnerToken(t *RunnerToken) error { + t.Token = base.EncodeSha1(gouuid.New().String()) + _, err := db.GetEngine(db.DefaultContext).Insert(t) + return err +}