From c69cbb75bfc0cbf80865095eb8a040575ce95ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalash=20Thakare=20=E2=98=AF=EF=B8=8E?= Date: Wed, 22 Apr 2026 02:44:34 +0530 Subject: [PATCH] fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (#37288) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes #37252 The `/api/v1/repos/{owner}/{repo}/actions/runs` endpoint was returning `event: "push"` for workflow runs triggered by `schedule:` (cron), instead of `event: "schedule"`. ## Root Cause `ActionRun` has two separate fields: - `Event` — the workflow registration event (e.g. `push`, set when the workflow file was first pushed) - `TriggerEvent` — the actual event that triggered the run (e.g. `schedule`) `ToActionWorkflowRun` in `services/convert/action.go` was serializing `run.Event` into the API response instead of `run.TriggerEvent`, causing scheduled runs to be indistinguishable from push events via the API. This was already asymmetric — the tasks/jobs API correctly used `TriggerEvent`. ## Fix Changed `ToActionWorkflowRun` to use `run.TriggerEvent` for the `event` field in the API response, consistent with how the jobs API works. ## Before `event: "push"` returned for all scheduled runs: Screenshot 2026-04-19 115642 ## After `event: "schedule"` correctly returned for scheduled runs: Screenshot 2026-04-19 121723 ## Testing - Added unit test `TestToActionWorkflowRun_UsesTriggerEvent` in `services/convert/action_test.go` that explicitly verifies the API returns `TriggerEvent` and not `Event` for a scheduled run. - Manually verified via the API against a live Gitea instance with a `cron: "* * * * *"` workflow. --------- Co-authored-by: Nicolas --- models/fixtures/action_run.yml | 2 +- services/convert/action_test.go | 17 +++++++++++++++++ services/convert/convert.go | 2 +- .../integration/workflow_run_api_check_test.go | 4 ++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/models/fixtures/action_run.yml b/models/fixtures/action_run.yml index b7d1201189f..1df02e48090 100644 --- a/models/fixtures/action_run.yml +++ b/models/fixtures/action_run.yml @@ -89,7 +89,7 @@ ref: "refs/heads/test" commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0" event: "push" - trigger_event: "push" + trigger_event: "schedule" is_fork_pull_request: 0 status: 1 started: 1683636528 diff --git a/services/convert/action_test.go b/services/convert/action_test.go index 7080fc2f146..a0a16cb0faa 100644 --- a/services/convert/action_test.go +++ b/services/convert/action_test.go @@ -8,8 +8,10 @@ import ( "strings" "testing" + actions_model "code.gitea.io/gitea/models/actions" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git/gitcmd" "code.gitea.io/gitea/modules/util" @@ -107,3 +109,18 @@ func TestGetActionWorkflow_FallbackRef(t *testing.T) { assert.ErrorIs(t, err, util.ErrNotExist) }) } + +func TestToActionWorkflowRun_UsesTriggerEvent(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) + run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: 803}) + + // Scheduled runs keep Event as the registration event (push) and use TriggerEvent as the real trigger. + run.Event = "push" + run.TriggerEvent = "schedule" + + apiRun, err := ToActionWorkflowRun(t.Context(), repo, run) + require.NoError(t, err) + assert.Equal(t, "schedule", apiRun.Event) +} diff --git a/services/convert/convert.go b/services/convert/convert.go index f7a207622be..269defe6a11 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -260,7 +260,7 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run * RunNumber: run.Index, StartedAt: run.Started.AsLocalTime(), CompletedAt: run.Stopped.AsLocalTime(), - Event: string(run.Event), + Event: run.TriggerEvent, DisplayTitle: run.Title, HeadBranch: git.RefName(run.Ref).BranchName(), HeadSha: run.CommitSHA, diff --git a/tests/integration/workflow_run_api_check_test.go b/tests/integration/workflow_run_api_check_test.go index 6a80bb51186..8efcf18f8b0 100644 --- a/tests/integration/workflow_run_api_check_test.go +++ b/tests/integration/workflow_run_api_check_test.go @@ -44,6 +44,10 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL, userUsername string, runI foundRun := false for _, run := range runnerList.Entries { + if run.ID == 802 { + // Fixture stores registration event (push) and schedule as trigger; API must expose the trigger as Event. + assert.Equal(t, "schedule", run.Event) + } // Verify filtering works verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "", "") verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "", "")