woodpecker/server/store/store.go

203 lines
7.6 KiB
Go
Raw Normal View History

2018-02-19 22:24:10 +00:00
// Copyright 2018 Drone.IO Inc.
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2018-03-21 13:02:17 +00:00
//
2018-02-19 22:24:10 +00:00
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package store
//go:generate go install github.com/vektra/mockery/v2@latest
//go:generate mockery --name Store --output mocks --case underscore
import (
"github.com/woodpecker-ci/woodpecker/server/model"
)
// TODO: CreateX func should return new object to not indirect let storage change an existing object (alter ID etc...)
type Store interface {
2022-01-06 06:44:14 +00:00
// Users
// GetUser gets a user by unique ID.
GetUser(int64) (*model.User, error)
// GetUserRemoteID gets a user by remote ID with fallback to login name.
GetUserRemoteID(model.ForgeRemoteID, string) (*model.User, error)
// GetUserLogin gets a user by unique Login name.
GetUserLogin(string) (*model.User, error)
// GetUserList gets a list of all users in the system.
GetUserList(p *model.ListOptions) ([]*model.User, error)
// GetUserCount gets a count of all users in the system.
GetUserCount() (int64, error)
// CreateUser creates a new user account.
CreateUser(*model.User) error
// UpdateUser updates a user account.
UpdateUser(*model.User) error
// DeleteUser deletes a user account.
DeleteUser(*model.User) error
2022-01-06 06:44:14 +00:00
// Repos
// GetRepo gets a repo by unique ID.
GetRepo(int64) (*model.Repo, error)
// GetRepoForgeID gets a repo by its forge ID.
GetRepoForgeID(model.ForgeRemoteID) (*model.Repo, error)
// GetRepoNameFallback gets the repo by its forge ID and if this doesn't exist by its full name.
GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error)
// GetRepoName gets a repo by its full name.
GetRepoName(string) (*model.Repo, error)
// GetRepoCount gets a count of all repositories in the system.
GetRepoCount() (int64, error)
// CreateRepo creates a new repository.
CreateRepo(*model.Repo) error
// UpdateRepo updates a user repository.
UpdateRepo(*model.Repo) error
// DeleteRepo deletes a user repository.
DeleteRepo(*model.Repo) error
// Redirections
// GetRedirection returns the redirection for the given full repo name
GetRedirection(string) (*model.Redirection, error)
// CreateRedirection creates a redirection
CreateRedirection(redirection *model.Redirection) error
// HasRedirectionForRepo checks if there's a redirection for the given repo and full name
HasRedirectionForRepo(int64, string) (bool, error)
// Pipelines
// GetPipeline gets a pipeline by unique ID.
GetPipeline(int64) (*model.Pipeline, error)
// GetPipelineNumber gets a pipeline by number.
GetPipelineNumber(*model.Repo, int64) (*model.Pipeline, error)
// GetPipelineRef gets a pipeline by its ref.
GetPipelineRef(*model.Repo, string) (*model.Pipeline, error)
// GetPipelineCommit gets a pipeline by its commit sha.
GetPipelineCommit(*model.Repo, string, string) (*model.Pipeline, error)
// GetPipelineLast gets the last pipeline for the branch.
GetPipelineLast(*model.Repo, string) (*model.Pipeline, error)
// GetPipelineLastBefore gets the last pipeline before pipeline number N.
GetPipelineLastBefore(*model.Repo, string, int64) (*model.Pipeline, error)
// GetPipelineList gets a list of pipelines for the repository
GetPipelineList(*model.Repo, *model.ListOptions) ([]*model.Pipeline, error)
// GetActivePipelineList gets a list of the active pipelines for the repository
GetActivePipelineList(repo *model.Repo) ([]*model.Pipeline, error)
// GetPipelineQueue gets a list of pipelines in queue.
GetPipelineQueue() ([]*model.Feed, error)
// GetPipelineCount gets a count of all pipelines in the system.
GetPipelineCount() (int64, error)
// CreatePipeline creates a new pipeline and steps.
CreatePipeline(*model.Pipeline, ...*model.Step) error
// UpdatePipeline updates a pipeline.
UpdatePipeline(*model.Pipeline) error
2022-01-06 06:44:14 +00:00
// Feeds
2017-07-14 19:58:38 +00:00
UserFeed(*model.User) ([]*model.Feed, error)
// Repositories
RepoList(user *model.User, owned, active bool) ([]*model.Repo, error)
RepoListLatest(*model.User) ([]*model.Feed, error)
2023-09-08 10:26:20 +00:00
RepoListAll(active bool, p *model.ListOptions) ([]*model.Repo, error)
2017-07-14 19:58:38 +00:00
2022-01-06 06:44:14 +00:00
// Permissions
2017-07-14 19:58:38 +00:00
PermFind(user *model.User, repo *model.Repo) (*model.Perm, error)
PermUpsert(perm *model.Perm) error
PermDelete(perm *model.Perm) error
2017-07-16 17:37:16 +00:00
PermFlush(user *model.User, before int64) error
2017-07-14 19:58:38 +00:00
2022-01-06 06:44:14 +00:00
// Configs
ConfigsForPipeline(pipelineID int64) ([]*model.Config, error)
ConfigFindIdentical(repoID int64, hash string) (*model.Config, error)
2017-05-05 18:05:42 +00:00
ConfigFindApproved(*model.Config) (bool, error)
ConfigCreate(*model.Config) error
PipelineConfigCreate(*model.PipelineConfig) error
2017-05-05 16:59:37 +00:00
2022-01-06 06:44:14 +00:00
// Secrets
SecretFind(*model.Repo, string) (*model.Secret, error)
SecretList(*model.Repo, bool, *model.ListOptions) ([]*model.Secret, error)
SecretListAll() ([]*model.Secret, error)
SecretCreate(*model.Secret) error
SecretUpdate(*model.Secret) error
SecretDelete(*model.Secret) error
OrgSecretFind(int64, string) (*model.Secret, error)
OrgSecretList(int64, *model.ListOptions) ([]*model.Secret, error)
GlobalSecretFind(string) (*model.Secret, error)
GlobalSecretList(*model.ListOptions) ([]*model.Secret, error)
// Registries
2017-04-06 12:51:01 +00:00
RegistryFind(*model.Repo, string) (*model.Registry, error)
RegistryList(*model.Repo, *model.ListOptions) ([]*model.Registry, error)
2017-04-06 12:51:01 +00:00
RegistryCreate(*model.Registry) error
RegistryUpdate(*model.Registry) error
RegistryDelete(repo *model.Repo, addr string) error
2017-03-28 08:53:06 +00:00
// Steps
StepLoad(int64) (*model.Step, error)
StepFind(*model.Pipeline, int) (*model.Step, error)
StepByUUID(string) (*model.Step, error)
StepChild(*model.Pipeline, int, string) (*model.Step, error)
StepList(*model.Pipeline) ([]*model.Step, error)
StepUpdate(*model.Step) error
StepClear(*model.Pipeline) error
StepListFromWorkflowFind(*model.Workflow) ([]*model.Step, error)
2017-03-28 08:53:06 +00:00
2022-01-06 06:44:14 +00:00
// Logs
LogFind(*model.Step) ([]*model.LogEntry, error)
LogSave(*model.Step, []*model.LogEntry) error
LogAppend(logEntry *model.LogEntry) error
LogDelete(*model.Step) error
2017-04-03 09:34:37 +00:00
2022-01-06 06:44:14 +00:00
// Tasks
// TaskList TODO: paginate & opt filter
2017-04-14 11:32:36 +00:00
TaskList() ([]*model.Task, error)
TaskInsert(*model.Task) error
TaskDelete(string) error
2017-10-05 21:17:27 +00:00
// ServerConfig
ServerConfigGet(string) (string, error)
ServerConfigSet(string, string) error
ServerConfigDelete(string) error
// Cron
CronCreate(*model.Cron) error
CronFind(*model.Repo, int64) (*model.Cron, error)
CronList(*model.Repo, *model.ListOptions) ([]*model.Cron, error)
CronUpdate(*model.Repo, *model.Cron) error
CronDelete(*model.Repo, int64) error
CronListNextExecute(int64, int64) ([]*model.Cron, error)
CronGetLock(*model.Cron, int64) (bool, error)
// Agent
AgentCreate(*model.Agent) error
AgentFind(int64) (*model.Agent, error)
AgentFindByToken(string) (*model.Agent, error)
AgentList(p *model.ListOptions) ([]*model.Agent, error)
AgentUpdate(*model.Agent) error
AgentDelete(*model.Agent) error
// Workflow
WorkflowGetTree(*model.Pipeline) ([]*model.Workflow, error)
WorkflowsCreate([]*model.Workflow) error
WorkflowLoad(int64) (*model.Workflow, error)
WorkflowUpdate(*model.Workflow) error
// Org
OrgCreate(*model.Org) error
OrgGet(int64) (*model.Org, error)
OrgFindByName(string) (*model.Org, error)
OrgUpdate(*model.Org) error
OrgDelete(int64) error
OrgList(*model.ListOptions) ([]*model.Org, error)
// Org repos
OrgRepoList(*model.Org, *model.ListOptions) ([]*model.Repo, error)
2022-01-06 06:44:14 +00:00
// Store operations
2017-10-05 21:17:27 +00:00
Ping() error
Close() error
Migrate() error
}