c572fcfe04
Rename the Go module path from code.gitea.io/gitea to git.mokoconsulting.tech/MokoConsulting/MokoGitea across the entire codebase. Scope: - go.mod module declaration - 2,235 Go source files (import paths) - Dockerfile WORKDIR and COPY paths - Swagger API templates - golangci.yml linter config External dependencies (code.gitea.io/gitea-vet, code.gitea.io/sdk/gitea, gitea.com/gitea/act, etc.) are intentionally NOT renamed — they are separate upstream modules. Closes #132 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/db"
|
|
repo_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/repo"
|
|
user_model "git.mokoconsulting.tech/MokoConsulting/MokoGitea/models/user"
|
|
"git.mokoconsulting.tech/MokoConsulting/MokoGitea/modules/container"
|
|
)
|
|
|
|
type RunnerList []*ActionRunner
|
|
|
|
// GetUserIDs returns a slice of user's id
|
|
func (runners RunnerList) GetUserIDs() []int64 {
|
|
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
|
|
return runner.OwnerID, runner.OwnerID != 0
|
|
})
|
|
}
|
|
|
|
func (runners RunnerList) LoadOwners(ctx context.Context) error {
|
|
userIDs := runners.GetUserIDs()
|
|
users := make(map[int64]*user_model.User, len(userIDs))
|
|
if err := db.GetEngine(ctx).In("id", userIDs).Find(&users); err != nil {
|
|
return err
|
|
}
|
|
for _, runner := range runners {
|
|
if runner.OwnerID > 0 && runner.Owner == nil {
|
|
runner.Owner = users[runner.OwnerID]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (runners RunnerList) getRepoIDs() []int64 {
|
|
return container.FilterSlice(runners, func(runner *ActionRunner) (int64, bool) {
|
|
return runner.RepoID, runner.RepoID > 0
|
|
})
|
|
}
|
|
|
|
func (runners RunnerList) LoadRepos(ctx context.Context) error {
|
|
repoIDs := runners.getRepoIDs()
|
|
repos := make(map[int64]*repo_model.Repository, len(repoIDs))
|
|
if err := db.GetEngine(ctx).In("id", repoIDs).Find(&repos); err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, runner := range runners {
|
|
if runner.RepoID > 0 && runner.Repo == nil {
|
|
runner.Repo = repos[runner.RepoID]
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (runners RunnerList) LoadAttributes(ctx context.Context) error {
|
|
if err := runners.LoadOwners(ctx); err != nil {
|
|
return err
|
|
}
|
|
|
|
return runners.LoadRepos(ctx)
|
|
}
|