From ef7f7e2a5cb152b7e0c391fc0f0f0f98e927da1d Mon Sep 17 00:00:00 2001 From: Ross Golder Date: Thu, 23 Oct 2025 22:27:48 +0700 Subject: [PATCH] Move run time reset logic to shared actions_service.ResetRunTimes function --- routers/api/v1/repo/actions_run.go | 22 ++++++---------------- services/actions/rerun.go | 13 +++++++++++++ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/routers/api/v1/repo/actions_run.go b/routers/api/v1/repo/actions_run.go index da51f362fd..d3e62575c4 100644 --- a/routers/api/v1/repo/actions_run.go +++ b/routers/api/v1/repo/actions_run.go @@ -126,14 +126,9 @@ func RerunWorkflowRun(ctx *context.APIContext) { } // Reset run's start and stop time when it is done - if run.Status.IsDone() { - run.PreviousDuration = run.Duration() - run.Started = 0 - run.Stopped = 0 - if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil { - ctx.APIErrorInternal(err) - return - } + if err := actions_service.ResetRunTimes(ctx, run); err != nil { + ctx.APIErrorInternal(err) + return } jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID) @@ -425,14 +420,9 @@ func RerunWorkflowJob(ctx *context.APIContext) { } // Reset run's start and stop time when it is done - if run.Status.IsDone() { - run.PreviousDuration = run.Duration() - run.Started = 0 - run.Stopped = 0 - if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil { - ctx.APIErrorInternal(err) - return - } + if err := actions_service.ResetRunTimes(ctx, run); err != nil { + ctx.APIErrorInternal(err) + return } // Get all jobs that need to be rerun (including dependencies) diff --git a/services/actions/rerun.go b/services/actions/rerun.go index 60f6650905..991b13b4cc 100644 --- a/services/actions/rerun.go +++ b/services/actions/rerun.go @@ -4,10 +4,23 @@ package actions import ( + "context" + actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/modules/container" ) +// ResetRunTimes resets the start and stop times for a run when it is done, for rerun +func ResetRunTimes(ctx context.Context, run *actions_model.ActionRun) error { + if run.Status.IsDone() { + run.PreviousDuration = run.Duration() + run.Started = 0 + run.Stopped = 0 + return actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration") + } + return nil +} + // GetAllRerunJobs get all jobs that need to be rerun when job should be rerun func GetAllRerunJobs(job *actions_model.ActionRunJob, allJobs []*actions_model.ActionRunJob) []*actions_model.ActionRunJob { rerunJobs := []*actions_model.ActionRunJob{job}