@@ -14,6 +14,8 @@ import (
1414 "code.gitea.io/gitea/models/db"
1515 "code.gitea.io/gitea/modules/timeutil"
1616 "code.gitea.io/gitea/modules/util"
17+
18+ "xorm.io/builder"
1719)
1820
1921// 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
108110 return err
109111}
110112
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
115119}
116120
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+ }
122135
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
127137}
128138
129139// ActionArtifactMeta is the meta data of an artifact
130140type ActionArtifactMeta struct {
131141 ArtifactName string
132142 FileSize int64
133- Status int64
143+ Status ArtifactStatus
134144}
135145
136146// ListUploadedArtifactsMeta returns all uploaded artifacts meta of a run
@@ -143,18 +153,6 @@ func ListUploadedArtifactsMeta(ctx context.Context, runID int64) ([]*ActionArtif
143153 Find (& arts )
144154}
145155
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-
158156// ListNeedExpiredArtifacts returns all need expired artifacts but not deleted
159157func ListNeedExpiredArtifacts (ctx context.Context ) ([]* ActionArtifact , error ) {
160158 arts := make ([]* ActionArtifact , 0 , 10 )
0 commit comments