@@ -14,7 +14,6 @@ import (
14
14
"net/http"
15
15
"net/url"
16
16
"strconv"
17
- "strings"
18
17
"time"
19
18
20
19
actions_model "code.gitea.io/gitea/models/actions"
@@ -31,6 +30,7 @@ import (
31
30
"code.gitea.io/gitea/modules/timeutil"
32
31
"code.gitea.io/gitea/modules/util"
33
32
"code.gitea.io/gitea/modules/web"
33
+ "code.gitea.io/gitea/routers/common"
34
34
actions_service "code.gitea.io/gitea/services/actions"
35
35
context_module "code.gitea.io/gitea/services/context"
36
36
notify_service "code.gitea.io/gitea/services/notify"
@@ -469,49 +469,19 @@ func Logs(ctx *context_module.Context) {
469
469
runIndex := getRunIndex (ctx )
470
470
jobIndex := ctx .PathParamInt64 ("job" )
471
471
472
- job , _ := getRunJobs (ctx , runIndex , jobIndex )
473
- if ctx .Written () {
474
- return
475
- }
476
- if job .TaskID == 0 {
477
- ctx .HTTPError (http .StatusNotFound , "job is not started" )
478
- return
479
- }
480
-
481
- err := job .LoadRun (ctx )
482
- if err != nil {
483
- ctx .HTTPError (http .StatusInternalServerError , err .Error ())
484
- return
485
- }
486
-
487
- task , err := actions_model .GetTaskByID (ctx , job .TaskID )
488
- if err != nil {
489
- ctx .HTTPError (http .StatusInternalServerError , err .Error ())
490
- return
491
- }
492
- if task .LogExpired {
493
- ctx .HTTPError (http .StatusNotFound , "logs have been cleaned up" )
494
- return
495
- }
496
-
497
- reader , err := actions .OpenLogs (ctx , task .LogInStorage , task .LogFilename )
472
+ run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
498
473
if err != nil {
499
- ctx .HTTPError (http .StatusInternalServerError , err .Error ())
474
+ ctx .NotFoundOrServerError ("GetRunByIndex" , func (err error ) bool {
475
+ return errors .Is (err , util .ErrNotExist )
476
+ }, err )
500
477
return
501
478
}
502
- defer reader .Close ()
503
479
504
- workflowName := job .Run .WorkflowID
505
- if p := strings .Index (workflowName , "." ); p > 0 {
506
- workflowName = workflowName [0 :p ]
480
+ if err = common .DownloadActionsRunJobLogsWithIndex (ctx .Base , ctx .Repo .Repository , run .ID , jobIndex ); err != nil {
481
+ ctx .NotFoundOrServerError ("DownloadActionsRunJobLogsWithIndex" , func (err error ) bool {
482
+ return errors .Is (err , util .ErrNotExist )
483
+ }, err )
507
484
}
508
- ctx .ServeContent (reader , & context_module.ServeHeaderOptions {
509
- Filename : fmt .Sprintf ("%v-%v-%v.log" , workflowName , job .Name , task .ID ),
510
- ContentLength : & task .LogSize ,
511
- ContentType : "text/plain" ,
512
- ContentTypeCharset : "utf-8" ,
513
- Disposition : "attachment" ,
514
- })
515
485
}
516
486
517
487
func Cancel (ctx * context_module.Context ) {
0 commit comments