mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-19 07:04:10 +09:00
refactor: rename tables to bot_*
This commit is contained in:
@ -22,8 +22,8 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// Run represents a run of a workflow file
|
||||
type Run struct {
|
||||
// BotRun represents a run of a workflow file
|
||||
type BotRun struct {
|
||||
ID int64
|
||||
Title string
|
||||
RepoID int64 `xorm:"index unique(repo_index)"`
|
||||
@ -46,20 +46,16 @@ type Run struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(Run))
|
||||
db.RegisterModel(new(RunIndex))
|
||||
db.RegisterModel(new(BotRun))
|
||||
db.RegisterModel(new(BotRunIndex))
|
||||
}
|
||||
|
||||
func (Run) TableName() string {
|
||||
return "bots_run"
|
||||
}
|
||||
|
||||
func (run *Run) HTMLURL() string {
|
||||
func (run *BotRun) HTMLURL() string {
|
||||
return fmt.Sprintf("%s/bots/runs/%d", run.Repo.HTMLURL(), run.Index)
|
||||
}
|
||||
|
||||
// LoadAttributes load Repo TriggerUser if not loaded
|
||||
func (run *Run) LoadAttributes(ctx context.Context) error {
|
||||
func (run *BotRun) LoadAttributes(ctx context.Context) error {
|
||||
if run == nil {
|
||||
return nil
|
||||
}
|
||||
@ -86,7 +82,7 @@ func (run *Run) LoadAttributes(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (run *Run) TakeTime() time.Duration {
|
||||
func (run *BotRun) TakeTime() time.Duration {
|
||||
if run.Started == 0 {
|
||||
return 0
|
||||
}
|
||||
@ -98,7 +94,7 @@ func (run *Run) TakeTime() time.Duration {
|
||||
return time.Since(started).Truncate(time.Second)
|
||||
}
|
||||
|
||||
func (run *Run) GetPushEventPayload() (*api.PushPayload, error) {
|
||||
func (run *BotRun) GetPushEventPayload() (*api.PushPayload, error) {
|
||||
if run.Event == webhook.HookEventPush {
|
||||
var payload api.PushPayload
|
||||
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
|
||||
@ -134,7 +130,7 @@ func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) err
|
||||
}
|
||||
|
||||
// InsertRun inserts a bot run
|
||||
func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
|
||||
func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error {
|
||||
ctx, commiter, err := db.TxContext(db.DefaultContext)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -167,7 +163,7 @@ func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
|
||||
return err
|
||||
}
|
||||
|
||||
runJobs := make([]*RunJob, 0, len(jobs))
|
||||
runJobs := make([]*BotRunJob, 0, len(jobs))
|
||||
for _, v := range jobs {
|
||||
id, job := v.Job()
|
||||
needs := job.Needs()
|
||||
@ -177,7 +173,7 @@ func InsertRun(run *Run, jobs []*jobparser.SingleWorkflow) error {
|
||||
if len(needs) > 0 {
|
||||
status = StatusBlocked
|
||||
}
|
||||
runJobs = append(runJobs, &RunJob{
|
||||
runJobs = append(runJobs, &BotRunJob{
|
||||
RunID: run.ID,
|
||||
RepoID: run.RepoID,
|
||||
OwnerID: run.OwnerID,
|
||||
@ -212,8 +208,8 @@ func (err ErrRunNotExist) Error() string {
|
||||
return fmt.Sprintf("run [%d] is not exist", err.ID)
|
||||
}
|
||||
|
||||
func GetRunByID(ctx context.Context, id int64) (*Run, error) {
|
||||
var run Run
|
||||
func GetRunByID(ctx context.Context, id int64) (*BotRun, error) {
|
||||
var run BotRun
|
||||
has, err := db.GetEngine(ctx).Where("id=?", id).Get(&run)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -226,8 +222,8 @@ func GetRunByID(ctx context.Context, id int64) (*Run, error) {
|
||||
return &run, nil
|
||||
}
|
||||
|
||||
func GetRunByIndex(ctx context.Context, repoID, index int64) (*Run, error) {
|
||||
run := &Run{
|
||||
func GetRunByIndex(ctx context.Context, repoID, index int64) (*BotRun, error) {
|
||||
run := &BotRun{
|
||||
RepoID: repoID,
|
||||
Index: index,
|
||||
}
|
||||
@ -244,7 +240,7 @@ func GetRunByIndex(ctx context.Context, repoID, index int64) (*Run, error) {
|
||||
return run, nil
|
||||
}
|
||||
|
||||
func UpdateRun(ctx context.Context, run *Run, cols ...string) error {
|
||||
func UpdateRun(ctx context.Context, run *BotRun, cols ...string) error {
|
||||
sess := db.GetEngine(ctx).ID(run.ID)
|
||||
if len(cols) > 0 {
|
||||
sess.Cols(cols...)
|
||||
@ -273,8 +269,4 @@ func UpdateRun(ctx context.Context, run *Run, cols ...string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
type RunIndex db.ResourceIndex
|
||||
|
||||
func (RunIndex) TableName() string {
|
||||
return "bots_run_index"
|
||||
}
|
||||
type BotRunIndex db.ResourceIndex
|
||||
|
Reference in New Issue
Block a user