1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-03 04:48:25 +00:00

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

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,
}

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},
},
},
}

View File

@@ -7,7 +7,7 @@ import (
"context"
"fmt"
bots_model "code.gitea.io/gitea/models/actions"
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
packages_model "code.gitea.io/gitea/models/packages"
@@ -16,13 +16,13 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
bots_module "code.gitea.io/gitea/modules/actions"
actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
bots_service "code.gitea.io/gitea/services/actions"
actions_service "code.gitea.io/gitea/services/actions"
"github.com/nektos/act/pkg/jobparser"
)
@@ -117,7 +117,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return fmt.Errorf("gitRepo.GetCommit: %v", err)
}
workflows, err := bots_module.DetectWorkflows(commit, input.Event)
workflows, err := actions_module.DetectWorkflows(commit, input.Event)
if err != nil {
return fmt.Errorf("DetectWorkflows: %v", err)
}
@@ -133,7 +133,7 @@ func notify(ctx context.Context, input *notifyInput) error {
}
for id, content := range workflows {
run := bots_model.BotRun{
run := actions_model.BotRun{
Title: commit.Message(),
RepoID: input.Repo.ID,
OwnerID: input.Repo.OwnerID,
@@ -144,7 +144,7 @@ func notify(ctx context.Context, input *notifyInput) error {
IsForkPullRequest: input.PullRequest != nil && input.PullRequest.IsFromFork(),
Event: input.Event,
EventPayload: string(p),
Status: bots_model.StatusWaiting,
Status: actions_model.StatusWaiting,
}
if len(run.Title) > 255 {
run.Title = run.Title[:255] // FIXME: we should use a better method to cut title
@@ -154,15 +154,15 @@ func notify(ctx context.Context, input *notifyInput) error {
log.Error("jobparser.Parse: %v", err)
continue
}
if err := bots_model.InsertRun(&run, jobs); err != nil {
if err := actions_model.InsertRun(&run, jobs); err != nil {
log.Error("InsertRun: %v", err)
continue
}
if jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{RunID: run.ID}); err != nil {
if jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID}); err != nil {
log.Error("FindRunJobs: %v", err)
} else {
for _, job := range jobs {
if err := bots_service.CreateCommitStatus(ctx, job); err != nil {
if err := actions_service.CreateCommitStatus(ctx, job); err != nil {
log.Error("CreateCommitStatus: %v", err)
}
}