@@ -14,6 +14,8 @@ import (
14
14
"code.gitea.io/gitea/models/db"
15
15
"code.gitea.io/gitea/modules/timeutil"
16
16
"code.gitea.io/gitea/modules/util"
17
+
18
+ "xorm.io/builder"
17
19
)
18
20
19
21
// ArtifactStatus is the status of an artifact, uploading, expired or need-delete
@@ -108,29 +110,37 @@ func UpdateArtifactByID(ctx context.Context, id int64, art *ActionArtifact) erro
108
110
return err
109
111
}
110
112
111
- // ListArtifactsByRunID returns all artifacts of a run
112
- func ListArtifactsByRunID (ctx context.Context , runID int64 ) ([]* ActionArtifact , error ) {
113
- arts := make ([]* ActionArtifact , 0 , 10 )
114
- return arts , db .GetEngine (ctx ).Where ("run_id=?" , runID ).Find (& arts )
113
+ type FindArtifactsOptions struct {
114
+ db.ListOptions
115
+ RepoID int64
116
+ RunID int64
117
+ ArtifactName string
118
+ Status int
115
119
}
116
120
117
- // ListArtifactsByRunIDAndArtifactName returns an artifacts of a run by artifact name
118
- func ListArtifactsByRunIDAndArtifactName (ctx context.Context , runID int64 , artifactName string ) ([]* ActionArtifact , error ) {
119
- arts := make ([]* ActionArtifact , 0 , 10 )
120
- return arts , db .GetEngine (ctx ).Where ("run_id=? AND artifact_name=?" , runID , artifactName ).Find (& arts )
121
- }
121
+ func (opts FindArtifactsOptions ) ToConds () builder.Cond {
122
+ cond := builder .NewCond ()
123
+ if opts .RepoID > 0 {
124
+ cond = cond .And (builder.Eq {"repo_id" : opts .RepoID })
125
+ }
126
+ if opts .RunID > 0 {
127
+ cond = cond .And (builder.Eq {"run_id" : opts .RunID })
128
+ }
129
+ if opts .ArtifactName != "" {
130
+ cond = cond .And (builder.Eq {"artifact_name" : opts .ArtifactName })
131
+ }
132
+ if opts .Status > 0 {
133
+ cond = cond .And (builder.Eq {"status" : opts .Status })
134
+ }
122
135
123
- // ListUploadedArtifactsByRunID returns all uploaded artifacts of a run
124
- func ListUploadedArtifactsByRunID (ctx context.Context , runID int64 ) ([]* ActionArtifact , error ) {
125
- arts := make ([]* ActionArtifact , 0 , 10 )
126
- return arts , db .GetEngine (ctx ).Where ("run_id=? AND status=?" , runID , ArtifactStatusUploadConfirmed ).Find (& arts )
136
+ return cond
127
137
}
128
138
129
139
// ActionArtifactMeta is the meta data of an artifact
130
140
type ActionArtifactMeta struct {
131
141
ArtifactName string
132
142
FileSize int64
133
- Status int64
143
+ Status ArtifactStatus
134
144
}
135
145
136
146
// ListUploadedArtifactsMeta returns all uploaded artifacts meta of a run
@@ -143,18 +153,6 @@ func ListUploadedArtifactsMeta(ctx context.Context, runID int64) ([]*ActionArtif
143
153
Find (& arts )
144
154
}
145
155
146
- // ListArtifactsByRepoID returns all artifacts of a repo
147
- func ListArtifactsByRepoID (ctx context.Context , repoID int64 ) ([]* ActionArtifact , error ) {
148
- arts := make ([]* ActionArtifact , 0 , 10 )
149
- return arts , db .GetEngine (ctx ).Where ("repo_id=?" , repoID ).Find (& arts )
150
- }
151
-
152
- // ListArtifactsByRunIDAndName returns artifacts by name of a run
153
- func ListArtifactsByRunIDAndName (ctx context.Context , runID int64 , name string ) ([]* ActionArtifact , error ) {
154
- arts := make ([]* ActionArtifact , 0 , 10 )
155
- return arts , db .GetEngine (ctx ).Where ("run_id=? AND artifact_name=?" , runID , name ).Find (& arts )
156
- }
157
-
158
156
// ListNeedExpiredArtifacts returns all need expired artifacts but not deleted
159
157
func ListNeedExpiredArtifacts (ctx context.Context ) ([]* ActionArtifact , error ) {
160
158
arts := make ([]* ActionArtifact , 0 , 10 )
0 commit comments