Skip to content

Commit c8dbc29

Browse files
author
zsbahtiar
committed
feat(web): add path DELETE /username/reponame/actions/runs/{id}
1 parent 5358fc5 commit c8dbc29

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

routers/web/repo/actions/actions.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package actions
66
import (
77
"bytes"
88
stdCtx "context"
9+
"fmt"
910
"net/http"
1011
"slices"
12+
"strconv"
1113
"strings"
1214

1315
actions_model "code.gitea.io/gitea/models/actions"
@@ -424,3 +426,30 @@ func decodeNode(node yaml.Node, out any) bool {
424426
}
425427
return true
426428
}
429+
430+
func DeleteRun(ctx *context.Context) {
431+
actionRunIDStr := ctx.PathParam("id")
432+
if len(actionRunIDStr) < 1 {
433+
ctx.ServerError("missing action_run.id for delete action run", nil)
434+
return
435+
}
436+
actionRunID, err := strconv.ParseInt(actionRunIDStr, 10, 64)
437+
if err != nil {
438+
ctx.ServerError("failed to casting action_run.id string to int64", err)
439+
return
440+
}
441+
442+
actionRun, err := actions_model.GetRunByID(ctx, actionRunID)
443+
if err != nil {
444+
ctx.ServerError("failed to get action_run", err)
445+
return
446+
}
447+
err = actions_model.DeleteRunByID(ctx, actionRun.ID)
448+
if err != nil {
449+
ctx.ServerError("failed to delete action_run", err)
450+
return
451+
}
452+
ctx.JSON(http.StatusOK, map[string]any{
453+
"redirect": fmt.Sprintf("%s/actions", ctx.Repo.RepoLink),
454+
})
455+
}

routers/web/web.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,8 @@ func registerRoutes(m *web.Router) {
14341434
m.Group("/workflows/{workflow_name}", func() {
14351435
m.Get("/badge.svg", actions.GetWorkflowBadge)
14361436
})
1437+
1438+
m.Delete("/runs/{id}", reqRepoActionsReader, actions.DeleteRun)
14371439
}, optSignIn, context.RepoAssignment, repo.MustBeNotEmpty, reqRepoActionsReader, actions.MustEnableActions)
14381440
// end "/{username}/{reponame}/actions"
14391441

0 commit comments

Comments
 (0)