refactor: rename tables to bot_*

This commit is contained in:
Jason Song
2022-11-29 12:34:23 +08:00
parent 3ac6bf3db4
commit 04d72d3500
20 changed files with 173 additions and 201 deletions

View File

@ -14,7 +14,7 @@ const (
)
// FullSteps returns steps with "Set up job" and "Complete job"
func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
if len(task.Steps) == 0 {
return fullStepsOfEmptySteps(task)
}
@ -22,7 +22,7 @@ func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
firstStep := task.Steps[0]
var logIndex int64
preStep := &bots_model.TaskStep{
preStep := &bots_model.BotTaskStep{
Name: preStepName,
LogLength: task.LogLength,
Started: task.Started,
@ -39,7 +39,7 @@ func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
}
logIndex += preStep.LogLength
var lastHasRunStep *bots_model.TaskStep
var lastHasRunStep *bots_model.BotTaskStep
for _, step := range task.Steps {
if step.Status.HasRun() {
lastHasRunStep = step
@ -50,7 +50,7 @@ func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
lastHasRunStep = preStep
}
postStep := &bots_model.TaskStep{
postStep := &bots_model.BotTaskStep{
Name: postStepName,
Status: bots_model.StatusWaiting,
}
@ -61,7 +61,7 @@ func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
postStep.Started = lastHasRunStep.Stopped
postStep.Stopped = task.Stopped
}
ret := make([]*bots_model.TaskStep, 0, len(task.Steps)+2)
ret := make([]*bots_model.BotTaskStep, 0, len(task.Steps)+2)
ret = append(ret, preStep)
ret = append(ret, task.Steps...)
ret = append(ret, postStep)
@ -69,8 +69,8 @@ func FullSteps(task *bots_model.Task) []*bots_model.TaskStep {
return ret
}
func fullStepsOfEmptySteps(task *bots_model.Task) []*bots_model.TaskStep {
preStep := &bots_model.TaskStep{
func fullStepsOfEmptySteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
preStep := &bots_model.BotTaskStep{
Name: preStepName,
LogLength: task.LogLength,
Started: task.Started,
@ -78,7 +78,7 @@ func fullStepsOfEmptySteps(task *bots_model.Task) []*bots_model.TaskStep {
Status: bots_model.StatusRunning,
}
postStep := &bots_model.TaskStep{
postStep := &bots_model.BotTaskStep{
Name: postStepName,
LogIndex: task.LogLength,
Started: task.Stopped,
@ -95,7 +95,7 @@ func fullStepsOfEmptySteps(task *bots_model.Task) []*bots_model.TaskStep {
}
}
return []*bots_model.TaskStep{
return []*bots_model.BotTaskStep{
preStep,
postStep,
}

View File

@ -15,13 +15,13 @@ import (
func TestFullSteps(t *testing.T) {
tests := []struct {
name string
task *bots_model.Task
want []*bots_model.TaskStep
task *bots_model.BotTask
want []*bots_model.BotTaskStep
}{
{
name: "regular",
task: &bots_model.Task{
Steps: []*bots_model.TaskStep{
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
},
Status: bots_model.StatusSuccess,
@ -29,7 +29,7 @@ func TestFullSteps(t *testing.T) {
Stopped: 10100,
LogLength: 100,
},
want: []*bots_model.TaskStep{
want: []*bots_model.BotTaskStep{
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
{Name: postStepName, Status: bots_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
@ -37,8 +37,8 @@ func TestFullSteps(t *testing.T) {
},
{
name: "failed step",
task: &bots_model.Task{
Steps: []*bots_model.TaskStep{
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
{Status: bots_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
@ -48,7 +48,7 @@ func TestFullSteps(t *testing.T) {
Stopped: 10100,
LogLength: 100,
},
want: []*bots_model.TaskStep{
want: []*bots_model.BotTaskStep{
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
{Status: bots_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
@ -58,8 +58,8 @@ func TestFullSteps(t *testing.T) {
},
{
name: "first step is running",
task: &bots_model.Task{
Steps: []*bots_model.TaskStep{
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
},
Status: bots_model.StatusRunning,
@ -67,7 +67,7 @@ func TestFullSteps(t *testing.T) {
Stopped: 10100,
LogLength: 100,
},
want: []*bots_model.TaskStep{
want: []*bots_model.BotTaskStep{
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: bots_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
{Name: postStepName, Status: bots_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
@ -75,8 +75,8 @@ func TestFullSteps(t *testing.T) {
},
{
name: "first step has canceled",
task: &bots_model.Task{
Steps: []*bots_model.TaskStep{
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
},
Status: bots_model.StatusFailure,
@ -84,7 +84,7 @@ func TestFullSteps(t *testing.T) {
Stopped: 10100,
LogLength: 100,
},
want: []*bots_model.TaskStep{
want: []*bots_model.BotTaskStep{
{Name: preStepName, Status: bots_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
{Name: postStepName, Status: bots_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
@ -92,14 +92,14 @@ func TestFullSteps(t *testing.T) {
},
{
name: "empty steps",
task: &bots_model.Task{
Steps: []*bots_model.TaskStep{},
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{},
Status: bots_model.StatusSuccess,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
want: []*bots_model.TaskStep{
want: []*bots_model.BotTaskStep{
{Name: preStepName, Status: bots_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
{Name: postStepName, Status: bots_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
},

View File

@ -86,7 +86,7 @@ func notifyWithPR(repo *repo_model.Repository, doer *user_model.User, ref string
}
for id, content := range workflows {
run := bots_model.Run{
run := bots_model.BotRun{
Title: commit.Message(),
RepoID: repo.ID,
OwnerID: repo.OwnerID,