refactor: rename import alias

This commit is contained in:
Jason Song
2022-12-05 15:57:45 +08:00
parent 5f74b35377
commit 67c5c8868b
22 changed files with 233 additions and 233 deletions
+18 -18
View File
@@ -4,7 +4,7 @@
package actions
import (
bots_model "code.gitea.io/gitea/models/actions"
actions_model "code.gitea.io/gitea/models/actions"
)
const (
@@ -13,7 +13,7 @@ const (
)
// FullSteps returns steps with "Set up job" and "Complete job"
func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep {
if len(task.Steps) == 0 {
return fullStepsOfEmptySteps(task)
}
@@ -21,24 +21,24 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
firstStep := task.Steps[0]
var logIndex int64
preStep := &bots_model.BotTaskStep{
preStep := &actions_model.BotTaskStep{
Name: preStepName,
LogLength: task.LogLength,
Started: task.Started,
Status: bots_model.StatusRunning,
Status: actions_model.StatusRunning,
}
if firstStep.Status.HasRun() || firstStep.Status.IsRunning() {
preStep.LogLength = firstStep.LogIndex
preStep.Stopped = firstStep.Started
preStep.Status = bots_model.StatusSuccess
preStep.Status = actions_model.StatusSuccess
} else if task.Status.IsDone() {
preStep.Stopped = task.Stopped
preStep.Status = bots_model.StatusFailure
preStep.Status = actions_model.StatusFailure
}
logIndex += preStep.LogLength
var lastHasRunStep *bots_model.BotTaskStep
var lastHasRunStep *actions_model.BotTaskStep
for _, step := range task.Steps {
if step.Status.HasRun() {
lastHasRunStep = step
@@ -49,9 +49,9 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
lastHasRunStep = preStep
}
postStep := &bots_model.BotTaskStep{
postStep := &actions_model.BotTaskStep{
Name: postStepName,
Status: bots_model.StatusWaiting,
Status: actions_model.StatusWaiting,
}
if task.Status.IsDone() {
postStep.LogIndex = logIndex
@@ -60,7 +60,7 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
postStep.Started = lastHasRunStep.Stopped
postStep.Stopped = task.Stopped
}
ret := make([]*bots_model.BotTaskStep, 0, len(task.Steps)+2)
ret := make([]*actions_model.BotTaskStep, 0, len(task.Steps)+2)
ret = append(ret, preStep)
ret = append(ret, task.Steps...)
ret = append(ret, postStep)
@@ -68,33 +68,33 @@ func FullSteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
return ret
}
func fullStepsOfEmptySteps(task *bots_model.BotTask) []*bots_model.BotTaskStep {
preStep := &bots_model.BotTaskStep{
func fullStepsOfEmptySteps(task *actions_model.BotTask) []*actions_model.BotTaskStep {
preStep := &actions_model.BotTaskStep{
Name: preStepName,
LogLength: task.LogLength,
Started: task.Started,
Stopped: task.Stopped,
Status: bots_model.StatusRunning,
Status: actions_model.StatusRunning,
}
postStep := &bots_model.BotTaskStep{
postStep := &actions_model.BotTaskStep{
Name: postStepName,
LogIndex: task.LogLength,
Started: task.Stopped,
Stopped: task.Stopped,
Status: bots_model.StatusWaiting,
Status: actions_model.StatusWaiting,
}
if task.Status.IsDone() {
preStep.Status = task.Status
if preStep.Status.IsSuccess() {
postStep.Status = bots_model.StatusSuccess
postStep.Status = actions_model.StatusSuccess
} else {
postStep.Status = bots_model.StatusCancelled
postStep.Status = actions_model.StatusCancelled
}
}
return []*bots_model.BotTaskStep{
return []*actions_model.BotTaskStep{
preStep,
postStep,
}
+45 -45
View File
@@ -6,7 +6,7 @@ package actions
import (
"testing"
bots_model "code.gitea.io/gitea/models/actions"
actions_model "code.gitea.io/gitea/models/actions"
"github.com/stretchr/testify/assert"
)
@@ -14,93 +14,93 @@ import (
func TestFullSteps(t *testing.T) {
tests := []struct {
name string
task *bots_model.BotTask
want []*bots_model.BotTaskStep
task *actions_model.BotTask
want []*actions_model.BotTaskStep
}{
{
name: "regular",
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
task: &actions_model.BotTask{
Steps: []*actions_model.BotTaskStep{
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
},
Status: bots_model.StatusSuccess,
Status: actions_model.StatusSuccess,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
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},
want: []*actions_model.BotTaskStep{
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
},
},
{
name: "failed step",
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},
task: &actions_model.BotTask{
Steps: []*actions_model.BotTaskStep{
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
},
Status: bots_model.StatusFailure,
Status: actions_model.StatusFailure,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
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},
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
{Name: postStepName, Status: bots_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
want: []*actions_model.BotTaskStep{
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 20, Started: 10010, Stopped: 10020},
{Status: actions_model.StatusFailure, LogIndex: 30, LogLength: 60, Started: 10020, Stopped: 10090},
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
},
},
{
name: "first step is running",
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
task: &actions_model.BotTask{
Steps: []*actions_model.BotTaskStep{
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
},
Status: bots_model.StatusRunning,
Status: actions_model.StatusRunning,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
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},
want: []*actions_model.BotTaskStep{
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
{Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0},
{Name: postStepName, Status: actions_model.StatusWaiting, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
},
},
{
name: "first step has canceled",
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{
{Status: bots_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
task: &actions_model.BotTask{
Steps: []*actions_model.BotTaskStep{
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
},
Status: bots_model.StatusFailure,
Status: actions_model.StatusFailure,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
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},
want: []*actions_model.BotTaskStep{
{Name: preStepName, Status: actions_model.StatusFailure, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
{Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
{Name: postStepName, Status: actions_model.StatusFailure, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
},
},
{
name: "empty steps",
task: &bots_model.BotTask{
Steps: []*bots_model.BotTaskStep{},
Status: bots_model.StatusSuccess,
task: &actions_model.BotTask{
Steps: []*actions_model.BotTaskStep{},
Status: actions_model.StatusSuccess,
Started: 10000,
Stopped: 10100,
LogLength: 100,
},
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},
want: []*actions_model.BotTaskStep{
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 100, Started: 10000, Stopped: 10100},
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
},
},
}