Skip to content

Commit fc9dfe0

Browse files
GiteaBotKalashThakarebircni
authored
fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (#37288) (#37360)
Backport #37288 by @KalashThakare ## 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: <img width="1112" height="191" alt="Screenshot 2026-04-19 115642" src="https://github.com/user-attachments/assets/c0a169f5-bbd9-4f5d-9474-e4c3795110e4" /> ## After `event: "schedule"` correctly returned for scheduled runs: <img width="890" height="166" alt="Screenshot 2026-04-19 121723" src="https://github.com/user-attachments/assets/860e99ac-0935-4a43-86a1-7b60f8113480" /> ## 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: Kalash Thakare ☯︎ <kalashthakare898@gmail.com> Co-authored-by: Nicolas <bircni@icloud.com>
1 parent 0916039 commit fc9dfe0

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

models/fixtures/action_run.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
ref: "refs/heads/test"
9090
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
9191
event: "push"
92-
trigger_event: "push"
92+
trigger_event: "schedule"
9393
is_fork_pull_request: 0
9494
status: 1
9595
started: 1683636528

services/convert/action_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import (
88
"strings"
99
"testing"
1010

11+
actions_model "code.gitea.io/gitea/models/actions"
1112
repo_model "code.gitea.io/gitea/models/repo"
1213
"code.gitea.io/gitea/models/unit"
14+
"code.gitea.io/gitea/models/unittest"
1315
"code.gitea.io/gitea/modules/git"
1416
"code.gitea.io/gitea/modules/git/gitcmd"
1517
"code.gitea.io/gitea/modules/util"
@@ -107,3 +109,18 @@ func TestGetActionWorkflow_FallbackRef(t *testing.T) {
107109
assert.ErrorIs(t, err, util.ErrNotExist)
108110
})
109111
}
112+
113+
func TestToActionWorkflowRun_UsesTriggerEvent(t *testing.T) {
114+
assert.NoError(t, unittest.PrepareTestDatabase())
115+
116+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
117+
run := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{ID: 803})
118+
119+
// Scheduled runs keep Event as the registration event (push) and use TriggerEvent as the real trigger.
120+
run.Event = "push"
121+
run.TriggerEvent = "schedule"
122+
123+
apiRun, err := ToActionWorkflowRun(t.Context(), repo, run)
124+
require.NoError(t, err)
125+
assert.Equal(t, "schedule", apiRun.Event)
126+
}

services/convert/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *
260260
RunNumber: run.Index,
261261
StartedAt: run.Started.AsLocalTime(),
262262
CompletedAt: run.Stopped.AsLocalTime(),
263-
Event: string(run.Event),
263+
Event: run.TriggerEvent,
264264
DisplayTitle: run.Title,
265265
HeadBranch: git.RefName(run.Ref).BranchName(),
266266
HeadSha: run.CommitSHA,

tests/integration/workflow_run_api_check_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func testAPIWorkflowRunBasic(t *testing.T, apiRootURL, userUsername string, runI
4444
foundRun := false
4545

4646
for _, run := range runnerList.Entries {
47+
if run.ID == 802 {
48+
// Fixture stores registration event (push) and schedule as trigger; API must expose the trigger as Event.
49+
assert.Equal(t, "schedule", run.Event)
50+
}
4751
// Verify filtering works
4852
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, "", run.Status, "", "", "", "")
4953
verifyWorkflowRunCanbeFoundWithStatusFilter(t, apiRunsURL, token, run.ID, run.Conclusion, "", "", "", "", "")

0 commit comments

Comments
 (0)