woodpecker/server/store/store.go

157 lines
5.4 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
import (
"io"
"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)
// GetUserLogin gets a user by unique Login name.
GetUserLogin(string) (*model.User, error)
// GetUserList gets a list of all users in the system.
// TODO: paginate
GetUserList() ([]*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)
// 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
2022-01-06 06:44:14 +00:00
// Builds
// GetBuild gets a build by unique ID.
GetBuild(int64) (*model.Build, error)
// GetBuildNumber gets a build by number.
GetBuildNumber(*model.Repo, int64) (*model.Build, error)
// GetBuildRef gets a build by its ref.
GetBuildRef(*model.Repo, string) (*model.Build, error)
// GetBuildCommit gets a build by its commit sha.
GetBuildCommit(*model.Repo, string, string) (*model.Build, error)
// GetBuildLast gets the last build for the branch.
GetBuildLast(*model.Repo, string) (*model.Build, error)
// GetBuildLastBefore gets the last build before build number N.
GetBuildLastBefore(*model.Repo, string, int64) (*model.Build, error)
// GetBuildList gets a list of builds for the repository
// TODO: paginate
GetBuildList(*model.Repo, int) ([]*model.Build, error)
// GetBuildList gets a list of the active builds for the repository
GetActiveBuildList(repo *model.Repo, page int) ([]*model.Build, error)
// GetBuildQueue gets a list of build in queue.
GetBuildQueue() ([]*model.Feed, error)
2017-07-25 19:32:22 +00:00
// GetBuildCount gets a count of all builds in the system.
GetBuildCount() (int64, error)
// CreateBuild creates a new build and jobs.
2017-04-02 14:13:26 +00:00
CreateBuild(*model.Build, ...*model.Proc) error
// UpdateBuild updates a build.
UpdateBuild(*model.Build) error
2022-01-06 06:44:14 +00:00
// Feeds
2017-07-14 19:58:38 +00:00
UserFeed(*model.User) ([]*model.Feed, error)
2022-01-06 06:44:14 +00:00
// Repositorys
// RepoList TODO: paginate
RepoList(user *model.User, owned bool) ([]*model.Repo, error)
RepoListLatest(*model.User) ([]*model.Feed, error)
// RepoBatch Sync batch of repos from SCM (with permissions) to store (create if not exist else update)
2017-07-14 19:58:38 +00:00
RepoBatch([]*model.Repo) error
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
ConfigsForBuild(buildID 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
BuildConfigCreate(*model.BuildConfig) 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) ([]*model.Secret, error)
SecretCreate(*model.Secret) error
SecretUpdate(*model.Secret) error
SecretDelete(*model.Secret) error
2022-01-06 06:44:14 +00:00
// Registrys
2017-04-06 12:51:01 +00:00
RegistryFind(*model.Repo, string) (*model.Registry, error)
RegistryList(*model.Repo) ([]*model.Registry, error)
RegistryCreate(*model.Registry) error
RegistryUpdate(*model.Registry) error
RegistryDelete(repo *model.Repo, addr string) error
2017-03-28 08:53:06 +00:00
2022-01-06 06:44:14 +00:00
// Procs
2017-04-01 11:17:04 +00:00
ProcLoad(int64) (*model.Proc, error)
2017-03-28 08:53:06 +00:00
ProcFind(*model.Build, int) (*model.Proc, error)
ProcChild(*model.Build, int, string) (*model.Proc, error)
ProcList(*model.Build) ([]*model.Proc, error)
ProcCreate([]*model.Proc) error
ProcUpdate(*model.Proc) error
ProcClear(*model.Build) error
2017-03-28 08:53:06 +00:00
2022-01-06 06:44:14 +00:00
// Logs
2017-04-03 09:34:37 +00:00
LogFind(*model.Proc) (io.ReadCloser, error)
// TODO: since we do ReadAll in any case a ioReader is not the best idear
// so either find a way to write log in chunks by xorm ...
2017-04-03 09:34:37 +00:00
LogSave(*model.Proc, io.Reader) error
2022-01-06 06:44:14 +00:00
// Files
2017-03-28 08:53:06 +00:00
FileList(*model.Build) ([]*model.File, error)
FileFind(*model.Proc, string) (*model.File, error)
FileRead(*model.Proc, string) (io.ReadCloser, error)
FileCreate(*model.File, io.Reader) error
2017-04-14 11:32:36 +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
2022-01-06 06:44:14 +00:00
// Store operations
2017-10-05 21:17:27 +00:00
Ping() error
Close() error
Migrate() error
}