Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
98 lines
2.1 KiB
Go
98 lines
2.1 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitcaddy.com/server/v3/models/db"
|
|
repo_model "code.gitcaddy.com/server/v3/models/repo"
|
|
"code.gitcaddy.com/server/v3/modules/container"
|
|
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
type SpecList []*ActionScheduleSpec
|
|
|
|
func (specs SpecList) GetScheduleIDs() []int64 {
|
|
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
|
|
return spec.ScheduleID, true
|
|
})
|
|
}
|
|
|
|
func (specs SpecList) LoadSchedules(ctx context.Context) error {
|
|
scheduleIDs := specs.GetScheduleIDs()
|
|
schedules, err := GetSchedulesMapByIDs(ctx, scheduleIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, spec := range specs {
|
|
spec.Schedule = schedules[spec.ScheduleID]
|
|
}
|
|
|
|
repoIDs := specs.GetRepoIDs()
|
|
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, spec := range specs {
|
|
spec.Repo = repos[spec.RepoID]
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (specs SpecList) GetRepoIDs() []int64 {
|
|
return container.FilterSlice(specs, func(spec *ActionScheduleSpec) (int64, bool) {
|
|
return spec.RepoID, true
|
|
})
|
|
}
|
|
|
|
func (specs SpecList) LoadRepos(ctx context.Context) error {
|
|
repoIDs := specs.GetRepoIDs()
|
|
repos, err := repo_model.GetRepositoriesMapByIDs(ctx, repoIDs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, spec := range specs {
|
|
spec.Repo = repos[spec.RepoID]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type FindSpecOptions struct {
|
|
db.ListOptions
|
|
RepoID int64
|
|
Next int64
|
|
}
|
|
|
|
func (opts FindSpecOptions) ToConds() builder.Cond {
|
|
cond := builder.NewCond()
|
|
if opts.RepoID > 0 {
|
|
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
|
|
}
|
|
|
|
if opts.Next > 0 {
|
|
cond = cond.And(builder.Lte{"next": opts.Next})
|
|
}
|
|
|
|
return cond
|
|
}
|
|
|
|
func (opts FindSpecOptions) ToOrders() string {
|
|
return "`id` DESC"
|
|
}
|
|
|
|
func FindSpecs(ctx context.Context, opts FindSpecOptions) (SpecList, int64, error) {
|
|
specs, total, err := db.FindAndCount[ActionScheduleSpec](ctx, opts)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
if err := SpecList(specs).LoadSchedules(ctx); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return specs, total, nil
|
|
}
|