From 67c5c8868bdbdc37529cb7e97ee3e90c954531a5 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Mon, 5 Dec 2022 15:57:45 +0800 Subject: [PATCH] refactor: rename import alias --- modules/actions/task_state.go | 36 +++++------ modules/actions/task_state_test.go | 90 +++++++++++++------------- modules/notification/actions/helper.go | 18 +++--- routers/api/actions/runner/runner.go | 34 +++++----- routers/api/actions/runner/unary.go | 12 ++-- routers/api/v1/api.go | 6 +- routers/common/runners.go | 36 +++++------ routers/init.go | 8 +-- routers/web/admin/runners.go | 4 +- routers/web/org/org_runners.go | 4 +- routers/web/repo/actions/actions.go | 10 +-- routers/web/repo/actions/view.go | 30 ++++----- routers/web/repo/http.go | 4 +- routers/web/repo/runners.go | 4 +- services/actions/actions.go | 30 ++++----- services/actions/clear_tasks.go | 22 +++---- services/actions/job_emitter.go | 32 ++++----- services/actions/job_emitter_test.go | 66 +++++++++---------- services/auth/basic.go | 4 +- services/auth/oauth2.go | 4 +- services/cron/tasks_actions.go | 8 +-- services/repository/repository.go | 4 +- 22 files changed, 233 insertions(+), 233 deletions(-) diff --git a/modules/actions/task_state.go b/modules/actions/task_state.go index 199525676f..c15311720c 100644 --- a/modules/actions/task_state.go +++ b/modules/actions/task_state.go @@ -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, } diff --git a/modules/actions/task_state_test.go b/modules/actions/task_state_test.go index 66454e7add..220acb16cd 100644 --- a/modules/actions/task_state_test.go +++ b/modules/actions/task_state_test.go @@ -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}, }, }, } diff --git a/modules/notification/actions/helper.go b/modules/notification/actions/helper.go index f2b27edc9e..bf25395e3f 100644 --- a/modules/notification/actions/helper.go +++ b/modules/notification/actions/helper.go @@ -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) } } diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go index d2fa7dcf17..3ae490c77a 100644 --- a/routers/api/actions/runner/runner.go +++ b/routers/api/actions/runner/runner.go @@ -9,13 +9,13 @@ import ( "fmt" "time" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/actions" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - bot_service "code.gitea.io/gitea/services/actions" + actions_service "code.gitea.io/gitea/services/actions" secret_service "code.gitea.io/gitea/services/secrets" runnerv1 "code.gitea.io/bots-proto-go/runner/v1" @@ -42,7 +42,7 @@ func (s *Service) Register( return nil, errors.New("missing runner token, name") } - runnerToken, err := bots_model.GetRunnerToken(req.Msg.Token) + runnerToken, err := actions_model.GetRunnerToken(req.Msg.Token) if err != nil { return nil, errors.New("runner token not found") } @@ -52,7 +52,7 @@ func (s *Service) Register( } // create new runner - runner := &bots_model.BotRunner{ + runner := &actions_model.BotRunner{ UUID: gouuid.New().String(), Name: req.Msg.Name, OwnerID: runnerToken.OwnerID, @@ -65,13 +65,13 @@ func (s *Service) Register( } // create new runner - if err := bots_model.NewRunner(ctx, runner); err != nil { + if err := actions_model.NewRunner(ctx, runner); err != nil { return nil, errors.New("can't create new runner") } // update token status runnerToken.IsActive = true - if err := bots_model.UpdateRunnerToken(ctx, runnerToken, "is_active"); err != nil { + if err := actions_model.UpdateRunnerToken(ctx, runnerToken, "is_active"); err != nil { return nil, errors.New("can't update runner token status") } @@ -133,7 +133,7 @@ func (s *Service) UpdateTask( } // Get Task first - task, err := bots_model.GetTaskByID(ctx, req.Msg.State.Id) + task, err := actions_model.GetTaskByID(ctx, req.Msg.State.Id) if err != nil { return nil, status.Errorf(codes.Internal, "can't find the task: %v", err) } @@ -146,7 +146,7 @@ func (s *Service) UpdateTask( }), nil } - task, err = bots_model.UpdateTaskByState(req.Msg.State) + task, err = actions_model.UpdateTaskByState(req.Msg.State) if err != nil { return nil, status.Errorf(codes.Internal, "update task: %v", err) } @@ -155,13 +155,13 @@ func (s *Service) UpdateTask( return nil, status.Errorf(codes.Internal, "load job: %v", err) } - if err := bot_service.CreateCommitStatus(ctx, task.Job); err != nil { + if err := actions_service.CreateCommitStatus(ctx, task.Job); err != nil { log.Error("Update commit status failed: %v", err) // go on } if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED { - if err := bot_service.EmitJobsIfReady(task.Job.RunID); err != nil { + if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil { log.Error("Emit ready jobs of run %d: %v", task.Job.RunID, err) } } @@ -181,7 +181,7 @@ func (s *Service) UpdateLog( ) (*connect.Response[runnerv1.UpdateLogResponse], error) { res := connect.NewResponse(&runnerv1.UpdateLogResponse{}) - task, err := bots_model.GetTaskByID(ctx, req.Msg.TaskId) + task, err := actions_model.GetTaskByID(ctx, req.Msg.TaskId) if err != nil { return nil, status.Errorf(codes.Internal, "get task: %v", err) } @@ -203,7 +203,7 @@ func (s *Service) UpdateLog( } task.LogLength += int64(len(rows)) if task.LogIndexes == nil { - task.LogIndexes = &bots_model.LogIndexes{} + task.LogIndexes = &actions_model.LogIndexes{} } for _, n := range ns { *task.LogIndexes = append(*task.LogIndexes, task.LogSize) @@ -221,7 +221,7 @@ func (s *Service) UpdateLog( } } - if err := bots_model.UpdateTask(ctx, task, "log_indexes", "log_length", "log_size", "log_in_storage"); err != nil { + if err := actions_model.UpdateTask(ctx, task, "log_indexes", "log_length", "log_size", "log_in_storage"); err != nil { return nil, status.Errorf(codes.Internal, "update task: %v", err) } if remove != nil { @@ -231,8 +231,8 @@ func (s *Service) UpdateLog( return res, nil } -func pickTask(ctx context.Context, runner *bots_model.BotRunner) (*runnerv1.Task, bool, error) { - t, ok, err := bots_model.CreateTaskForRunner(ctx, runner) +func pickTask(ctx context.Context, runner *actions_model.BotRunner) (*runnerv1.Task, bool, error) { + t, ok, err := actions_model.CreateTaskForRunner(ctx, runner) if err != nil { return nil, false, fmt.Errorf("CreateTaskForRunner: %w", err) } @@ -249,7 +249,7 @@ func pickTask(ctx context.Context, runner *bots_model.BotRunner) (*runnerv1.Task return task, true, nil } -func getSecretsOfTask(ctx context.Context, task *bots_model.BotTask) map[string]string { +func getSecretsOfTask(ctx context.Context, task *actions_model.BotTask) map[string]string { // Returning an error is worse than returning empty secrets. secrets := map[string]string{} @@ -289,7 +289,7 @@ func getSecretsOfTask(ctx context.Context, task *bots_model.BotTask) map[string] return secrets } -func generateTaskContext(t *bots_model.BotTask) *structpb.Struct { +func generateTaskContext(t *actions_model.BotTask) *structpb.Struct { event := map[string]interface{}{} _ = json.Unmarshal([]byte(t.Job.Run.EventPayload), &event) diff --git a/routers/api/actions/runner/unary.go b/routers/api/actions/runner/unary.go index dfa3550ba6..f660739164 100644 --- a/routers/api/actions/runner/unary.go +++ b/routers/api/actions/runner/unary.go @@ -8,7 +8,7 @@ import ( "crypto/subtle" "strings" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" @@ -31,9 +31,9 @@ var WithRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar } uuid := request.Header().Get(uuidHeaderKey) token := request.Header().Get(tokenHeaderKey) - runner, err := bots_model.GetRunnerByUUID(uuid) + runner, err := actions_model.GetRunnerByUUID(uuid) if err != nil { - if _, ok := err.(bots_model.ErrRunnerNotExist); ok { + if _, ok := err.(actions_model.ErrRunnerNotExist); ok { return nil, status.Error(codes.Unauthenticated, "unregistered runner") } return nil, status.Error(codes.Internal, err.Error()) @@ -48,7 +48,7 @@ var WithRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar runner.LastActive = timeutil.TimeStampNow() cols = append(cols, "last_active") } - if err := bots_model.UpdateRunner(ctx, runner, cols...); err != nil { + if err := actions_model.UpdateRunner(ctx, runner, cols...); err != nil { log.Error("can't update runner status: %v", err) } @@ -67,9 +67,9 @@ func getMethodName(req connect.AnyRequest) string { type runnerCtxKey struct{} -func GetRunner(ctx context.Context) *bots_model.BotRunner { +func GetRunner(ctx context.Context) *actions_model.BotRunner { if v := ctx.Value(runnerCtxKey{}); v != nil { - if r, ok := v.(*bots_model.BotRunner); ok { + if r, ok := v.(*actions_model.BotRunner); ok { return r } } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index a9fd0b8444..7e9fa9bd29 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -70,7 +70,7 @@ import ( "reflect" "strings" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/organization" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" @@ -187,9 +187,9 @@ func repoAssignment() func(ctx *context.APIContext) { if ctx.Doer != nil && ctx.Doer.ID == user_model.BotUserID { botTaskID := ctx.Data["BotTaskID"].(int64) - task, err := bots_model.GetTaskByID(ctx, botTaskID) + task, err := actions_model.GetTaskByID(ctx, botTaskID) if err != nil { - ctx.Error(http.StatusInternalServerError, "bots_model.GetTaskByID", err) + ctx.Error(http.StatusInternalServerError, "actions_model.GetTaskByID", err) return } if task.RepoID != repo.ID { diff --git a/routers/common/runners.go b/routers/common/runners.go index c4e4bf9835..ef42c88764 100644 --- a/routers/common/runners.go +++ b/routers/common/runners.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -18,14 +18,14 @@ import ( ) // RunnersList render common runners list page -func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.FindRunnerOptions) { - count, err := bots_model.CountRunners(opts) +func RunnersList(ctx *context.Context, tplName base.TplName, opts actions_model.FindRunnerOptions) { + count, err := actions_model.CountRunners(opts) if err != nil { ctx.ServerError("AdminRunners", err) return } - runners, err := bots_model.FindRunners(opts) + runners, err := actions_model.FindRunners(opts) if err != nil { ctx.ServerError("AdminRunners", err) return @@ -36,10 +36,10 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.Fin } // ownid=0,repo_id=0,means this token is used for global - var token *bots_model.BotRunnerToken - token, err = bots_model.GetUnactivatedRunnerToken(opts.OwnerID, opts.RepoID) - if _, ok := err.(bots_model.ErrRunnerTokenNotExist); ok { - token, err = bots_model.NewRunnerToken(opts.OwnerID, opts.RepoID) + var token *actions_model.BotRunnerToken + token, err = actions_model.GetUnactivatedRunnerToken(opts.OwnerID, opts.RepoID) + if _, ok := err.(actions_model.ErrRunnerTokenNotExist); ok { + token, err = actions_model.NewRunnerToken(opts.OwnerID, opts.RepoID) if err != nil { ctx.ServerError("CreateRunnerToken", err) return @@ -64,7 +64,7 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts bots_model.Fin // RunnerDetails render runner details page func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerID, ownerID, repoID int64) { - runner, err := bots_model.GetRunnerByID(runnerID) + runner, err := actions_model.GetRunnerByID(runnerID) if err != nil { ctx.ServerError("GetRunnerByID", err) return @@ -81,23 +81,23 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerI ctx.Data["Runner"] = runner - opts := bots_model.FindTaskOptions{ + opts := actions_model.FindTaskOptions{ ListOptions: db.ListOptions{ Page: page, PageSize: 30, }, - Status: bots_model.StatusUnknown, // Unknown means all + Status: actions_model.StatusUnknown, // Unknown means all IDOrderDesc: true, RunnerID: runner.ID, } - count, err := bots_model.CountTasks(ctx, opts) + count, err := actions_model.CountTasks(ctx, opts) if err != nil { ctx.ServerError("CountTasks", err) return } - tasks, _, err := bots_model.FindTasks(ctx, opts) + tasks, _, err := actions_model.FindTasks(ctx, opts) if err != nil { ctx.ServerError("FindTasks", err) return @@ -116,7 +116,7 @@ func RunnerDetails(ctx *context.Context, tplName base.TplName, page int, runnerI // RunnerDetailsEditPost response for edit runner details func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64, redirectTo string) { - runner, err := bots_model.GetRunnerByID(runnerID) + runner, err := actions_model.GetRunnerByID(runnerID) if err != nil { log.Warn("RunnerDetailsEditPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL) ctx.ServerError("RunnerDetailsEditPost.GetRunnerByID", err) @@ -132,7 +132,7 @@ func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64 runner.Description = form.Description runner.CustomLabels = strings.Split(form.CustomLabels, ",") - err = bots_model.UpdateRunner(ctx, runner, "description", "custom_labels") + err = actions_model.UpdateRunner(ctx, runner, "description", "custom_labels") if err != nil { log.Warn("RunnerDetailsEditPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL) ctx.Flash.Warning(ctx.Tr("admin.runners.update_runner_failed")) @@ -148,7 +148,7 @@ func RunnerDetailsEditPost(ctx *context.Context, runnerID, ownerID, repoID int64 // RunnerResetRegistrationToken reset registration token func RunnerResetRegistrationToken(ctx *context.Context, ownerID, repoID int64, redirectTo string) { - _, err := bots_model.NewRunnerToken(ownerID, repoID) + _, err := actions_model.NewRunnerToken(ownerID, repoID) if err != nil { ctx.ServerError("ResetRunnerRegistrationToken", err) return @@ -162,14 +162,14 @@ func RunnerResetRegistrationToken(ctx *context.Context, ownerID, repoID int64, r func RunnerDeletePost(ctx *context.Context, runnerID int64, successRedirectTo, failedRedirectTo string, ) { - runner, err := bots_model.GetRunnerByID(runnerID) + runner, err := actions_model.GetRunnerByID(runnerID) if err != nil { log.Warn("DeleteRunnerPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL) ctx.ServerError("DeleteRunnerPost.GetRunnerByID", err) return } - err = bots_model.DeleteRunner(ctx, runner) + err = actions_model.DeleteRunner(ctx, runner) if err != nil { log.Warn("DeleteRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL) ctx.Flash.Warning(ctx.Tr("runners.delete_runner_failed")) diff --git a/routers/init.go b/routers/init.go index cd42645362..24c2c11ff2 100644 --- a/routers/init.go +++ b/routers/init.go @@ -30,13 +30,13 @@ import ( "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" - bots_router "code.gitea.io/gitea/routers/api/actions" + actions_router "code.gitea.io/gitea/routers/api/actions" packages_router "code.gitea.io/gitea/routers/api/packages" apiv1 "code.gitea.io/gitea/routers/api/v1" "code.gitea.io/gitea/routers/common" "code.gitea.io/gitea/routers/private" web_routers "code.gitea.io/gitea/routers/web" - bot_service "code.gitea.io/gitea/services/actions" + actions_service "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/automerge" @@ -174,7 +174,7 @@ func GlobalInitInstalled(ctx context.Context) { auth.Init() svg.Init() - bot_service.Init() + actions_service.Init() // Finally start up the cron cron.NewContext(ctx) @@ -204,7 +204,7 @@ func NormalRoutes(ctx context.Context) *web.Route { if setting.Bots.Enabled { prefix := "/api/bots" - r.Mount(prefix, bots_router.Routes(ctx, prefix)) + r.Mount(prefix, actions_router.Routes(ctx, prefix)) } return r diff --git a/routers/web/admin/runners.go b/routers/web/admin/runners.go index ea29eab898..75b2b85ccb 100644 --- a/routers/web/admin/runners.go +++ b/routers/web/admin/runners.go @@ -7,7 +7,7 @@ package admin import ( "net/url" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -31,7 +31,7 @@ func Runners(ctx *context.Context) { page = 1 } - opts := bots_model.FindRunnerOptions{ + opts := actions_model.FindRunnerOptions{ ListOptions: db.ListOptions{ Page: page, PageSize: 100, diff --git a/routers/web/org/org_runners.go b/routers/web/org/org_runners.go index c2c37b812a..925b71529a 100644 --- a/routers/web/org/org_runners.go +++ b/routers/web/org/org_runners.go @@ -6,7 +6,7 @@ package org import ( "net/url" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/common" @@ -23,7 +23,7 @@ func Runners(ctx *context.Context) { page = 1 } - opts := bots_model.FindRunnerOptions{ + opts := actions_model.FindRunnerOptions{ ListOptions: db.ListOptions{ Page: page, PageSize: 100, diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 44808559e4..3a8c777c24 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -6,7 +6,7 @@ package actions import ( "net/http" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/actions" @@ -74,7 +74,7 @@ func List(ctx *context.Context) { workflow := ctx.FormString("workflow") ctx.Data["CurWorkflow"] = workflow - opts := bots_model.FindRunOptions{ + opts := actions_model.FindRunOptions{ ListOptions: db.ListOptions{ Page: page, PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), @@ -85,7 +85,7 @@ func List(ctx *context.Context) { // open counts opts.IsClosed = util.OptionalBoolFalse - numOpenRuns, err := bots_model.CountRuns(ctx, opts) + numOpenRuns, err := actions_model.CountRuns(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return @@ -94,7 +94,7 @@ func List(ctx *context.Context) { // closed counts opts.IsClosed = util.OptionalBoolTrue - numClosedRuns, err := bots_model.CountRuns(ctx, opts) + numClosedRuns, err := actions_model.CountRuns(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return @@ -108,7 +108,7 @@ func List(ctx *context.Context) { } else { opts.IsClosed = util.OptionalBoolFalse } - runs, total, err := bots_model.FindRuns(ctx, opts) + runs, total, err := actions_model.FindRuns(ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 388a8b8019..856de14c3e 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -9,13 +9,13 @@ import ( "net/http" "time" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/actions" context_module "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/web" - bots_service "code.gitea.io/gitea/services/actions" + actions_service "code.gitea.io/gitea/services/actions" runnerv1 "code.gitea.io/bots-proto-go/runner/v1" "xorm.io/builder" @@ -125,10 +125,10 @@ func ViewPost(ctx *context_module.Context) { }, } - var task *bots_model.BotTask + var task *actions_model.BotTask if current.TaskID > 0 { var err error - task, err = bots_model.GetTaskByID(ctx, current.TaskID) + task, err = actions_model.GetTaskByID(ctx, current.TaskID) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return @@ -206,15 +206,15 @@ func Rerun(ctx *context_module.Context) { } job.TaskID = 0 - job.Status = bots_model.StatusWaiting + job.Status = actions_model.StatusWaiting job.Started = 0 job.Stopped = 0 if err := db.WithTx(ctx, func(ctx context.Context) error { - if _, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped"); err != nil { + if _, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": status}, "task_id", "status", "started", "stopped"); err != nil { return err } - return bots_service.CreateCommitStatus(ctx, job) + return actions_service.CreateCommitStatus(ctx, job) }); err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return @@ -238,9 +238,9 @@ func Cancel(ctx *context_module.Context) { continue } if job.TaskID == 0 { - job.Status = bots_model.StatusCancelled + job.Status = actions_model.StatusCancelled job.Stopped = timeutil.TimeStampNow() - n, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"task_id": 0}, "status", "stopped") + n, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"task_id": 0}, "status", "stopped") if err != nil { return err } @@ -249,10 +249,10 @@ func Cancel(ctx *context_module.Context) { } continue } - if err := bots_model.StopTask(ctx, job.TaskID, bots_model.StatusCancelled); err != nil { + if err := actions_model.StopTask(ctx, job.TaskID, actions_model.StatusCancelled); err != nil { return err } - if err := bots_service.CreateCommitStatus(ctx, job); err != nil { + if err := actions_service.CreateCommitStatus(ctx, job); err != nil { return err } } @@ -268,10 +268,10 @@ func Cancel(ctx *context_module.Context) { // getRunJobs gets the jobs of runIndex, and returns jobs[jobIndex], jobs. // Any error will be written to the ctx. // It never returns a nil job of an empty jobs, if the jobIndex is out of range, it will be treated as 0. -func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*bots_model.BotRunJob, []*bots_model.BotRunJob) { - run, err := bots_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) +func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions_model.BotRunJob, []*actions_model.BotRunJob) { + run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) if err != nil { - if _, ok := err.(bots_model.ErrRunNotExist); ok { + if _, ok := err.(actions_model.ErrRunNotExist); ok { ctx.Error(http.StatusNotFound, err.Error()) return nil, nil } @@ -280,7 +280,7 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*bots_mo } run.Repo = ctx.Repo.Repository - jobs, err := bots_model.GetRunJobsByRunID(ctx, run.ID) + jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return nil, nil diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 0c3400a6ec..a0b33e8749 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -18,7 +18,7 @@ import ( "sync" "time" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" @@ -189,7 +189,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { if ctx.Data["IsBotToken"] == true { taskID := ctx.Data["BotTaskID"].(int64) - task, err := bots_model.GetTaskByID(ctx, taskID) + task, err := actions_model.GetTaskByID(ctx, taskID) if err != nil { ctx.ServerError("GetTaskByID", err) return diff --git a/routers/web/repo/runners.go b/routers/web/repo/runners.go index 58ba651cc3..24e974fe05 100644 --- a/routers/web/repo/runners.go +++ b/routers/web/repo/runners.go @@ -6,7 +6,7 @@ package repo import ( "net/url" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/routers/common" @@ -27,7 +27,7 @@ func Runners(ctx *context.Context) { page = 1 } - opts := bots_model.FindRunnerOptions{ + opts := actions_model.FindRunnerOptions{ ListOptions: db.ListOptions{ Page: page, PageSize: 100, diff --git a/services/actions/actions.go b/services/actions/actions.go index 446df879e7..9f4d5b88eb 100644 --- a/services/actions/actions.go +++ b/services/actions/actions.go @@ -7,13 +7,13 @@ 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" git_model "code.gitea.io/gitea/models/git" repo_model "code.gitea.io/gitea/models/repo" 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/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/queue" @@ -26,26 +26,26 @@ func Init() { } func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository) error { - tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{RepoID: repo.ID}) + tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{RepoID: repo.ID}) if err != nil { return fmt.Errorf("find task of repo %v: %w", repo.ID, err) } if err := db.WithTx(ctx, func(ctx context.Context) error { e := db.GetEngine(ctx) - if _, err := e.Delete(&bots_model.BotTaskStep{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.BotTaskStep{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots task steps of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&bots_model.BotTask{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.BotTask{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots tasks of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&bots_model.BotRunJob{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.BotRunJob{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots run jobs of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&bots_model.BotRun{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.BotRun{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots runs of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&bots_model.BotRunner{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.BotRunner{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots runner of repo %d: %w", repo.ID, err) } return nil @@ -55,7 +55,7 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository // remove logs file after tasks have been deleted, to avoid new log files for _, task := range tasks { - err := bots_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename) + err := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename) if err != nil { log.Error("remove log file %q: %v", task.LogFilename, err) // go on @@ -65,7 +65,7 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository return nil } -func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error { +func CreateCommitStatus(ctx context.Context, job *actions_model.BotRunJob) error { if err := job.LoadAttributes(ctx); err != nil { return fmt.Errorf("load run: %w", err) } @@ -122,15 +122,15 @@ func CreateCommitStatus(ctx context.Context, job *bots_model.BotRunJob) error { return nil } -func toCommitStatus(status bots_model.Status) api.CommitStatusState { +func toCommitStatus(status actions_model.Status) api.CommitStatusState { switch status { - case bots_model.StatusSuccess: + case actions_model.StatusSuccess: return api.CommitStatusSuccess - case bots_model.StatusFailure, bots_model.StatusCancelled, bots_model.StatusSkipped: + case actions_model.StatusFailure, actions_model.StatusCancelled, actions_model.StatusSkipped: return api.CommitStatusFailure - case bots_model.StatusWaiting, bots_model.StatusBlocked: + case actions_model.StatusWaiting, actions_model.StatusBlocked: return api.CommitStatusPending - case bots_model.StatusRunning: + case actions_model.StatusRunning: return api.CommitStatusRunning default: return api.CommitStatusError diff --git a/services/actions/clear_tasks.go b/services/actions/clear_tasks.go index 7bfd42a70c..2800aea502 100644 --- a/services/actions/clear_tasks.go +++ b/services/actions/clear_tasks.go @@ -7,7 +7,7 @@ import ( "context" "time" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" @@ -21,8 +21,8 @@ const ( // StopZombieTasks stops the task which have running status, but haven't been updated for a long time func StopZombieTasks(ctx context.Context) error { - tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{ - Status: bots_model.StatusRunning, + tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{ + Status: actions_model.StatusRunning, UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-zombieTaskTimeout).Unix()), }) if err != nil { @@ -32,7 +32,7 @@ func StopZombieTasks(ctx context.Context) error { for _, task := range tasks { if err := db.WithTx(ctx, func(ctx context.Context) error { - if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil { + if err := actions_model.StopTask(ctx, task.ID, actions_model.StatusFailure); err != nil { return err } if err := task.LoadJob(ctx); err != nil { @@ -49,8 +49,8 @@ func StopZombieTasks(ctx context.Context) error { // StopEndlessTasks stops the tasks which have running status and continuous updates, but don't end for a long time func StopEndlessTasks(ctx context.Context) error { - tasks, _, err := bots_model.FindTasks(ctx, bots_model.FindTaskOptions{ - Status: bots_model.StatusRunning, + tasks, _, err := actions_model.FindTasks(ctx, actions_model.FindTaskOptions{ + Status: actions_model.StatusRunning, StartedBefore: timeutil.TimeStamp(time.Now().Add(-endlessTaskTimeout).Unix()), }) if err != nil { @@ -60,7 +60,7 @@ func StopEndlessTasks(ctx context.Context) error { for _, task := range tasks { if err := db.WithTx(ctx, func(ctx context.Context) error { - if err := bots_model.StopTask(ctx, task.ID, bots_model.StatusFailure); err != nil { + if err := actions_model.StopTask(ctx, task.ID, actions_model.StatusFailure); err != nil { return err } if err := task.LoadJob(ctx); err != nil { @@ -77,8 +77,8 @@ func StopEndlessTasks(ctx context.Context) error { // CancelAbandonedJobs cancels the jobs which have waiting status, but haven't been picked by a runner for a long time func CancelAbandonedJobs(ctx context.Context) error { - jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{ - Statuses: []bots_model.Status{bots_model.StatusWaiting, bots_model.StatusBlocked}, + jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{ + Statuses: []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusBlocked}, UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()), }) if err != nil { @@ -88,10 +88,10 @@ func CancelAbandonedJobs(ctx context.Context) error { now := timeutil.TimeStampNow() for _, job := range jobs { - job.Status = bots_model.StatusCancelled + job.Status = actions_model.StatusCancelled job.Stopped = now if err := db.WithTx(ctx, func(ctx context.Context) error { - if _, err := bots_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil { + if _, err := actions_model.UpdateRunJob(ctx, job, nil, "status", "stopped"); err != nil { return err } return CreateCommitStatus(ctx, job) diff --git a/services/actions/job_emitter.go b/services/actions/job_emitter.go index 2974232d31..d4230c3bcb 100644 --- a/services/actions/job_emitter.go +++ b/services/actions/job_emitter.go @@ -8,7 +8,7 @@ import ( "errors" "fmt" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/queue" @@ -46,11 +46,11 @@ func jobEmitterQueueHandle(data ...queue.Data) []queue.Data { func checkJobsOfRun(ctx context.Context, runID int64) error { return db.WithTx(ctx, func(ctx context.Context) error { - jobs, _, err := bots_model.FindRunJobs(ctx, bots_model.FindRunJobOptions{RunID: runID}) + jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: runID}) if err != nil { return err } - idToJobs := make(map[string][]*bots_model.BotRunJob, len(jobs)) + idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs)) for _, job := range jobs { idToJobs[job.JobID] = append(idToJobs[job.JobID], job) } @@ -59,7 +59,7 @@ func checkJobsOfRun(ctx context.Context, runID int64) error { for _, job := range jobs { if status, ok := updates[job.ID]; ok { job.Status = status - if n, err := bots_model.UpdateRunJob(ctx, job, builder.Eq{"status": bots_model.StatusBlocked}, "status"); err != nil { + if n, err := actions_model.UpdateRunJob(ctx, job, builder.Eq{"status": actions_model.StatusBlocked}, "status"); err != nil { return err } else if n != 1 { return fmt.Errorf("no affected for updating blocked job %v", job.ID) @@ -71,17 +71,17 @@ func checkJobsOfRun(ctx context.Context, runID int64) error { } type jobStatusResolver struct { - statuses map[int64]bots_model.Status + statuses map[int64]actions_model.Status needs map[int64][]int64 } -func newJobStatusResolver(jobs bots_model.RunJobList) *jobStatusResolver { - idToJobs := make(map[string][]*bots_model.BotRunJob, len(jobs)) +func newJobStatusResolver(jobs actions_model.RunJobList) *jobStatusResolver { + idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs)) for _, job := range jobs { idToJobs[job.JobID] = append(idToJobs[job.JobID], job) } - statuses := make(map[int64]bots_model.Status, len(jobs)) + statuses := make(map[int64]actions_model.Status, len(jobs)) needs := make(map[int64][]int64, len(jobs)) for _, job := range jobs { statuses[job.ID] = job.Status @@ -97,8 +97,8 @@ func newJobStatusResolver(jobs bots_model.RunJobList) *jobStatusResolver { } } -func (r *jobStatusResolver) Resolve() map[int64]bots_model.Status { - ret := map[int64]bots_model.Status{} +func (r *jobStatusResolver) Resolve() map[int64]actions_model.Status { + ret := map[int64]actions_model.Status{} for i := 0; i < len(r.statuses); i++ { updated := r.resolve() if len(updated) == 0 { @@ -112,10 +112,10 @@ func (r *jobStatusResolver) Resolve() map[int64]bots_model.Status { return ret } -func (r *jobStatusResolver) resolve() map[int64]bots_model.Status { - ret := map[int64]bots_model.Status{} +func (r *jobStatusResolver) resolve() map[int64]actions_model.Status { + ret := map[int64]actions_model.Status{} for id, status := range r.statuses { - if status != bots_model.StatusBlocked { + if status != actions_model.StatusBlocked { continue } allDone, allSucceed := true, true @@ -124,15 +124,15 @@ func (r *jobStatusResolver) resolve() map[int64]bots_model.Status { if !needStatus.IsDone() { allDone = false } - if needStatus.In(bots_model.StatusFailure, bots_model.StatusCancelled, bots_model.StatusSkipped) { + if needStatus.In(actions_model.StatusFailure, actions_model.StatusCancelled, actions_model.StatusSkipped) { allSucceed = false } } if allDone { if allSucceed { - ret[id] = bots_model.StatusWaiting + ret[id] = actions_model.StatusWaiting } else { - ret[id] = bots_model.StatusSkipped + ret[id] = actions_model.StatusSkipped } } } diff --git a/services/actions/job_emitter_test.go b/services/actions/job_emitter_test.go index 03928114cf..ecdf170fec 100644 --- a/services/actions/job_emitter_test.go +++ b/services/actions/job_emitter_test.go @@ -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,61 +14,61 @@ import ( func Test_jobStatusResolver_Resolve(t *testing.T) { tests := []struct { name string - jobs bots_model.RunJobList - want map[int64]bots_model.Status + jobs actions_model.RunJobList + want map[int64]actions_model.Status }{ { name: "no blocked", - jobs: bots_model.RunJobList{ - {ID: 1, JobID: "1", Status: bots_model.StatusWaiting, Needs: []string{}}, - {ID: 2, JobID: "2", Status: bots_model.StatusWaiting, Needs: []string{}}, - {ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}}, + jobs: actions_model.RunJobList{ + {ID: 1, JobID: "1", Status: actions_model.StatusWaiting, Needs: []string{}}, + {ID: 2, JobID: "2", Status: actions_model.StatusWaiting, Needs: []string{}}, + {ID: 3, JobID: "3", Status: actions_model.StatusWaiting, Needs: []string{}}, }, - want: map[int64]bots_model.Status{}, + want: map[int64]actions_model.Status{}, }, { name: "single blocked", - jobs: bots_model.RunJobList{ - {ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}}, - {ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}}, - {ID: 3, JobID: "3", Status: bots_model.StatusWaiting, Needs: []string{}}, + jobs: actions_model.RunJobList{ + {ID: 1, JobID: "1", Status: actions_model.StatusSuccess, Needs: []string{}}, + {ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}}, + {ID: 3, JobID: "3", Status: actions_model.StatusWaiting, Needs: []string{}}, }, - want: map[int64]bots_model.Status{ - 2: bots_model.StatusWaiting, + want: map[int64]actions_model.Status{ + 2: actions_model.StatusWaiting, }, }, { name: "multiple blocked", - jobs: bots_model.RunJobList{ - {ID: 1, JobID: "1", Status: bots_model.StatusSuccess, Needs: []string{}}, - {ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}}, - {ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"1"}}, + jobs: actions_model.RunJobList{ + {ID: 1, JobID: "1", Status: actions_model.StatusSuccess, Needs: []string{}}, + {ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}}, + {ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"1"}}, }, - want: map[int64]bots_model.Status{ - 2: bots_model.StatusWaiting, - 3: bots_model.StatusWaiting, + want: map[int64]actions_model.Status{ + 2: actions_model.StatusWaiting, + 3: actions_model.StatusWaiting, }, }, { name: "chain blocked", - jobs: bots_model.RunJobList{ - {ID: 1, JobID: "1", Status: bots_model.StatusFailure, Needs: []string{}}, - {ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}}, - {ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}}, + jobs: actions_model.RunJobList{ + {ID: 1, JobID: "1", Status: actions_model.StatusFailure, Needs: []string{}}, + {ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}}, + {ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"2"}}, }, - want: map[int64]bots_model.Status{ - 2: bots_model.StatusSkipped, - 3: bots_model.StatusSkipped, + want: map[int64]actions_model.Status{ + 2: actions_model.StatusSkipped, + 3: actions_model.StatusSkipped, }, }, { name: "loop need", - jobs: bots_model.RunJobList{ - {ID: 1, JobID: "1", Status: bots_model.StatusBlocked, Needs: []string{"3"}}, - {ID: 2, JobID: "2", Status: bots_model.StatusBlocked, Needs: []string{"1"}}, - {ID: 3, JobID: "3", Status: bots_model.StatusBlocked, Needs: []string{"2"}}, + jobs: actions_model.RunJobList{ + {ID: 1, JobID: "1", Status: actions_model.StatusBlocked, Needs: []string{"3"}}, + {ID: 2, JobID: "2", Status: actions_model.StatusBlocked, Needs: []string{"1"}}, + {ID: 3, JobID: "3", Status: actions_model.StatusBlocked, Needs: []string{"2"}}, }, - want: map[int64]bots_model.Status{}, + want: map[int64]actions_model.Status{}, }, } for _, tt := range tests { diff --git a/services/auth/basic.go b/services/auth/basic.go index ca6ba17c63..f1d5d523a3 100644 --- a/services/auth/basic.go +++ b/services/auth/basic.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" @@ -109,7 +109,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore } // check task token - task, err := bots_model.GetRunningTaskByToken(db.DefaultContext, authToken) + task, err := actions_model.GetRunningTaskByToken(db.DefaultContext, authToken) if err == nil && task != nil { log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID) diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go index 51c49aa159..ef1aeb936c 100644 --- a/services/auth/oauth2.go +++ b/services/auth/oauth2.go @@ -9,7 +9,7 @@ import ( "strings" "time" - bots_model "code.gitea.io/gitea/models/actions" + actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" @@ -94,7 +94,7 @@ func (o *OAuth2) userIDFromToken(req *http.Request, store DataStore) int64 { if err != nil { if auth_model.IsErrAccessTokenNotExist(err) { // check task token - task, err := bots_model.GetRunningTaskByToken(db.DefaultContext, tokenSHA) + task, err := actions_model.GetRunningTaskByToken(db.DefaultContext, tokenSHA) if err == nil && task != nil { log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID) diff --git a/services/cron/tasks_actions.go b/services/cron/tasks_actions.go index d4acfa7061..f1b2f07013 100644 --- a/services/cron/tasks_actions.go +++ b/services/cron/tasks_actions.go @@ -7,7 +7,7 @@ import ( "context" user_model "code.gitea.io/gitea/models/user" - bots_service "code.gitea.io/gitea/services/actions" + actions_service "code.gitea.io/gitea/services/actions" ) func initBotsTasks() { @@ -22,7 +22,7 @@ func registerStopZombieTasks() { RunAtStart: true, Schedule: "@every 5m", }, func(ctx context.Context, _ *user_model.User, cfg Config) error { - return bots_service.StopZombieTasks(ctx) + return actions_service.StopZombieTasks(ctx) }) } @@ -32,7 +32,7 @@ func registerStopEndlessTasks() { RunAtStart: true, Schedule: "@every 30m", }, func(ctx context.Context, _ *user_model.User, cfg Config) error { - return bots_service.StopEndlessTasks(ctx) + return actions_service.StopEndlessTasks(ctx) }) } @@ -42,6 +42,6 @@ func registerCancelAbandonedJobs() { RunAtStart: true, Schedule: "@every 6h", }, func(ctx context.Context, _ *user_model.User, cfg Config) error { - return bots_service.CancelAbandonedJobs(ctx) + return actions_service.CancelAbandonedJobs(ctx) }) } diff --git a/services/repository/repository.go b/services/repository/repository.go index 724f3463ae..5e7c204a9b 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -20,7 +20,7 @@ import ( "code.gitea.io/gitea/modules/notification" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" - bots_service "code.gitea.io/gitea/services/actions" + actions_service "code.gitea.io/gitea/services/actions" pull_service "code.gitea.io/gitea/services/pull" ) @@ -53,7 +53,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod } // deletes bots resource after the repo has been deleted, to avoid new bots tasks - if err := bots_service.DeleteResourceOfRepository(ctx, repo); err != nil { + if err := actions_service.DeleteResourceOfRepository(ctx, repo); err != nil { log.Error("delete bots resource failed: %v", err) }