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, "", "", "", "", "")