@@ -57,15 +57,16 @@ type ViewRequest struct {
5757type ViewResponse struct {
5858 State struct {
5959 Run struct {
60- Link string `json:"link"`
61- Title string `json:"title"`
62- Status string `json:"status"`
63- CanCancel bool `json:"canCancel"`
64- CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
65- CanRerun bool `json:"canRerun"`
66- Done bool `json:"done"`
67- Jobs []* ViewJob `json:"jobs"`
68- Commit ViewCommit `json:"commit"`
60+ Link string `json:"link"`
61+ Title string `json:"title"`
62+ Status string `json:"status"`
63+ CanCancel bool `json:"canCancel"`
64+ CanApprove bool `json:"canApprove"` // the run needs an approval and the doer has permission to approve
65+ CanRerun bool `json:"canRerun"`
66+ CanDeleteArtifact bool `json:"canDeleteArtifact"`
67+ Done bool `json:"done"`
68+ Jobs []* ViewJob `json:"jobs"`
69+ Commit ViewCommit `json:"commit"`
6970 } `json:"run"`
7071 CurrentJob struct {
7172 Title string `json:"title"`
@@ -146,6 +147,7 @@ func ViewPost(ctx *context_module.Context) {
146147 resp .State .Run .CanCancel = ! run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
147148 resp .State .Run .CanApprove = run .NeedApproval && ctx .Repo .CanWrite (unit .TypeActions )
148149 resp .State .Run .CanRerun = run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
150+ resp .State .Run .CanDeleteArtifact = run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
149151 resp .State .Run .Done = run .Status .IsDone ()
150152 resp .State .Run .Jobs = make ([]* ViewJob , 0 , len (jobs )) // marshal to '[]' instead fo 'null' in json
151153 resp .State .Run .Status = run .Status .String ()
@@ -535,6 +537,29 @@ func ArtifactsView(ctx *context_module.Context) {
535537 ctx .JSON (http .StatusOK , artifactsResponse )
536538}
537539
540+ func ArtifactsDeleteView (ctx * context_module.Context ) {
541+ if ! ctx .Repo .CanWrite (unit .TypeActions ) {
542+ ctx .Error (http .StatusForbidden , "no permission" )
543+ return
544+ }
545+
546+ runIndex := ctx .ParamsInt64 ("run" )
547+ artifactName := ctx .Params ("artifact_name" )
548+
549+ run , err := actions_model .GetRunByIndex (ctx , ctx .Repo .Repository .ID , runIndex )
550+ if err != nil {
551+ ctx .NotFoundOrServerError ("GetRunByIndex" , func (err error ) bool {
552+ return errors .Is (err , util .ErrNotExist )
553+ }, err )
554+ return
555+ }
556+ if err = actions_model .SetArtifactNeedDelete (ctx , run .ID , artifactName ); err != nil {
557+ ctx .Error (http .StatusInternalServerError , err .Error ())
558+ return
559+ }
560+ ctx .JSON (http .StatusOK , struct {}{})
561+ }
562+
538563func ArtifactsDownloadView (ctx * context_module.Context ) {
539564 runIndex := ctx .ParamsInt64 ("run" )
540565 artifactName := ctx .Params ("artifact_name" )
@@ -562,6 +587,14 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
562587 return
563588 }
564589
590+ // if artifacts status is not uploaded-confirmed, treat it as not found
591+ for _ , art := range artifacts {
592+ if art .Status != int64 (actions_model .ArtifactStatusUploadConfirmed ) {
593+ ctx .Error (http .StatusNotFound , "artifact not found" )
594+ return
595+ }
596+ }
597+
565598 ctx .Resp .Header ().Set ("Content-Disposition" , fmt .Sprintf ("attachment; filename=%s.zip; filename*=UTF-8''%s.zip" , url .PathEscape (artifactName ), artifactName ))
566599
567600 writer := zip .NewWriter (ctx .Resp )
0 commit comments