@@ -57,15 +57,16 @@ type ViewRequest struct {
57
57
type ViewResponse struct {
58
58
State struct {
59
59
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"`
69
70
} `json:"run"`
70
71
CurrentJob struct {
71
72
Title string `json:"title"`
@@ -146,6 +147,7 @@ func ViewPost(ctx *context_module.Context) {
146
147
resp .State .Run .CanCancel = ! run .Status .IsDone () && ctx .Repo .CanWrite (unit .TypeActions )
147
148
resp .State .Run .CanApprove = run .NeedApproval && ctx .Repo .CanWrite (unit .TypeActions )
148
149
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 )
149
151
resp .State .Run .Done = run .Status .IsDone ()
150
152
resp .State .Run .Jobs = make ([]* ViewJob , 0 , len (jobs )) // marshal to '[]' instead fo 'null' in json
151
153
resp .State .Run .Status = run .Status .String ()
@@ -535,6 +537,29 @@ func ArtifactsView(ctx *context_module.Context) {
535
537
ctx .JSON (http .StatusOK , artifactsResponse )
536
538
}
537
539
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
+
538
563
func ArtifactsDownloadView (ctx * context_module.Context ) {
539
564
runIndex := ctx .ParamsInt64 ("run" )
540
565
artifactName := ctx .Params ("artifact_name" )
@@ -562,6 +587,14 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
562
587
return
563
588
}
564
589
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
+
565
598
ctx .Resp .Header ().Set ("Content-Disposition" , fmt .Sprintf ("attachment; filename=%s.zip; filename*=UTF-8''%s.zip" , url .PathEscape (artifactName ), artifactName ))
566
599
567
600
writer := zip .NewWriter (ctx .Resp )
0 commit comments