@@ -1061,6 +1061,73 @@ func GetArtifactsOfRun(ctx *context.APIContext) {
10611061 ctx .JSON (http .StatusOK , & res )
10621062}
10631063
1064+ // DeleteActionRun Delete a workflow run
1065+ func DeleteActionRun (ctx * context.APIContext ) {
1066+ // swagger:operation DELETE /repos/{owner}/{repo}/actions/runs/{run} repository deleteActionRun
1067+ // ---
1068+ // summary: Delete a workflow run
1069+ // produces:
1070+ // - application/json
1071+ // parameters:
1072+ // - name: owner
1073+ // in: path
1074+ // description: name of the owner
1075+ // type: string
1076+ // required: true
1077+ // - name: repo
1078+ // in: path
1079+ // description: name of the repository
1080+ // type: string
1081+ // required: true
1082+ // - name: run
1083+ // in: path
1084+ // description: runid of the workflow run
1085+ // type: integer
1086+ // required: true
1087+ // responses:
1088+ // "204":
1089+ // description: "No Content"
1090+ // "400":
1091+ // "$ref": "#/responses/error"
1092+ // "404":
1093+ // "$ref": "#/responses/notFound"
1094+
1095+ repoID := ctx .Repo .Repository .ID
1096+ runIndex := ctx .PathParamInt64 ("run" )
1097+
1098+ run , err := actions_model .GetRunByIndex (ctx , repoID , runIndex )
1099+ if err != nil {
1100+ if errors .Is (err , util .ErrNotExist ) {
1101+ ctx .APIError (http .StatusNotFound , err .Error ())
1102+ return
1103+ }
1104+ ctx .APIErrorInternal (err )
1105+ return
1106+ }
1107+ if ! run .Status .IsDone () {
1108+ ctx .APIError (http .StatusBadRequest , "Run not done yet" )
1109+ return
1110+ }
1111+
1112+ jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
1113+ if err != nil {
1114+ ctx .APIErrorInternal (err )
1115+ return
1116+ }
1117+
1118+ // TODO: ?
1119+ if len (jobs ) == 0 {
1120+ ctx .Status (http .StatusNoContent )
1121+ return
1122+ }
1123+
1124+ if err := actions_model .DeleteRun (ctx , repoID , run , jobs ); err != nil {
1125+ ctx .APIErrorInternal (err )
1126+ return
1127+ }
1128+ ctx .Status (http .StatusNoContent )
1129+ }
1130+
10641131// GetArtifacts Lists all artifacts for a repository.
10651132func GetArtifacts (ctx * context.APIContext ) {
10661133 // swagger:operation GET /repos/{owner}/{repo}/actions/artifacts repository getArtifacts
0 commit comments