mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 17:05:45 +02:00
chore(runner): create runner token table
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
4dd135580f
commit
0993c40c4f
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
@ -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.
|
||||
|
43
models/bots/runner_token.go
Normal file
43
models/bots/runner_token.go
Normal file
@ -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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user