@@ -98,15 +98,16 @@ type ViewRequest struct {
9898type ViewResponse struct {
9999 State struct {
100100 Run struct {
101- Link string `json:"link"`
102- Title string `json:"title"`
103- Status string `json:"status"`
104- CanCancel bool `json:"canCancel"`
105- CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
106- CanRerun bool `json:"canRerun"`
107- Done bool `json:"done"`
108- Jobs []* ViewJob `json:"jobs"`
109- Commit ViewCommit `json:"commit"`
101+ Link string `json:"link"`
102+ Title string `json:"title"`
103+ Status string `json:"status"`
104+ CanCancel bool `json:"canCancel"`
105+ CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
106+ CanRerun bool `json:"canRerun"`
107+ CanDeleteArtifact bool `json:"canDeleteArtifact"`
108+ Done bool `json:"done"`
109+ Jobs []* ViewJob `json:"jobs"`
110+ Commit ViewCommit `json:"commit"`
110111 } `json:"run"`
111112 CurrentJob struct {
112113 Title string `json:"title"`
@@ -187,6 +188,7 @@ func ViewPost(ctx *context_module.Context) {
187188 resp .State .Run .CanCancel = ! run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
188189 resp .State .Run .CanApprove = run .NeedApproval && ctx .Repo .CanWrite (unit .TypeActions )
189190 resp .State .Run .CanRerun = run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
191+ resp .State .Run .CanDeleteArtifact = run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
190192 resp .State .Run .Done = run .Status .IsDone ()
191193 resp .State .Run .Jobs = make ([]* ViewJob , 0 , len (jobs )) // marshal to '[]' instead fo 'null' in json
192194 resp .State .Run .Status = run .Status .String ()
@@ -576,6 +578,29 @@ func ArtifactsView(ctx *context_module.Context) {
576578 ctx .JSON (http .StatusOK , artifactsResponse )
577579}
578580
581+ func ArtifactsDeleteView (ctx * context_module.Context ) {
582+ if ! ctx .Repo .CanWrite (unit .TypeActions ) {
583+ ctx .Error (http .StatusForbidden , "no permission" )
584+ return
585+ }
586+
587+ runIndex := ctx .ParamsInt64 ("run" )
588+ artifactName := ctx .Params ("artifact_name" )
589+
590+ run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
591+ if err != nil {
592+ ctx .NotFoundOrServerError ("GetRunByIndex" , func (err error ) bool {
593+ return errors .Is (err , util .ErrNotExist )
594+ }, err )
595+ return
596+ }
597+ if err = actions_model .SetArtifactNeedDelete (ctx , run .ID , artifactName ); err != nil {
598+ ctx .Error (http .StatusInternalServerError , err .Error ())
599+ return
600+ }
601+ ctx .JSON (http .StatusOK , struct {}{})
602+ }
603+
579604func ArtifactsDownloadView (ctx * context_module.Context ) {
580605 runIndex := ctx .ParamsInt64 ("run" )
581606 artifactName := ctx .Params ("artifact_name" )
@@ -603,6 +628,14 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
603628 return
604629 }
605630
631+ // if artifacts status is not uploaded-confirmed, treat it as not found
632+ for _ , art := range artifacts {
633+ if art .Status != int64 (actions_model .ArtifactStatusUploadConfirmed ) {
634+ ctx .Error (http .StatusNotFound , "artifact not found" )
635+ return
636+ }
637+ }
638+
606639 ctx .Resp .Header ().Set ("Content-Disposition" , fmt .Sprintf ("attachment; filename=%s.zip; filename*=UTF-8''%s.zip" , url .PathEscape (artifactName ), artifactName ))
607640
608641 writer := zip .NewWriter (ctx .Resp )
0 commit comments