Skip to content

Commit 32b6aef

Browse files
committed
Artifacts download api for artifact actions v4
* download endpoint has to use 302 redirect * fake blob download used if direct download not possible * downloading v3 artifacts not possible New apis based on GitHub Rest V3 /runs/{run}/artifacts (Cannot use run index of url due to not beeing unique) /artifacts /artifacts/{artifact_id}/zip
1 parent 09a3b07 commit 32b6aef

File tree

5 files changed

+402
-4
lines changed

5 files changed

+402
-4
lines changed

models/actions/artifact.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ func UpdateArtifactByID(ctx context.Context, id int64, art *ActionArtifact) erro
108108

109109
type FindArtifactsOptions struct {
110110
db.ListOptions
111-
RepoID int64
112-
RunID int64
113-
ArtifactName string
114-
Status int
111+
RepoID int64
112+
RunID int64
113+
ArtifactName string
114+
Status int
115+
FinalizedArtifactsV2 bool
115116
}
116117

117118
func (opts FindArtifactsOptions) ToConds() builder.Cond {
@@ -128,6 +129,10 @@ func (opts FindArtifactsOptions) ToConds() builder.Cond {
128129
if opts.Status > 0 {
129130
cond = cond.And(builder.Eq{"status": opts.Status})
130131
}
132+
if opts.FinalizedArtifactsV2 {
133+
cond = cond.And(builder.Eq{"status": ArtifactStatusUploadConfirmed}.Or(builder.Eq{"status": ArtifactStatusExpired}))
134+
cond = cond.And(builder.Eq{"content_encoding": "application/zip"})
135+
}
131136

132137
return cond
133138
}

modules/structs/repo_actions.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,33 @@ type ActionTaskResponse struct {
3232
Entries []*ActionTask `json:"workflow_runs"`
3333
TotalCount int64 `json:"total_count"`
3434
}
35+
36+
// ActionTask represents a ActionTask
37+
type ActionArtifact struct {
38+
ID int64 `json:"id"`
39+
Name string `json:"name"`
40+
SizeInBytes int64 `json:"size_in_bytes"`
41+
URL string `json:"url"`
42+
ArchiveDownloadURL string `json:"archive_download_url"`
43+
Expired bool `json:"expired"`
44+
WorkflowRun *ActionWorkflowRun `json:"workflow_run"`
45+
46+
// swagger:strfmt date-time
47+
CreatedAt time.Time `json:"created_at"`
48+
// swagger:strfmt date-time
49+
UpdatedAt time.Time `json:"updated_at"`
50+
// swagger:strfmt date-time
51+
ExpiresAt time.Time `json:"expires_at"`
52+
}
53+
54+
type ActionWorkflowRun struct {
55+
ID int64 `json:"id"`
56+
RepositoryID int64 `json:"repository_id"`
57+
HeadSha string `json:"head_sha"`
58+
}
59+
60+
// ActionArtifactsResponse returns a ActionTask
61+
type ActionArtifactsResponse struct {
62+
Entries []*ActionArtifact `json:"artifacts"`
63+
TotalCount int64 `json:"total_count"`
64+
}

routers/api/v1/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,10 @@ func Routes() *web.Router {
12351235
}, reqToken(), reqAdmin())
12361236
m.Group("/actions", func() {
12371237
m.Get("/tasks", repo.ListActionTasks)
1238+
m.Get("/runs/{run}/artifacts", repo.GetArtifactsOfRun)
1239+
m.Get("/artifacts", repo.GetArtifacts)
1240+
m.Get("/artifacts/{artifact_id}/zip", repo.DownloadArtifact)
1241+
m.Get("/artifacts/{artifact_id}/zip/raw", repo.DownloadArtifactRaw)
12381242
}, reqRepoReader(unit.TypeActions), context.ReferencesGitRepo(true))
12391243
m.Group("/keys", func() {
12401244
m.Combo("").Get(repo.ListDeployKeys).

0 commit comments

Comments
 (0)