@@ -66,15 +66,25 @@ func View(ctx *context_module.Context) {
66
66
ctx .HTML (http .StatusOK , tplViewActions )
67
67
}
68
68
69
+ type LogCursor struct {
70
+ Step int `json:"step"`
71
+ Cursor int64 `json:"cursor"`
72
+ Expanded bool `json:"expanded"`
73
+ }
74
+
69
75
type ViewRequest struct {
70
- LogCursors []struct {
71
- Step int `json:"step"`
72
- Cursor int64 `json:"cursor"`
73
- Expanded bool `json:"expanded"`
74
- } `json:"logCursors"`
76
+ LogCursors []LogCursor `json:"logCursors"`
77
+ }
78
+
79
+ type ArtifactsViewItem struct {
80
+ Name string `json:"name"`
81
+ Size int64 `json:"size"`
82
+ Status string `json:"status"`
75
83
}
76
84
77
85
type ViewResponse struct {
86
+ Artifacts []* ArtifactsViewItem `json:"artifacts"`
87
+
78
88
State struct {
79
89
Run struct {
80
90
Link string `json:"link"`
@@ -146,6 +156,25 @@ type ViewStepLogLine struct {
146
156
Timestamp float64 `json:"timestamp"`
147
157
}
148
158
159
+ func getActionsViewArtifacts (ctx context.Context , repoID , runIndex int64 ) (artifactsViewItems []* ArtifactsViewItem , err error ) {
160
+ run , err := actions_model .GetRunByIndex (ctx , repoID , runIndex )
161
+ if err != nil {
162
+ return nil , err
163
+ }
164
+ artifacts , err := actions_model .ListUploadedArtifactsMeta (ctx , run .ID )
165
+ if err != nil {
166
+ return nil , err
167
+ }
168
+ for _ , art := range artifacts {
169
+ artifactsViewItems = append (artifactsViewItems , & ArtifactsViewItem {
170
+ Name : art .ArtifactName ,
171
+ Size : art .FileSize ,
172
+ Status : util .Iif (art .Status == actions_model .ArtifactStatusExpired , "expired" , "completed" ),
173
+ })
174
+ }
175
+ return artifactsViewItems , nil
176
+ }
177
+
149
178
func ViewPost (ctx * context_module.Context ) {
150
179
req := web .GetForm (ctx ).(* ViewRequest )
151
180
runIndex := getRunIndex (ctx )
@@ -157,11 +186,19 @@ func ViewPost(ctx *context_module.Context) {
157
186
}
158
187
run := current .Run
159
188
if err := run .LoadAttributes (ctx ); err != nil {
160
- ctx .Error ( http . StatusInternalServerError , err . Error () )
189
+ ctx .ServerError ( "run.LoadAttributes" , err )
161
190
return
162
191
}
163
192
193
+ var err error
164
194
resp := & ViewResponse {}
195
+ resp .Artifacts , err = getActionsViewArtifacts (ctx , ctx .Repo .Repository .ID , runIndex )
196
+ if err != nil {
197
+ if ! errors .Is (err , util .ErrNotExist ) {
198
+ ctx .ServerError ("getActionsViewArtifacts" , err )
199
+ return
200
+ }
201
+ }
165
202
166
203
resp .State .Run .Title = run .Title
167
204
resp .State .Run .Link = run .Link ()
@@ -205,12 +242,12 @@ func ViewPost(ctx *context_module.Context) {
205
242
var err error
206
243
task , err = actions_model .GetTaskByID (ctx , current .TaskID )
207
244
if err != nil {
208
- ctx .Error ( http . StatusInternalServerError , err . Error () )
245
+ ctx .ServerError ( "actions_model.GetTaskByID" , err )
209
246
return
210
247
}
211
248
task .Job = current
212
249
if err := task .LoadAttributes (ctx ); err != nil {
213
- ctx .Error ( http . StatusInternalServerError , err . Error () )
250
+ ctx .ServerError ( "task.LoadAttributes" , err )
214
251
return
215
252
}
216
253
}
@@ -278,7 +315,7 @@ func ViewPost(ctx *context_module.Context) {
278
315
offset := task .LogIndexes [index ]
279
316
logRows , err := actions .ReadLogs (ctx , task .LogInStorage , task .LogFilename , offset , length )
280
317
if err != nil {
281
- ctx .Error ( http . StatusInternalServerError , err . Error () )
318
+ ctx .ServerError ( "actions.ReadLogs" , err )
282
319
return
283
320
}
284
321
@@ -555,49 +592,6 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
555
592
return jobs [0 ], jobs
556
593
}
557
594
558
- type ArtifactsViewResponse struct {
559
- Artifacts []* ArtifactsViewItem `json:"artifacts"`
560
- }
561
-
562
- type ArtifactsViewItem struct {
563
- Name string `json:"name"`
564
- Size int64 `json:"size"`
565
- Status string `json:"status"`
566
- }
567
-
568
- func ArtifactsView (ctx * context_module.Context ) {
569
- runIndex := getRunIndex (ctx )
570
- run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
571
- if err != nil {
572
- if errors .Is (err , util .ErrNotExist ) {
573
- ctx .Error (http .StatusNotFound , err .Error ())
574
- return
575
- }
576
- ctx .Error (http .StatusInternalServerError , err .Error ())
577
- return
578
- }
579
- artifacts , err := actions_model .ListUploadedArtifactsMeta (ctx , run .ID )
580
- if err != nil {
581
- ctx .Error (http .StatusInternalServerError , err .Error ())
582
- return
583
- }
584
- artifactsResponse := ArtifactsViewResponse {
585
- Artifacts : make ([]* ArtifactsViewItem , 0 , len (artifacts )),
586
- }
587
- for _ , art := range artifacts {
588
- status := "completed"
589
- if art .Status == actions_model .ArtifactStatusExpired {
590
- status = "expired"
591
- }
592
- artifactsResponse .Artifacts = append (artifactsResponse .Artifacts , & ArtifactsViewItem {
593
- Name : art .ArtifactName ,
594
- Size : art .FileSize ,
595
- Status : status ,
596
- })
597
- }
598
- ctx .JSON (http .StatusOK , artifactsResponse )
599
- }
600
-
601
595
func ArtifactsDeleteView (ctx * context_module.Context ) {
602
596
if ! ctx .Repo .CanWrite (unit .TypeActions ) {
603
597
ctx .Error (http .StatusForbidden , "no permission" )
0 commit comments