@ -63,6 +63,7 @@ type ViewResponse struct {
CanCancel bool ` json:"canCancel" `
CanApprove bool ` json:"canApprove" ` // the run needs an approval and the doer has permission to approve
CanRerun bool ` json:"canRerun" `
CanDeleteArtifact bool ` json:"canDeleteArtifact" `
Done bool ` json:"done" `
Jobs [ ] * ViewJob ` json:"jobs" `
Commit ViewCommit ` json:"commit" `
@ -146,6 +147,7 @@ func ViewPost(ctx *context_module.Context) {
resp . State . Run . CanCancel = ! run . Status . IsDone ( ) && ctx . Repo . CanWrite ( unit . TypeActions )
resp . State . Run . CanApprove = run . NeedApproval && ctx . Repo . CanWrite ( unit . TypeActions )
resp . State . Run . CanRerun = run . Status . IsDone ( ) && ctx . Repo . CanWrite ( unit . TypeActions )
resp . State . Run . CanDeleteArtifact = run . Status . IsDone ( ) && ctx . Repo . CanWrite ( unit . TypeActions )
resp . State . Run . Done = run . Status . IsDone ( )
resp . State . Run . Jobs = make ( [ ] * ViewJob , 0 , len ( jobs ) ) // marshal to '[]' instead fo 'null' in json
resp . State . Run . Status = run . Status . String ( )
@ -535,6 +537,29 @@ func ArtifactsView(ctx *context_module.Context) {
ctx . JSON ( http . StatusOK , artifactsResponse )
}
func ArtifactsDeleteView ( ctx * context_module . Context ) {
if ! ctx . Repo . CanWrite ( unit . TypeActions ) {
ctx . Error ( http . StatusForbidden , "no permission" )
return
}
runIndex := ctx . ParamsInt64 ( "run" )
artifactName := ctx . Params ( "artifact_name" )
run , err := actions_model . GetRunByIndex ( ctx , ctx . Repo . Repository . ID , runIndex )
if err != nil {
ctx . NotFoundOrServerError ( "GetRunByIndex" , func ( err error ) bool {
return errors . Is ( err , util . ErrNotExist )
} , err )
return
}
if err = actions_model . SetArtifactNeedDelete ( ctx , run . ID , artifactName ) ; err != nil {
ctx . Error ( http . StatusInternalServerError , err . Error ( ) )
return
}
ctx . JSON ( http . StatusOK , struct { } { } )
}
func ArtifactsDownloadView ( ctx * context_module . Context ) {
runIndex := ctx . ParamsInt64 ( "run" )
artifactName := ctx . Params ( "artifact_name" )
@ -562,6 +587,14 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
return
}
// if artifacts status is not uploaded-confirmed, treat it as not found
for _ , art := range artifacts {
if art . Status != int64 ( actions_model . ArtifactStatusUploadConfirmed ) {
ctx . Error ( http . StatusNotFound , "artifact not found" )
return
}
}
ctx . Resp . Header ( ) . Set ( "Content-Disposition" , fmt . Sprintf ( "attachment; filename=%s.zip; filename*=UTF-8''%s.zip" , url . PathEscape ( artifactName ) , artifactName ) )
writer := zip . NewWriter ( ctx . Resp )