@@ -66,15 +66,25 @@ func View(ctx *context_module.Context) {
6666 ctx .HTML (http .StatusOK , tplViewActions )
6767}
6868
69+ type LogCursor struct {
70+ Step int `json:"step"`
71+ Cursor int64 `json:"cursor"`
72+ Expanded bool `json:"expanded"`
73+ }
74+
6975type 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"`
7583}
7684
7785type ViewResponse struct {
86+ Artifacts []* ArtifactsViewItem `json:"artifacts"`
87+
7888 State struct {
7989 Run struct {
8090 Link string `json:"link"`
@@ -146,6 +156,25 @@ type ViewStepLogLine struct {
146156 Timestamp float64 `json:"timestamp"`
147157}
148158
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+
149178func ViewPost (ctx * context_module.Context ) {
150179 req := web .GetForm (ctx ).(* ViewRequest )
151180 runIndex := getRunIndex (ctx )
@@ -157,11 +186,19 @@ func ViewPost(ctx *context_module.Context) {
157186 }
158187 run := current .Run
159188 if err := run .LoadAttributes (ctx ); err != nil {
160- ctx .Error ( http . StatusInternalServerError , err . Error () )
189+ ctx .ServerError ( "run.LoadAttributes" , err )
161190 return
162191 }
163192
193+ var err error
164194 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+ }
165202
166203 resp .State .Run .Title = run .Title
167204 resp .State .Run .Link = run .Link ()
@@ -205,12 +242,12 @@ func ViewPost(ctx *context_module.Context) {
205242 var err error
206243 task , err = actions_model .GetTaskByID (ctx , current .TaskID )
207244 if err != nil {
208- ctx .Error ( http . StatusInternalServerError , err . Error () )
245+ ctx .ServerError ( "actions_model.GetTaskByID" , err )
209246 return
210247 }
211248 task .Job = current
212249 if err := task .LoadAttributes (ctx ); err != nil {
213- ctx .Error ( http . StatusInternalServerError , err . Error () )
250+ ctx .ServerError ( "task.LoadAttributes" , err )
214251 return
215252 }
216253 }
@@ -278,7 +315,7 @@ func ViewPost(ctx *context_module.Context) {
278315 offset := task .LogIndexes [index ]
279316 logRows , err := actions .ReadLogs (ctx , task .LogInStorage , task .LogFilename , offset , length )
280317 if err != nil {
281- ctx .Error ( http . StatusInternalServerError , err . Error () )
318+ ctx .ServerError ( "actions.ReadLogs" , err )
282319 return
283320 }
284321
@@ -555,49 +592,6 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
555592 return jobs [0 ], jobs
556593}
557594
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-
601595func ArtifactsDeleteView (ctx * context_module.Context ) {
602596 if ! ctx .Repo .CanWrite (unit .TypeActions ) {
603597 ctx .Error (http .StatusForbidden , "no permission" )
0 commit comments