forked from harness/harness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
245 lines (182 loc) · 7.3 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package store
import (
"io"
"github.com/drone/drone/model"
"golang.org/x/net/context"
)
type Store interface {
// 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.
GetUserList() ([]*model.User, error)
// GetUserFeed gets a user activity feed.
GetUserFeed([]*model.RepoLite) ([]*model.Feed, error)
// GetUserFeedLatest gets a user activity feed for all repositories including
// only the latest build for each repository.
GetUserFeedLatest(listof []*model.RepoLite) ([]*model.Feed, error)
// GetUserCount gets a count of all users in the system.
GetUserCount() (int, 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
// 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)
// GetRepoListOf gets the list of enumerated repos in the system.
GetRepoListOf([]*model.RepoLite) ([]*model.Repo, error)
// GetRepoCount gets a count of all repositories in the system.
GetRepoCount() (int, 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
// GetBuild gets a build by unique ID.
GetBuild(int64) (*model.Build, error)
// GetBuildNumber gets a build by number.
GetBuildNumber(*model.Repo, int) (*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
GetBuildList(*model.Repo) ([]*model.Build, error)
// GetBuildQueue gets a list of build in queue.
GetBuildQueue() ([]*model.Feed, error)
// CreateBuild creates a new build and jobs.
CreateBuild(*model.Build, ...*model.Proc) error
// UpdateBuild updates a build.
UpdateBuild(*model.Build) error
//
// new functions
//
ConfigLoad(int64) (*model.Config, error)
ConfigFind(*model.Repo, string) (*model.Config, error)
ConfigFindApproved(*model.Config) (bool, error)
ConfigCreate(*model.Config) error
SenderFind(*model.Repo, string) (*model.Sender, error)
SenderList(*model.Repo) ([]*model.Sender, error)
SenderCreate(*model.Sender) error
SenderUpdate(*model.Sender) error
SenderDelete(*model.Sender) error
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
RegistryFind(*model.Repo, string) (*model.Registry, error)
RegistryList(*model.Repo) ([]*model.Registry, error)
RegistryCreate(*model.Registry) error
RegistryUpdate(*model.Registry) error
RegistryDelete(*model.Registry) error
ProcLoad(int64) (*model.Proc, error)
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
LogFind(*model.Proc) (io.ReadCloser, error)
LogSave(*model.Proc, io.Reader) error
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
TaskList() ([]*model.Task, error)
TaskInsert(*model.Task) error
TaskDelete(string) error
}
// GetUser gets a user by unique ID.
func GetUser(c context.Context, id int64) (*model.User, error) {
return FromContext(c).GetUser(id)
}
// GetUserLogin gets a user by unique Login name.
func GetUserLogin(c context.Context, login string) (*model.User, error) {
return FromContext(c).GetUserLogin(login)
}
// GetUserList gets a list of all users in the system.
func GetUserList(c context.Context) ([]*model.User, error) {
return FromContext(c).GetUserList()
}
// GetUserFeed gets a user activity feed.
func GetUserFeed(c context.Context, listof []*model.RepoLite, latest bool) ([]*model.Feed, error) {
if latest {
return FromContext(c).GetUserFeedLatest(listof)
}
return FromContext(c).GetUserFeed(listof)
}
// GetUserCount gets a count of all users in the system.
func GetUserCount(c context.Context) (int, error) {
return FromContext(c).GetUserCount()
}
func CreateUser(c context.Context, user *model.User) error {
return FromContext(c).CreateUser(user)
}
func UpdateUser(c context.Context, user *model.User) error {
return FromContext(c).UpdateUser(user)
}
func DeleteUser(c context.Context, user *model.User) error {
return FromContext(c).DeleteUser(user)
}
func GetRepo(c context.Context, id int64) (*model.Repo, error) {
return FromContext(c).GetRepo(id)
}
func GetRepoName(c context.Context, name string) (*model.Repo, error) {
return FromContext(c).GetRepoName(name)
}
func GetRepoOwnerName(c context.Context, owner, name string) (*model.Repo, error) {
return FromContext(c).GetRepoName(owner + "/" + name)
}
func GetRepoListOf(c context.Context, listof []*model.RepoLite) ([]*model.Repo, error) {
return FromContext(c).GetRepoListOf(listof)
}
func CreateRepo(c context.Context, repo *model.Repo) error {
return FromContext(c).CreateRepo(repo)
}
func UpdateRepo(c context.Context, repo *model.Repo) error {
return FromContext(c).UpdateRepo(repo)
}
func DeleteRepo(c context.Context, repo *model.Repo) error {
return FromContext(c).DeleteRepo(repo)
}
func GetBuild(c context.Context, id int64) (*model.Build, error) {
return FromContext(c).GetBuild(id)
}
func GetBuildNumber(c context.Context, repo *model.Repo, num int) (*model.Build, error) {
return FromContext(c).GetBuildNumber(repo, num)
}
func GetBuildRef(c context.Context, repo *model.Repo, ref string) (*model.Build, error) {
return FromContext(c).GetBuildRef(repo, ref)
}
func GetBuildCommit(c context.Context, repo *model.Repo, sha, branch string) (*model.Build, error) {
return FromContext(c).GetBuildCommit(repo, sha, branch)
}
func GetBuildLast(c context.Context, repo *model.Repo, branch string) (*model.Build, error) {
return FromContext(c).GetBuildLast(repo, branch)
}
func GetBuildLastBefore(c context.Context, repo *model.Repo, branch string, number int64) (*model.Build, error) {
return FromContext(c).GetBuildLastBefore(repo, branch, number)
}
func GetBuildList(c context.Context, repo *model.Repo) ([]*model.Build, error) {
return FromContext(c).GetBuildList(repo)
}
func GetBuildQueue(c context.Context) ([]*model.Feed, error) {
return FromContext(c).GetBuildQueue()
}
func CreateBuild(c context.Context, build *model.Build, procs ...*model.Proc) error {
return FromContext(c).CreateBuild(build, procs...)
}
func UpdateBuild(c context.Context, build *model.Build) error {
return FromContext(c).UpdateBuild(build)
}