From c07d0c17688d1701ef887a3261847b033bc2fdbe Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 6 Dec 2022 13:48:09 +0800 Subject: [PATCH] refactor: rename model --- models/actions/run.go | 34 ++++++------- models/actions/run_job.go | 36 +++++++------- models/actions/run_job_list.go | 18 +++---- models/actions/run_list.go | 4 +- models/actions/runner.go | 46 ++++++++--------- models/actions/runner_list.go | 2 +- models/actions/runner_token.go | 20 ++++---- models/actions/status.go | 2 +- models/actions/task.go | 68 +++++++++++++------------- models/actions/task_list.go | 8 +-- models/actions/task_step.go | 12 ++--- modules/actions/task_state.go | 18 +++---- modules/actions/task_state_test.go | 34 ++++++------- modules/notification/actions/helper.go | 6 +-- routers/api/actions/runner/runner.go | 8 +-- routers/api/actions/runner/unary.go | 4 +- routers/common/runners.go | 2 +- routers/web/repo/actions/view.go | 4 +- services/actions/actions.go | 16 +++--- services/actions/job_emitter.go | 6 +-- services/actions/job_emitter_test.go | 12 ++--- 21 files changed, 180 insertions(+), 180 deletions(-) diff --git a/models/actions/run.go b/models/actions/run.go index ccebf04f40..50c468d85a 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -21,8 +21,8 @@ import ( "xorm.io/builder" ) -// BotRun represents a run of a workflow file -type BotRun struct { +// ActionRun represents a run of a workflow file +type ActionRun struct { ID int64 Title string RepoID int64 `xorm:"index unique(repo_index)"` @@ -45,16 +45,16 @@ type BotRun struct { } func init() { - db.RegisterModel(new(BotRun)) - db.RegisterModel(new(BotRunIndex)) + db.RegisterModel(new(ActionRun)) + db.RegisterModel(new(ActionRunIndex)) } -func (run *BotRun) HTMLURL() string { +func (run *ActionRun) HTMLURL() string { return fmt.Sprintf("%s/bots/runs/%d", run.Repo.HTMLURL(), run.Index) } // LoadAttributes load Repo TriggerUser if not loaded -func (run *BotRun) LoadAttributes(ctx context.Context) error { +func (run *ActionRun) LoadAttributes(ctx context.Context) error { if run == nil { return nil } @@ -81,7 +81,7 @@ func (run *BotRun) LoadAttributes(ctx context.Context) error { return nil } -func (run *BotRun) TakeTime() time.Duration { +func (run *ActionRun) TakeTime() time.Duration { if run.Started == 0 { return 0 } @@ -93,7 +93,7 @@ func (run *BotRun) TakeTime() time.Duration { return time.Since(started).Truncate(time.Second) } -func (run *BotRun) GetPushEventPayload() (*api.PushPayload, error) { +func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) { if run.Event == webhook.HookEventPush { var payload api.PushPayload if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil { @@ -129,7 +129,7 @@ func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) err } // InsertRun inserts a bot run -func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error { +func InsertRun(run *ActionRun, jobs []*jobparser.SingleWorkflow) error { ctx, commiter, err := db.TxContext(db.DefaultContext) if err != nil { return err @@ -162,7 +162,7 @@ func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error { return err } - runJobs := make([]*BotRunJob, 0, len(jobs)) + runJobs := make([]*ActionRunJob, 0, len(jobs)) for _, v := range jobs { id, job := v.Job() needs := job.Needs() @@ -172,7 +172,7 @@ func InsertRun(run *BotRun, jobs []*jobparser.SingleWorkflow) error { if len(needs) > 0 { status = StatusBlocked } - runJobs = append(runJobs, &BotRunJob{ + runJobs = append(runJobs, &ActionRunJob{ RunID: run.ID, RepoID: run.RepoID, OwnerID: run.OwnerID, @@ -207,8 +207,8 @@ func (err ErrRunNotExist) Error() string { return fmt.Sprintf("run [%d] is not exist", err.ID) } -func GetRunByID(ctx context.Context, id int64) (*BotRun, error) { - var run BotRun +func GetRunByID(ctx context.Context, id int64) (*ActionRun, error) { + var run ActionRun has, err := db.GetEngine(ctx).Where("id=?", id).Get(&run) if err != nil { return nil, err @@ -221,8 +221,8 @@ func GetRunByID(ctx context.Context, id int64) (*BotRun, error) { return &run, nil } -func GetRunByIndex(ctx context.Context, repoID, index int64) (*BotRun, error) { - run := &BotRun{ +func GetRunByIndex(ctx context.Context, repoID, index int64) (*ActionRun, error) { + run := &ActionRun{ RepoID: repoID, Index: index, } @@ -239,7 +239,7 @@ func GetRunByIndex(ctx context.Context, repoID, index int64) (*BotRun, error) { return run, nil } -func UpdateRun(ctx context.Context, run *BotRun, cols ...string) error { +func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error { sess := db.GetEngine(ctx).ID(run.ID) if len(cols) > 0 { sess.Cols(cols...) @@ -268,4 +268,4 @@ func UpdateRun(ctx context.Context, run *BotRun, cols ...string) error { return err } -type BotRunIndex db.ResourceIndex +type ActionRunIndex db.ResourceIndex diff --git a/models/actions/run_job.go b/models/actions/run_job.go index 6855a0a11b..54e4ac8702 100644 --- a/models/actions/run_job.go +++ b/models/actions/run_job.go @@ -15,14 +15,14 @@ import ( "xorm.io/builder" ) -// BotRunJob represents a job of a run -type BotRunJob struct { +// ActionRunJob represents a job of a run +type ActionRunJob struct { ID int64 - RunID int64 `xorm:"index"` - Run *BotRun `xorm:"-"` - RepoID int64 `xorm:"index"` - OwnerID int64 `xorm:"index"` - CommitSHA string `xorm:"index"` + RunID int64 `xorm:"index"` + Run *ActionRun `xorm:"-"` + RepoID int64 `xorm:"index"` + OwnerID int64 `xorm:"index"` + CommitSHA string `xorm:"index"` IsForkPullRequest bool Name string Attempt int64 @@ -39,10 +39,10 @@ type BotRunJob struct { } func init() { - db.RegisterModel(new(BotRunJob)) + db.RegisterModel(new(ActionRunJob)) } -func (job *BotRunJob) TakeTime() time.Duration { +func (job *ActionRunJob) TakeTime() time.Duration { if job.Started == 0 { return 0 } @@ -54,7 +54,7 @@ func (job *BotRunJob) TakeTime() time.Duration { return time.Since(started).Truncate(time.Second) } -func (job *BotRunJob) LoadRun(ctx context.Context) error { +func (job *ActionRunJob) LoadRun(ctx context.Context) error { if job.Run == nil { run, err := GetRunByID(ctx, job.RunID) if err != nil { @@ -66,7 +66,7 @@ func (job *BotRunJob) LoadRun(ctx context.Context) error { } // LoadAttributes load Run if not loaded -func (job *BotRunJob) LoadAttributes(ctx context.Context) error { +func (job *ActionRunJob) LoadAttributes(ctx context.Context) error { if job == nil { return nil } @@ -87,8 +87,8 @@ func (err ErrRunJobNotExist) Error() string { return fmt.Sprintf("run job [%d] is not exist", err.ID) } -func GetRunJobByID(ctx context.Context, id int64) (*BotRunJob, error) { - var job BotRunJob +func GetRunJobByID(ctx context.Context, id int64) (*ActionRunJob, error) { + var job ActionRunJob has, err := db.GetEngine(ctx).Where("id=?", id).Get(&job) if err != nil { return nil, err @@ -101,15 +101,15 @@ func GetRunJobByID(ctx context.Context, id int64) (*BotRunJob, error) { return &job, nil } -func GetRunJobsByRunID(ctx context.Context, runID int64) ([]*BotRunJob, error) { - var jobs []*BotRunJob +func GetRunJobsByRunID(ctx context.Context, runID int64) ([]*ActionRunJob, error) { + var jobs []*ActionRunJob if err := db.GetEngine(ctx).Where("run_id=?", runID).OrderBy("id").Find(&jobs); err != nil { return nil, err } return jobs, nil } -func UpdateRunJob(ctx context.Context, job *BotRunJob, cond builder.Cond, cols ...string) (int64, error) { +func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, cols ...string) (int64, error) { e := db.GetEngine(ctx) sess := e.ID(job.ID) @@ -144,7 +144,7 @@ func UpdateRunJob(ctx context.Context, job *BotRunJob, cond builder.Cond, cols . runStatus := aggregateJobStatus(jobs) - run := &BotRun{ + run := &ActionRun{ ID: job.RunID, Status: runStatus, } @@ -154,7 +154,7 @@ func UpdateRunJob(ctx context.Context, job *BotRunJob, cond builder.Cond, cols . return affected, UpdateRun(ctx, run) } -func aggregateJobStatus(jobs []*BotRunJob) Status { +func aggregateJobStatus(jobs []*ActionRunJob) Status { allDone := true allWaiting := true hasFailure := false diff --git a/models/actions/run_job_list.go b/models/actions/run_job_list.go index 3a51d4832b..1904354b4f 100644 --- a/models/actions/run_job_list.go +++ b/models/actions/run_job_list.go @@ -12,9 +12,9 @@ import ( "xorm.io/builder" ) -type RunJobList []*BotRunJob +type ActionJobList []*ActionRunJob -func (jobs RunJobList) GetRunIDs() []int64 { +func (jobs ActionJobList) GetRunIDs() []int64 { runIDsMap := make(map[int64]struct{}) for _, j := range jobs { if j.RunID == 0 { @@ -29,9 +29,9 @@ func (jobs RunJobList) GetRunIDs() []int64 { return runIDs } -func (jobs RunJobList) LoadRuns(ctx context.Context, withRepo bool) error { +func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error { runIDs := jobs.GetRunIDs() - runs := make(map[int64]*BotRun, len(runIDs)) + runs := make(map[int64]*ActionRun, len(runIDs)) if err := db.GetEngine(ctx).In("id", runIDs).Find(&runs); err != nil { return err } @@ -41,7 +41,7 @@ func (jobs RunJobList) LoadRuns(ctx context.Context, withRepo bool) error { } } if withRepo { - var runsList RunList = make([]*BotRun, 0, len(runs)) + var runsList RunList = make([]*ActionRun, 0, len(runs)) for _, r := range runs { runsList = append(runsList, r) } @@ -50,7 +50,7 @@ func (jobs RunJobList) LoadRuns(ctx context.Context, withRepo bool) error { return nil } -func (jobs RunJobList) LoadAttributes(ctx context.Context, withRepo bool) error { +func (jobs ActionJobList) LoadAttributes(ctx context.Context, withRepo bool) error { return jobs.LoadRuns(ctx, withRepo) } @@ -87,16 +87,16 @@ func (opts FindRunJobOptions) toConds() builder.Cond { return cond } -func FindRunJobs(ctx context.Context, opts FindRunJobOptions) (RunJobList, int64, error) { +func FindRunJobs(ctx context.Context, opts FindRunJobOptions) (ActionJobList, int64, error) { e := db.GetEngine(ctx).Where(opts.toConds()) if opts.PageSize > 0 && opts.Page >= 1 { e.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } - var tasks RunJobList + var tasks ActionJobList total, err := e.FindAndCount(&tasks) return tasks, total, err } func CountRunJobs(ctx context.Context, opts FindRunJobOptions) (int64, error) { - return db.GetEngine(ctx).Where(opts.toConds()).Count(new(BotRunJob)) + return db.GetEngine(ctx).Where(opts.toConds()).Count(new(ActionRunJob)) } diff --git a/models/actions/run_list.go b/models/actions/run_list.go index 3314353b31..841455260c 100644 --- a/models/actions/run_list.go +++ b/models/actions/run_list.go @@ -14,7 +14,7 @@ import ( "xorm.io/builder" ) -type RunList []*BotRun +type RunList []*ActionRun // GetUserIDs returns a slice of user's id func (runs RunList) GetUserIDs() []int64 { @@ -110,5 +110,5 @@ func FindRuns(ctx context.Context, opts FindRunOptions) (RunList, int64, error) } func CountRuns(ctx context.Context, opts FindRunOptions) (int64, error) { - return db.GetEngine(ctx).Where(opts.toConds()).Count(new(BotRun)) + return db.GetEngine(ctx).Where(opts.toConds()).Count(new(ActionRun)) } diff --git a/models/actions/runner.go b/models/actions/runner.go index 63b2ec1b9c..b45fbe7dcb 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -33,8 +33,8 @@ func (err ErrRunnerNotExist) Error() string { return fmt.Sprintf("Bot runner token [%s] is not exist", err.Token) } -// BotRunner represents runner machines -type BotRunner struct { +// ActionRunner represents runner machines +type ActionRunner struct { ID int64 UUID string `xorm:"CHAR(36) UNIQUE"` Name string `xorm:"VARCHAR(32)"` @@ -64,7 +64,7 @@ type BotRunner struct { Deleted timeutil.TimeStamp `xorm:"deleted"` } -func (r *BotRunner) OwnType() string { +func (r *ActionRunner) OwnType() string { if r.OwnerID == 0 { return "Global" } @@ -75,7 +75,7 @@ func (r *BotRunner) OwnType() string { return r.Repo.FullName() } -func (r *BotRunner) Status() runnerv1.RunnerStatus { +func (r *ActionRunner) Status() runnerv1.RunnerStatus { if time.Since(r.LastOnline.AsTime()) > time.Minute { return runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE } @@ -85,11 +85,11 @@ func (r *BotRunner) Status() runnerv1.RunnerStatus { return runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE } -func (r *BotRunner) StatusName() string { +func (r *ActionRunner) StatusName() string { return strings.ToLower(strings.TrimPrefix(r.Status().String(), "RUNNER_STATUS_")) } -func (r *BotRunner) IsOnline() bool { +func (r *ActionRunner) IsOnline() bool { status := r.Status() if status == runnerv1.RunnerStatus_RUNNER_STATUS_IDLE || status == runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE { return true @@ -98,12 +98,12 @@ func (r *BotRunner) IsOnline() bool { } // AllLabels returns agent and custom labels -func (r *BotRunner) AllLabels() []string { +func (r *ActionRunner) AllLabels() []string { return append(r.AgentLabels, r.CustomLabels...) } // Editable checks if the runner is editable by the user -func (r *BotRunner) Editable(ownerID, repoID int64) bool { +func (r *ActionRunner) Editable(ownerID, repoID int64) bool { if ownerID == 0 && repoID == 0 { return true } @@ -114,7 +114,7 @@ func (r *BotRunner) Editable(ownerID, repoID int64) bool { } // LoadAttributes loads the attributes of the runner -func (r *BotRunner) LoadAttributes(ctx context.Context) error { +func (r *ActionRunner) LoadAttributes(ctx context.Context) error { if r.OwnerID > 0 { var user user_model.User has, err := db.GetEngine(ctx).ID(r.OwnerID).Get(&user) @@ -138,13 +138,13 @@ func (r *BotRunner) LoadAttributes(ctx context.Context) error { return nil } -func (r *BotRunner) GenerateToken() (err error) { +func (r *ActionRunner) GenerateToken() (err error) { r.Token, r.TokenSalt, r.TokenHash, _, err = generateSaltedToken() return err } func init() { - db.RegisterModel(&BotRunner{}) + db.RegisterModel(&ActionRunner{}) } type FindRunnerOptions struct { @@ -195,7 +195,7 @@ func (opts FindRunnerOptions) toOrder() string { func CountRunners(opts FindRunnerOptions) (int64, error) { return db.GetEngine(db.DefaultContext). - Table(BotRunner{}). + Table(ActionRunner{}). Where(opts.toCond()). OrderBy(opts.toOrder()). Count() @@ -212,8 +212,8 @@ func FindRunners(opts FindRunnerOptions) (runners RunnerList, err error) { } // GetUsableRunner returns the usable runner -func GetUsableRunner(opts FindRunnerOptions) (*BotRunner, error) { - var runner BotRunner +func GetUsableRunner(opts FindRunnerOptions) (*ActionRunner, error) { + var runner ActionRunner has, err := db.GetEngine(db.DefaultContext). Where(opts.toCond()). Asc("last_online"). @@ -229,8 +229,8 @@ func GetUsableRunner(opts FindRunnerOptions) (*BotRunner, error) { } // GetRunnerByUUID returns a bot runner via uuid -func GetRunnerByUUID(uuid string) (*BotRunner, error) { - var runner BotRunner +func GetRunnerByUUID(uuid string) (*ActionRunner, error) { + var runner ActionRunner has, err := db.GetEngine(db.DefaultContext).Where("uuid=?", uuid).Get(&runner) if err != nil { return nil, err @@ -243,8 +243,8 @@ func GetRunnerByUUID(uuid string) (*BotRunner, error) { } // GetRunnerByID returns a bot runner via id -func GetRunnerByID(id int64) (*BotRunner, error) { - var runner BotRunner +func GetRunnerByID(id int64) (*ActionRunner, error) { + var runner ActionRunner has, err := db.GetEngine(db.DefaultContext).Where("id=?", id).Get(&runner) if err != nil { return nil, err @@ -257,7 +257,7 @@ func GetRunnerByID(id int64) (*BotRunner, error) { } // UpdateRunner updates runner's information. -func UpdateRunner(ctx context.Context, r *BotRunner, cols ...string) error { +func UpdateRunner(ctx context.Context, r *ActionRunner, cols ...string) error { e := db.GetEngine(ctx) var err error if len(cols) == 0 { @@ -269,15 +269,15 @@ func UpdateRunner(ctx context.Context, r *BotRunner, cols ...string) error { } // DeleteRunner deletes a runner by given ID. -func DeleteRunner(ctx context.Context, r *BotRunner) error { +func DeleteRunner(ctx context.Context, r *ActionRunner) error { e := db.GetEngine(ctx) _, err := e.Delete(r) return err } // FindRunnersByRepoID returns all workers for the repository -func FindRunnersByRepoID(repoID int64) ([]*BotRunner, error) { - var runners []*BotRunner +func FindRunnersByRepoID(repoID int64) ([]*ActionRunner, error) { + var runners []*ActionRunner err := db.GetEngine(db.DefaultContext).Where("repo_id=? OR repo_id=0", repoID). Find(&runners) if err != nil { @@ -288,7 +288,7 @@ func FindRunnersByRepoID(repoID int64) ([]*BotRunner, error) { } // NewRunner creates new runner. -func NewRunner(ctx context.Context, t *BotRunner) error { +func NewRunner(ctx context.Context, t *ActionRunner) error { _, err := db.GetEngine(ctx).Insert(t) return err } diff --git a/models/actions/runner_list.go b/models/actions/runner_list.go index aee5dc5d85..596fe20a09 100644 --- a/models/actions/runner_list.go +++ b/models/actions/runner_list.go @@ -12,7 +12,7 @@ import ( "code.gitea.io/gitea/modules/container" ) -type RunnerList []*BotRunner +type RunnerList []*ActionRunner // GetUserIDs returns a slice of user's id func (runners RunnerList) GetUserIDs() []int64 { diff --git a/models/actions/runner_token.go b/models/actions/runner_token.go index 1e40e64507..a71bbb6251 100644 --- a/models/actions/runner_token.go +++ b/models/actions/runner_token.go @@ -23,8 +23,8 @@ func (err ErrRunnerTokenNotExist) Error() string { return fmt.Sprintf("runner token [%s] is not exist", err.Token) } -// BotRunnerToken represents runner tokens -type BotRunnerToken struct { +// ActionRunnerToken represents runner tokens +type ActionRunnerToken struct { ID int64 Token string `xorm:"UNIQUE"` OwnerID int64 `xorm:"index"` // org level runner, 0 means system @@ -39,12 +39,12 @@ type BotRunnerToken struct { } func init() { - db.RegisterModel(new(BotRunnerToken)) + db.RegisterModel(new(ActionRunnerToken)) } // GetRunnerToken returns a bot runner via token -func GetRunnerToken(token string) (*BotRunnerToken, error) { - var runnerToken BotRunnerToken +func GetRunnerToken(token string) (*ActionRunnerToken, error) { + var runnerToken ActionRunnerToken has, err := db.GetEngine(db.DefaultContext).Where("token=?", token).Get(&runnerToken) if err != nil { return nil, err @@ -57,7 +57,7 @@ func GetRunnerToken(token string) (*BotRunnerToken, error) { } // UpdateRunnerToken updates runner token information. -func UpdateRunnerToken(ctx context.Context, r *BotRunnerToken, cols ...string) (err error) { +func UpdateRunnerToken(ctx context.Context, r *ActionRunnerToken, cols ...string) (err error) { e := db.GetEngine(ctx) if len(cols) == 0 { @@ -69,12 +69,12 @@ func UpdateRunnerToken(ctx context.Context, r *BotRunnerToken, cols ...string) ( } // NewRunnerToken creates a new runner token -func NewRunnerToken(ownerID, repoID int64) (*BotRunnerToken, error) { +func NewRunnerToken(ownerID, repoID int64) (*ActionRunnerToken, error) { token, err := util.CryptoRandomString(40) if err != nil { return nil, err } - runnerToken := &BotRunnerToken{ + runnerToken := &ActionRunnerToken{ OwnerID: ownerID, RepoID: repoID, IsActive: false, @@ -85,8 +85,8 @@ func NewRunnerToken(ownerID, repoID int64) (*BotRunnerToken, error) { } // GetUnactivatedRunnerToken returns a unactivated runner token -func GetUnactivatedRunnerToken(ownerID, repoID int64) (*BotRunnerToken, error) { - var runnerToken BotRunnerToken +func GetUnactivatedRunnerToken(ownerID, repoID int64) (*ActionRunnerToken, error) { + var runnerToken ActionRunnerToken has, err := db.GetEngine(db.DefaultContext).Where("owner_id=? AND repo_id=? AND is_active=?", ownerID, repoID, false).OrderBy("id DESC").Get(&runnerToken) if err != nil { return nil, err diff --git a/models/actions/status.go b/models/actions/status.go index acffde4f43..68566e4fcd 100644 --- a/models/actions/status.go +++ b/models/actions/status.go @@ -5,7 +5,7 @@ package actions import runnerv1 "code.gitea.io/actions-proto-go/runner/v1" -// Status represents the status of BotRun, BotRunJob, BotTask, or BotTaskStep +// Status represents the status of ActionRun, ActionRunJob, ActionTask, or ActionTaskStep type Status int const ( diff --git a/models/actions/task.go b/models/actions/task.go index b9c75e74af..c577938a3f 100644 --- a/models/actions/task.go +++ b/models/actions/task.go @@ -28,12 +28,12 @@ import ( "xorm.io/builder" ) -// BotTask represents a distribution of job -type BotTask struct { +// ActionTask represents a distribution of job +type ActionTask struct { ID int64 JobID int64 - Job *BotRunJob `xorm:"-"` - Steps []*BotTaskStep `xorm:"-"` + Job *ActionRunJob `xorm:"-"` + Steps []*ActionTaskStep `xorm:"-"` Attempt int64 RunnerID int64 `xorm:"index"` Status Status `xorm:"index"` @@ -64,7 +64,7 @@ type BotTask struct { var successfulTokenTaskCache *lru.Cache func init() { - db.RegisterModel(new(BotTask), func() error { + db.RegisterModel(new(ActionTask), func() error { if setting.SuccessfulTokensCacheSize > 0 { var err error successfulTokenTaskCache, err = lru.New(setting.SuccessfulTokensCacheSize) @@ -78,7 +78,7 @@ func init() { }) } -func (task *BotTask) TakeTime() time.Duration { +func (task *ActionTask) TakeTime() time.Duration { if task.Started == 0 { return 0 } @@ -90,15 +90,15 @@ func (task *BotTask) TakeTime() time.Duration { return time.Since(started).Truncate(time.Second) } -func (task *BotTask) IsStopped() bool { +func (task *ActionTask) IsStopped() bool { return task.Stopped > 0 } -func (task *BotTask) GetRepo() string { +func (task *ActionTask) GetRepo() string { return "xxxx" } -func (task *BotTask) GetCommitSHA() string { +func (task *ActionTask) GetCommitSHA() string { if task.Job == nil { return "" } @@ -109,7 +109,7 @@ func (task *BotTask) GetCommitSHA() string { return task.Job.Run.CommitSHA } -func (task *BotTask) GetCommitSHAShort() string { +func (task *ActionTask) GetCommitSHAShort() string { commitSHA := task.GetCommitSHA() if len(commitSHA) > 8 { return commitSHA[:8] @@ -117,14 +117,14 @@ func (task *BotTask) GetCommitSHAShort() string { return commitSHA } -func (task *BotTask) GetBuildViewLink() string { +func (task *ActionTask) GetBuildViewLink() string { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { return "" } return task.Job.Run.Repo.Link() + "/bots/runs/" + strconv.FormatInt(task.ID, 10) } -func (task *BotTask) GetCommitLink() string { +func (task *ActionTask) GetCommitLink() string { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { return "" } @@ -134,21 +134,21 @@ func (task *BotTask) GetCommitLink() string { return "" } -func (task *BotTask) GetRepoName() string { +func (task *ActionTask) GetRepoName() string { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { return "" } return task.Job.Run.Repo.FullName() } -func (task *BotTask) GetRepoLink() string { +func (task *ActionTask) GetRepoLink() string { if task.Job == nil || task.Job.Run == nil || task.Job.Run.Repo == nil { return "" } return task.Job.Run.Repo.Link() } -func (task *BotTask) LoadJob(ctx context.Context) error { +func (task *ActionTask) LoadJob(ctx context.Context) error { if task.Job == nil { job, err := GetRunJobByID(ctx, task.JobID) if err != nil { @@ -160,7 +160,7 @@ func (task *BotTask) LoadJob(ctx context.Context) error { } // LoadAttributes load Job Steps if not loaded -func (task *BotTask) LoadAttributes(ctx context.Context) error { +func (task *ActionTask) LoadAttributes(ctx context.Context) error { if task == nil { return nil } @@ -183,7 +183,7 @@ func (task *BotTask) LoadAttributes(ctx context.Context) error { return nil } -func (task *BotTask) GenerateToken() (err error) { +func (task *ActionTask) GenerateToken() (err error) { task.Token, task.TokenSalt, task.TokenHash, task.TokenLastEight, err = generateSaltedToken() return err } @@ -213,8 +213,8 @@ func (indexes *LogIndexes) ToDB() ([]byte, error) { return buf[:i], nil } -func GetTaskByID(ctx context.Context, id int64) (*BotTask, error) { - var task BotTask +func GetTaskByID(ctx context.Context, id int64) (*ActionTask, error) { + var task ActionTask has, err := db.GetEngine(ctx).Where("id=?", id).Get(&task) if err != nil { return nil, err @@ -225,7 +225,7 @@ func GetTaskByID(ctx context.Context, id int64) (*BotTask, error) { return &task, nil } -func GetRunningTaskByToken(ctx context.Context, token string) (*BotTask, error) { +func GetRunningTaskByToken(ctx context.Context, token string) (*ActionTask, error) { errNotExist := fmt.Errorf("task with token %q: %w", token, util.ErrNotExist) if token == "" { return nil, errNotExist @@ -243,7 +243,7 @@ func GetRunningTaskByToken(ctx context.Context, token string) (*BotTask, error) lastEight := token[len(token)-8:] if id := getTaskIDFromCache(token); id > 0 { - task := &BotTask{ + task := &ActionTask{ TokenLastEight: lastEight, } // Re-get the task from the db in case it has been deleted in the intervening period @@ -257,7 +257,7 @@ func GetRunningTaskByToken(ctx context.Context, token string) (*BotTask, error) successfulTokenTaskCache.Remove(token) } - var tasks []*BotTask + var tasks []*ActionTask err := db.GetEngine(ctx).Where("token_last_eight = ? AND status = ?", lastEight, StatusRunning).Find(&tasks) if err != nil { return nil, err @@ -277,7 +277,7 @@ func GetRunningTaskByToken(ctx context.Context, token string) (*BotTask, error) return nil, errNotExist } -func CreateTaskForRunner(ctx context.Context, runner *BotRunner) (*BotTask, bool, error) { +func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask, bool, error) { dbCtx, commiter, err := db.TxContext(ctx) if err != nil { return nil, false, err @@ -297,13 +297,13 @@ func CreateTaskForRunner(ctx context.Context, runner *BotRunner) (*BotTask, bool jobCond = builder.In("run_id", builder.Select("id").From("bot_run").Where(jobCond)) } - var jobs []*BotRunJob + var jobs []*ActionRunJob if err := e.Where("task_id=? AND status=?", 0, StatusWaiting).And(jobCond).Asc("id").Find(&jobs); err != nil { return nil, false, err } // TODO: a more efficient way to filter labels - var job *BotRunJob + var job *ActionRunJob labels := runner.AgentLabels labels = append(labels, runner.CustomLabels...) log.Trace("runner labels: %v", labels) @@ -325,7 +325,7 @@ func CreateTaskForRunner(ctx context.Context, runner *BotRunner) (*BotTask, bool job.Started = now job.Status = StatusRunning - task := &BotTask{ + task := &ActionTask{ JobID: job.ID, Attempt: job.Attempt, RunnerID: runner.ID, @@ -358,9 +358,9 @@ func CreateTaskForRunner(ctx context.Context, runner *BotRunner) (*BotTask, bool return nil, false, err } - steps := make([]*BotTaskStep, len(workflowJob.Steps)) + steps := make([]*ActionTaskStep, len(workflowJob.Steps)) for i, v := range workflowJob.Steps { - steps[i] = &BotTaskStep{ + steps[i] = &ActionTaskStep{ Name: v.String(), TaskID: task.ID, Number: int64(i), @@ -397,7 +397,7 @@ func CreateTaskForRunner(ctx context.Context, runner *BotRunner) (*BotTask, bool return task, true, nil } -func UpdateTask(ctx context.Context, task *BotTask, cols ...string) error { +func UpdateTask(ctx context.Context, task *ActionTask, cols ...string) error { sess := db.GetEngine(ctx).ID(task.ID) if len(cols) > 0 { sess.Cols(cols...) @@ -406,7 +406,7 @@ func UpdateTask(ctx context.Context, task *BotTask, cols ...string) error { return err } -func UpdateTaskByState(state *runnerv1.TaskState) (*BotTask, error) { +func UpdateTaskByState(state *runnerv1.TaskState) (*ActionTask, error) { stepStates := map[int64]*runnerv1.StepState{} for _, v := range state.Steps { stepStates[v.Id] = v @@ -420,7 +420,7 @@ func UpdateTaskByState(state *runnerv1.TaskState) (*BotTask, error) { e := db.GetEngine(ctx) - task := &BotTask{} + task := &ActionTask{} if has, err := e.ID(state.Id).Get(task); err != nil { return nil, err } else if !has { @@ -430,7 +430,7 @@ func UpdateTaskByState(state *runnerv1.TaskState) (*BotTask, error) { if state.Result != runnerv1.Result_RESULT_UNSPECIFIED { task.Status = Status(state.Result) task.Stopped = timeutil.TimeStamp(state.StoppedAt.AsTime().Unix()) - if _, err := UpdateRunJob(ctx, &BotRunJob{ + if _, err := UpdateRunJob(ctx, &ActionRunJob{ ID: task.JobID, Status: task.Status, Stopped: task.Stopped, @@ -482,7 +482,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { } e := db.GetEngine(ctx) - task := &BotTask{} + task := &ActionTask{} if has, err := e.ID(taskID).Get(task); err != nil { return err } else if !has { @@ -495,7 +495,7 @@ func StopTask(ctx context.Context, taskID int64, status Status) error { now := timeutil.TimeStampNow() task.Status = status task.Stopped = now - if _, err := UpdateRunJob(ctx, &BotRunJob{ + if _, err := UpdateRunJob(ctx, &ActionRunJob{ ID: task.JobID, Status: task.Status, Stopped: task.Stopped, diff --git a/models/actions/task_list.go b/models/actions/task_list.go index 8ba39d083c..c1fbb5ddbd 100644 --- a/models/actions/task_list.go +++ b/models/actions/task_list.go @@ -12,7 +12,7 @@ import ( "xorm.io/builder" ) -type TaskList []*BotTask +type TaskList []*ActionTask func (tasks TaskList) GetJobIDs() []int64 { jobIDsMap := make(map[int64]struct{}) @@ -31,7 +31,7 @@ func (tasks TaskList) GetJobIDs() []int64 { func (tasks TaskList) LoadJobs(ctx context.Context) error { jobIDs := tasks.GetJobIDs() - jobs := make(map[int64]*BotRunJob, len(jobIDs)) + jobs := make(map[int64]*ActionRunJob, len(jobIDs)) if err := db.GetEngine(ctx).In("id", jobIDs).Find(&jobs); err != nil { return err } @@ -41,7 +41,7 @@ func (tasks TaskList) LoadJobs(ctx context.Context) error { } } - var jobsList RunJobList = make([]*BotRunJob, 0, len(jobs)) + var jobsList ActionJobList = make([]*ActionRunJob, 0, len(jobs)) for _, j := range jobs { jobsList = append(jobsList, j) } @@ -104,5 +104,5 @@ func FindTasks(ctx context.Context, opts FindTaskOptions) (TaskList, int64, erro } func CountTasks(ctx context.Context, opts FindTaskOptions) (int64, error) { - return db.GetEngine(ctx).Where(opts.toConds()).Count(new(BotTask)) + return db.GetEngine(ctx).Where(opts.toConds()).Count(new(ActionTask)) } diff --git a/models/actions/task_step.go b/models/actions/task_step.go index 5d330be01c..bf7c77e2c5 100644 --- a/models/actions/task_step.go +++ b/models/actions/task_step.go @@ -11,8 +11,8 @@ import ( "code.gitea.io/gitea/modules/timeutil" ) -// BotTaskStep represents a step of BotTask -type BotTaskStep struct { +// ActionTaskStep represents a step of ActionTask +type ActionTaskStep struct { ID int64 Name string TaskID int64 `xorm:"index unique(task_number)"` @@ -27,7 +27,7 @@ type BotTaskStep struct { Updated timeutil.TimeStamp `xorm:"updated"` } -func (step *BotTaskStep) TakeTime() time.Duration { +func (step *ActionTaskStep) TakeTime() time.Duration { if step.Started == 0 { return 0 } @@ -40,10 +40,10 @@ func (step *BotTaskStep) TakeTime() time.Duration { } func init() { - db.RegisterModel(new(BotTaskStep)) + db.RegisterModel(new(ActionTaskStep)) } -func GetTaskStepsByTaskID(ctx context.Context, taskID int64) ([]*BotTaskStep, error) { - var steps []*BotTaskStep +func GetTaskStepsByTaskID(ctx context.Context, taskID int64) ([]*ActionTaskStep, error) { + var steps []*ActionTaskStep return steps, db.GetEngine(ctx).Where("task_id=?", taskID).OrderBy("number").Find(&steps) } diff --git a/modules/actions/task_state.go b/modules/actions/task_state.go index c15311720c..cbbc0b357d 100644 --- a/modules/actions/task_state.go +++ b/modules/actions/task_state.go @@ -13,7 +13,7 @@ const ( ) // FullSteps returns steps with "Set up job" and "Complete job" -func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { +func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep { if len(task.Steps) == 0 { return fullStepsOfEmptySteps(task) } @@ -21,7 +21,7 @@ func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { firstStep := task.Steps[0] var logIndex int64 - preStep := &actions_model.BotTaskStep{ + preStep := &actions_model.ActionTaskStep{ Name: preStepName, LogLength: task.LogLength, Started: task.Started, @@ -38,7 +38,7 @@ func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { } logIndex += preStep.LogLength - var lastHasRunStep *actions_model.BotTaskStep + var lastHasRunStep *actions_model.ActionTaskStep for _, step := range task.Steps { if step.Status.HasRun() { lastHasRunStep = step @@ -49,7 +49,7 @@ func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { lastHasRunStep = preStep } - postStep := &actions_model.BotTaskStep{ + postStep := &actions_model.ActionTaskStep{ Name: postStepName, Status: actions_model.StatusWaiting, } @@ -60,7 +60,7 @@ func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { postStep.Started = lastHasRunStep.Stopped postStep.Stopped = task.Stopped } - ret := make([]*actions_model.BotTaskStep, 0, len(task.Steps)+2) + ret := make([]*actions_model.ActionTaskStep, 0, len(task.Steps)+2) ret = append(ret, preStep) ret = append(ret, task.Steps...) ret = append(ret, postStep) @@ -68,8 +68,8 @@ func FullSteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { return ret } -func fullStepsOfEmptySteps(task *actions_model.BotTask) []*actions_model.BotTaskStep { - preStep := &actions_model.BotTaskStep{ +func fullStepsOfEmptySteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep { + preStep := &actions_model.ActionTaskStep{ Name: preStepName, LogLength: task.LogLength, Started: task.Started, @@ -77,7 +77,7 @@ func fullStepsOfEmptySteps(task *actions_model.BotTask) []*actions_model.BotTask Status: actions_model.StatusRunning, } - postStep := &actions_model.BotTaskStep{ + postStep := &actions_model.ActionTaskStep{ Name: postStepName, LogIndex: task.LogLength, Started: task.Stopped, @@ -94,7 +94,7 @@ func fullStepsOfEmptySteps(task *actions_model.BotTask) []*actions_model.BotTask } } - return []*actions_model.BotTaskStep{ + return []*actions_model.ActionTaskStep{ preStep, postStep, } diff --git a/modules/actions/task_state_test.go b/modules/actions/task_state_test.go index 220acb16cd..3a599fbcbd 100644 --- a/modules/actions/task_state_test.go +++ b/modules/actions/task_state_test.go @@ -14,13 +14,13 @@ import ( func TestFullSteps(t *testing.T) { tests := []struct { name string - task *actions_model.BotTask - want []*actions_model.BotTaskStep + task *actions_model.ActionTask + want []*actions_model.ActionTaskStep }{ { name: "regular", - task: &actions_model.BotTask{ - Steps: []*actions_model.BotTaskStep{ + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ {Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090}, }, Status: actions_model.StatusSuccess, @@ -28,7 +28,7 @@ func TestFullSteps(t *testing.T) { Stopped: 10100, LogLength: 100, }, - want: []*actions_model.BotTaskStep{ + want: []*actions_model.ActionTaskStep{ {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}, @@ -36,8 +36,8 @@ func TestFullSteps(t *testing.T) { }, { name: "failed step", - task: &actions_model.BotTask{ - Steps: []*actions_model.BotTaskStep{ + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ {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}, @@ -47,7 +47,7 @@ func TestFullSteps(t *testing.T) { Stopped: 10100, LogLength: 100, }, - want: []*actions_model.BotTaskStep{ + want: []*actions_model.ActionTaskStep{ {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}, @@ -57,8 +57,8 @@ func TestFullSteps(t *testing.T) { }, { name: "first step is running", - task: &actions_model.BotTask{ - Steps: []*actions_model.BotTaskStep{ + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ {Status: actions_model.StatusRunning, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 0}, }, Status: actions_model.StatusRunning, @@ -66,7 +66,7 @@ func TestFullSteps(t *testing.T) { Stopped: 10100, LogLength: 100, }, - want: []*actions_model.BotTaskStep{ + want: []*actions_model.ActionTaskStep{ {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}, @@ -74,8 +74,8 @@ func TestFullSteps(t *testing.T) { }, { name: "first step has canceled", - task: &actions_model.BotTask{ - Steps: []*actions_model.BotTaskStep{ + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{ {Status: actions_model.StatusCancelled, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0}, }, Status: actions_model.StatusFailure, @@ -83,7 +83,7 @@ func TestFullSteps(t *testing.T) { Stopped: 10100, LogLength: 100, }, - want: []*actions_model.BotTaskStep{ + want: []*actions_model.ActionTaskStep{ {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}, @@ -91,14 +91,14 @@ func TestFullSteps(t *testing.T) { }, { name: "empty steps", - task: &actions_model.BotTask{ - Steps: []*actions_model.BotTaskStep{}, + task: &actions_model.ActionTask{ + Steps: []*actions_model.ActionTaskStep{}, Status: actions_model.StatusSuccess, Started: 10000, Stopped: 10100, LogLength: 100, }, - want: []*actions_model.BotTaskStep{ + want: []*actions_model.ActionTaskStep{ {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 bf25395e3f..c3127ff3b5 100644 --- a/modules/notification/actions/helper.go +++ b/modules/notification/actions/helper.go @@ -16,7 +16,7 @@ import ( "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" - actions_module "code.gitea.io/gitea/modules/actions" + bots_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" @@ -117,7 +117,7 @@ func notify(ctx context.Context, input *notifyInput) error { return fmt.Errorf("gitRepo.GetCommit: %v", err) } - workflows, err := actions_module.DetectWorkflows(commit, input.Event) + workflows, err := bots_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 := actions_model.BotRun{ + run := actions_model.ActionRun{ Title: commit.Message(), RepoID: input.Repo.ID, OwnerID: input.Repo.OwnerID, diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go index ce26c42698..579341b0ef 100644 --- a/routers/api/actions/runner/runner.go +++ b/routers/api/actions/runner/runner.go @@ -52,7 +52,7 @@ func (s *Service) Register( } // create new runner - runner := &actions_model.BotRunner{ + runner := &actions_model.ActionRunner{ UUID: gouuid.New().String(), Name: req.Msg.Name, OwnerID: runnerToken.OwnerID, @@ -231,7 +231,7 @@ func (s *Service) UpdateLog( return res, nil } -func pickTask(ctx context.Context, runner *actions_model.BotRunner) (*runnerv1.Task, bool, error) { +func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*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 *actions_model.BotRunner) (*runnerv1.T return task, true, nil } -func getSecretsOfTask(ctx context.Context, task *actions_model.BotTask) map[string]string { +func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) 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 *actions_model.BotTask) map[stri return secrets } -func generateTaskContext(t *actions_model.BotTask) *structpb.Struct { +func generateTaskContext(t *actions_model.ActionTask) *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 f660739164..9571beb7c7 100644 --- a/routers/api/actions/runner/unary.go +++ b/routers/api/actions/runner/unary.go @@ -67,9 +67,9 @@ func getMethodName(req connect.AnyRequest) string { type runnerCtxKey struct{} -func GetRunner(ctx context.Context) *actions_model.BotRunner { +func GetRunner(ctx context.Context) *actions_model.ActionRunner { if v := ctx.Value(runnerCtxKey{}); v != nil { - if r, ok := v.(*actions_model.BotRunner); ok { + if r, ok := v.(*actions_model.ActionRunner); ok { return r } } diff --git a/routers/common/runners.go b/routers/common/runners.go index ef42c88764..7010d3f16a 100644 --- a/routers/common/runners.go +++ b/routers/common/runners.go @@ -36,7 +36,7 @@ func RunnersList(ctx *context.Context, tplName base.TplName, opts actions_model. } // ownid=0,repo_id=0,means this token is used for global - var token *actions_model.BotRunnerToken + var token *actions_model.ActionRunnerToken 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) diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index e012587206..dbabf6e4b1 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -125,7 +125,7 @@ func ViewPost(ctx *context_module.Context) { }, } - var task *actions_model.BotTask + var task *actions_model.ActionTask if current.TaskID > 0 { var err error task, err = actions_model.GetTaskByID(ctx, current.TaskID) @@ -268,7 +268,7 @@ 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) (*actions_model.BotRunJob, []*actions_model.BotRunJob) { +func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions_model.ActionRunJob, []*actions_model.ActionRunJob) { run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex) if err != nil { if _, ok := err.(actions_model.ErrRunNotExist); ok { diff --git a/services/actions/actions.go b/services/actions/actions.go index 9f4d5b88eb..d55e329ebd 100644 --- a/services/actions/actions.go +++ b/services/actions/actions.go @@ -13,7 +13,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" - actions_module "code.gitea.io/gitea/modules/actions" + bots_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" @@ -33,19 +33,19 @@ func DeleteResourceOfRepository(ctx context.Context, repo *repo_model.Repository if err := db.WithTx(ctx, func(ctx context.Context) error { e := db.GetEngine(ctx) - if _, err := e.Delete(&actions_model.BotTaskStep{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.ActionTaskStep{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots task steps of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&actions_model.BotTask{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.ActionTask{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots tasks of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&actions_model.BotRunJob{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.ActionRunJob{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots run jobs of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&actions_model.BotRun{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.ActionRun{RepoID: repo.ID}); err != nil { return fmt.Errorf("delete bots runs of repo %d: %w", repo.ID, err) } - if _, err := e.Delete(&actions_model.BotRunner{RepoID: repo.ID}); err != nil { + if _, err := e.Delete(&actions_model.ActionRunner{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 := actions_module.RemoveLogs(ctx, task.LogInStorage, task.LogFilename) + err := bots_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 *actions_model.BotRunJob) error { +func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) error { if err := job.LoadAttributes(ctx); err != nil { return fmt.Errorf("load run: %w", err) } diff --git a/services/actions/job_emitter.go b/services/actions/job_emitter.go index d4230c3bcb..cb2cc8d1ac 100644 --- a/services/actions/job_emitter.go +++ b/services/actions/job_emitter.go @@ -50,7 +50,7 @@ func checkJobsOfRun(ctx context.Context, runID int64) error { if err != nil { return err } - idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs)) + idToJobs := make(map[string][]*actions_model.ActionRunJob, len(jobs)) for _, job := range jobs { idToJobs[job.JobID] = append(idToJobs[job.JobID], job) } @@ -75,8 +75,8 @@ type jobStatusResolver struct { needs map[int64][]int64 } -func newJobStatusResolver(jobs actions_model.RunJobList) *jobStatusResolver { - idToJobs := make(map[string][]*actions_model.BotRunJob, len(jobs)) +func newJobStatusResolver(jobs actions_model.ActionJobList) *jobStatusResolver { + idToJobs := make(map[string][]*actions_model.ActionRunJob, len(jobs)) for _, job := range jobs { idToJobs[job.JobID] = append(idToJobs[job.JobID], job) } diff --git a/services/actions/job_emitter_test.go b/services/actions/job_emitter_test.go index ecdf170fec..e81aa61d80 100644 --- a/services/actions/job_emitter_test.go +++ b/services/actions/job_emitter_test.go @@ -14,12 +14,12 @@ import ( func Test_jobStatusResolver_Resolve(t *testing.T) { tests := []struct { name string - jobs actions_model.RunJobList + jobs actions_model.ActionJobList want map[int64]actions_model.Status }{ { name: "no blocked", - jobs: actions_model.RunJobList{ + jobs: actions_model.ActionJobList{ {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{}}, @@ -28,7 +28,7 @@ func Test_jobStatusResolver_Resolve(t *testing.T) { }, { name: "single blocked", - jobs: actions_model.RunJobList{ + jobs: actions_model.ActionJobList{ {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{}}, @@ -39,7 +39,7 @@ func Test_jobStatusResolver_Resolve(t *testing.T) { }, { name: "multiple blocked", - jobs: actions_model.RunJobList{ + jobs: actions_model.ActionJobList{ {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"}}, @@ -51,7 +51,7 @@ func Test_jobStatusResolver_Resolve(t *testing.T) { }, { name: "chain blocked", - jobs: actions_model.RunJobList{ + jobs: actions_model.ActionJobList{ {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"}}, @@ -63,7 +63,7 @@ func Test_jobStatusResolver_Resolve(t *testing.T) { }, { name: "loop need", - jobs: actions_model.RunJobList{ + jobs: actions_model.ActionJobList{ {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"}},