Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runs_list): add button delete workflow run #33138

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fcd6948
feat(runs_list): add button delete workflow run
Jan 7, 2025
862237c
fix: lint
Jan 7, 2025
5358fc5
feat(action_model): add query DeleteRunByID
Jan 7, 2025
c8dbc29
feat(web): add path DELETE /username/reponame/actions/runs/{id}
Jan 7, 2025
3938aea
feat(initGlobalDeleteButton): add option http method delete when data…
Jan 7, 2025
6c58a02
fix: lint
Jan 7, 2025
8170c47
feat(DeleteRunByID): add delete action_run_job
Jan 7, 2025
60982c7
Merge branch 'main' into feat/actions-delete-workflow-run
zsbahtiar Jan 7, 2025
c4bdf78
refactor: change middleware to reqRepoActionsWriter
Jan 8, 2025
1e75212
feat(websrc): add repo action for handling delete
Jan 8, 2025
aa8a3d0
feat(action.list): add checkbox all and button delete
Jan 8, 2025
b6afdc6
refactor(run_list): change from button delete workflow to checkbox
Jan 8, 2025
8413beb
refactor(action.delete): change to support plural delete action runs
Jan 8, 2025
7f511d9
feat(DeleteRunByIDs): add delete action_task_step, action_task_output…
Jan 8, 2025
3faea22
revert
Jan 8, 2025
0b27261
revert
Jan 8, 2025
050a6b6
feat: add GetRunJobsByRunIDs
Jan 8, 2025
5dd6245
fix: job id
Jan 8, 2025
05af60b
refactor: change to GetRunsByIDsAndTriggerUserID
Jan 8, 2025
80377f8
rm: invalid test
Jan 8, 2025
1390874
feat: add GetRunTasksByJobIDs
Jan 8, 2025
965087e
feat: add removeActionTaskLogFilenames
Jan 8, 2025
71b773a
fix: lint
Jan 8, 2025
1a7a7e7
refactor: change to DeleteActionRunAndChild
Jan 8, 2025
8c742ab
test(integration): add TestRepoActionDelete
Jan 9, 2025
e17f73a
test(integration): add assert error equal
Jan 9, 2025
95924a1
fix: lint
Jan 9, 2025
f389529
fix: job
Jan 9, 2025
530360b
fix: check backend
Jan 9, 2025
5576b10
Merge branch 'main' into feat/actions-delete-workflow-run
silverwind Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,23 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error {
}

type ActionRunIndex db.ResourceIndex

// DeleteRunByID delete action_run and action_run_job.
func DeleteRunByID(ctx context.Context, id int64) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
_, err = db.GetEngine(ctx).Where("id=?", id).Delete(ActionRun{})
if err != nil {
return err
}

_, err = db.GetEngine(ctx).Where("run_id=?", id).Delete(ActionRunJob{})
if err != nil {
return err
}

return committer.Commit()
}
29 changes: 29 additions & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package actions
import (
"bytes"
stdCtx "context"
"fmt"
"net/http"
"slices"
"strconv"
"strings"

actions_model "code.gitea.io/gitea/models/actions"
Expand Down Expand Up @@ -424,3 +426,30 @@ func decodeNode(node yaml.Node, out any) bool {
}
return true
}

func DeleteRun(ctx *context.Context) {
zsbahtiar marked this conversation as resolved.
Show resolved Hide resolved
actionRunIDStr := ctx.PathParam("id")
if len(actionRunIDStr) < 1 {
ctx.ServerError("missing action_run.id for delete action run", nil)
return
}
actionRunID, err := strconv.ParseInt(actionRunIDStr, 10, 64)
if err != nil {
ctx.ServerError("failed to casting action_run.id string to int64", err)
return
}

actionRun, err := actions_model.GetRunByID(ctx, actionRunID)
zsbahtiar marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("failed to get action_run", err)
return
}
err = actions_model.DeleteRunByID(ctx, actionRun.ID)
if err != nil {
ctx.ServerError("failed to delete action_run", err)
return
}
ctx.JSON(http.StatusOK, map[string]any{
"redirect": fmt.Sprintf("%s/actions", ctx.Repo.RepoLink),
})
}
2 changes: 2 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,8 @@ func registerRoutes(m *web.Router) {
m.Group("/workflows/{workflow_name}", func() {
m.Get("/badge.svg", actions.GetWorkflowBadge)
})

m.Delete("/runs/{id}", reqRepoActionsReader, actions.DeleteRun)
zsbahtiar marked this conversation as resolved.
Show resolved Hide resolved
}, optSignIn, context.RepoAssignment, repo.MustBeNotEmpty, reqRepoActionsReader, actions.MustEnableActions)
// end "/{username}/{reponame}/actions"

Expand Down
16 changes: 16 additions & 0 deletions templates/repo/actions/runs_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,25 @@
<div class="run-list-item-right">
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{DateUtils.TimeSince .Updated}}</div>
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{.Duration}}</div>
{{if and (ne .Status 6) (ne .Status 5)}}
<div class="run-list-meta">
<button class="ui red tiny button delete-button name" data-modal-id="modal-delete-workflow" data-url="actions/runs/{{.ID}}" data-name="Delete workflow run {{.ID}}" data-method="delete" name="Delete Workflow {{.ID}}">Delete Workflow</button>
</div>
{{end}}
</div>
</div>
</div>
{{end}}
</div>

<div class="ui g-modal-confirm delete modal" id="modal-delete-workflow">
<div class="header">
<i class="trash icon"></i>
<span class="name"></span>
</div>
<div class="content">
<p>Are you sure you want to permanently delete this workflow run? This action cannot be undone.</p>
</div>
{{template "base/modal_actions_confirm" .}}
</div>
{{template "base/paginate" .}}
7 changes: 5 additions & 2 deletions web_src/js/features/common-button.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {POST} from '../modules/fetch.ts';
import {DELETE, POST} from '../modules/fetch.ts';
import {addDelegatedEventListener, hideElem, queryElems, showElem, toggleElem} from '../utils/dom.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';
import {camelize} from 'vue';
Expand Down Expand Up @@ -62,7 +62,10 @@ export function initGlobalDeleteButton(): void {
}
}

const response = await POST(btn.getAttribute('data-url'), {data: postData});
const method = btn.getAttribute('data-method')?.toUpperCase() || 'POST';
const response = method === 'DELETE' ?
await DELETE(btn.getAttribute('data-url')) :
await POST(btn.getAttribute('data-url'), {data: postData});
if (response.ok) {
zsbahtiar marked this conversation as resolved.
Show resolved Hide resolved
const data = await response.json();
window.location.href = data.redirect;
Expand Down
Loading