Skip to content

Commit b92b3c5

Browse files
committed
API endpoint
1 parent 29a0fe5 commit b92b3c5

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

routers/api/v1/api.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,10 @@ func Routes() *web.Router {
12791279
}, reqToken(), reqAdmin())
12801280
m.Group("/actions", func() {
12811281
m.Get("/tasks", repo.ListActionTasks)
1282-
m.Get("/runs/{run}/artifacts", repo.GetArtifactsOfRun)
1282+
m.Group("/runs/{run}", func() {
1283+
m.Get("/artifacts", repo.GetArtifactsOfRun)
1284+
m.Delete("", reqRepoWriter(unit.TypeActions), repo.DeleteActionRun)
1285+
})
12831286
m.Get("/artifacts", repo.GetArtifacts)
12841287
m.Group("/artifacts/{artifact_id}", func() {
12851288
m.Get("", repo.GetArtifact)

routers/api/v1/repo/action.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
10651132
func GetArtifacts(ctx *context.APIContext) {
10661133
// swagger:operation GET /repos/{owner}/{repo}/actions/artifacts repository getArtifacts

0 commit comments

Comments
 (0)