From a4778fc9705caa8f8be032fcad00847d5c78795d Mon Sep 17 00:00:00 2001 From: Jaime merino Date: Mon, 24 Feb 2025 18:14:12 +0000 Subject: [PATCH] fix: job list response to avoid wrapped body. (#7050) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7050 Reviewed-by: Gusted Co-authored-by: Jaime merino Co-committed-by: Jaime merino --- routers/api/v1/shared/runners.go | 10 +--------- routers/api/v1/swagger/action.go | 7 +++++++ tests/integration/api_admin_actions_test.go | 8 ++++---- tests/integration/api_org_actions_test.go | 8 ++++---- tests/integration/api_repo_actions_test.go | 8 ++++---- tests/integration/api_user_actions_test.go | 8 ++++---- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/routers/api/v1/shared/runners.go b/routers/api/v1/shared/runners.go index 53761a07e9..9c27078326 100644 --- a/routers/api/v1/shared/runners.go +++ b/routers/api/v1/shared/runners.go @@ -34,13 +34,6 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) { ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token}) } -// RunJobList is a list of action run jobs -// swagger:response RunJobList -type RunJobList struct { - // in:body - Body []*structs.ActionRunJob `json:"body"` -} - func GetActionRunJobs(ctx *context.APIContext, ownerID, repoID int64) { labels := strings.Split(ctx.FormTrim("labels"), ",") @@ -54,8 +47,7 @@ func GetActionRunJobs(ctx *context.APIContext, ownerID, repoID int64) { return } - res := new(RunJobList) - res.Body = fromRunJobModelToResponse(total, labels) + res := fromRunJobModelToResponse(total, labels) ctx.JSON(http.StatusOK, res) } diff --git a/routers/api/v1/swagger/action.go b/routers/api/v1/swagger/action.go index 665f4d0b85..e7ec6a81e4 100644 --- a/routers/api/v1/swagger/action.go +++ b/routers/api/v1/swagger/action.go @@ -32,3 +32,10 @@ type swaggerResponseVariableList struct { // in:body Body []api.ActionVariable `json:"body"` } + +// RunJobList is a list of action run jobs +// swagger:response RunJobList +type swaggerRunJobList struct { + // in:body + Body []*api.ActionRunJob `json:"body"` +} diff --git a/tests/integration/api_admin_actions_test.go b/tests/integration/api_admin_actions_test.go index 22590dc4c4..fd55f0fd2e 100644 --- a/tests/integration/api_admin_actions_test.go +++ b/tests/integration/api_admin_actions_test.go @@ -11,7 +11,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/routers/api/v1/shared" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -31,9 +31,9 @@ func TestAPISearchActionJobs_GlobalRunner(t *testing.T) { ).AddTokenAuth(token) res := MakeRequest(t, req, http.StatusOK) - var jobs shared.RunJobList + var jobs []*api.ActionRunJob DecodeJSON(t, res, &jobs) - assert.Len(t, jobs.Body, 1) - assert.EqualValues(t, job.ID, jobs.Body[0].ID) + assert.Len(t, jobs, 1) + assert.EqualValues(t, job.ID, jobs[0].ID) } diff --git a/tests/integration/api_org_actions_test.go b/tests/integration/api_org_actions_test.go index c8ebbdf293..8c1948fc4a 100644 --- a/tests/integration/api_org_actions_test.go +++ b/tests/integration/api_org_actions_test.go @@ -11,7 +11,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/routers/api/v1/shared" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -30,9 +30,9 @@ func TestAPISearchActionJobs_OrgRunner(t *testing.T) { AddTokenAuth(token) res := MakeRequest(t, req, http.StatusOK) - var jobs shared.RunJobList + var jobs []*api.ActionRunJob DecodeJSON(t, res, &jobs) - assert.Len(t, jobs.Body, 1) - assert.EqualValues(t, job.ID, jobs.Body[0].ID) + assert.Len(t, jobs, 1) + assert.EqualValues(t, job.ID, jobs[0].ID) } diff --git a/tests/integration/api_repo_actions_test.go b/tests/integration/api_repo_actions_test.go index 9c3b6aa2b6..ec8bb501e3 100644 --- a/tests/integration/api_repo_actions_test.go +++ b/tests/integration/api_repo_actions_test.go @@ -12,7 +12,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" - "code.gitea.io/gitea/routers/api/v1/shared" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -35,9 +35,9 @@ func TestAPISearchActionJobs_RepoRunner(t *testing.T) { ).AddTokenAuth(token) res := MakeRequest(t, req, http.StatusOK) - var jobs shared.RunJobList + var jobs []*api.ActionRunJob DecodeJSON(t, res, &jobs) - assert.Len(t, jobs.Body, 1) - assert.EqualValues(t, job.ID, jobs.Body[0].ID) + assert.Len(t, jobs, 1) + assert.EqualValues(t, job.ID, jobs[0].ID) } diff --git a/tests/integration/api_user_actions_test.go b/tests/integration/api_user_actions_test.go index f9c9c1df4e..a03d4e95ae 100644 --- a/tests/integration/api_user_actions_test.go +++ b/tests/integration/api_user_actions_test.go @@ -11,7 +11,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/unittest" - "code.gitea.io/gitea/routers/api/v1/shared" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -30,9 +30,9 @@ func TestAPISearchActionJobs_UserRunner(t *testing.T) { AddTokenAuth(token) res := MakeRequest(t, req, http.StatusOK) - var jobs shared.RunJobList + var jobs []*api.ActionRunJob DecodeJSON(t, res, &jobs) - assert.Len(t, jobs.Body, 1) - assert.EqualValues(t, job.ID, jobs.Body[0].ID) + assert.Len(t, jobs, 1) + assert.EqualValues(t, job.ID, jobs[0].ID) }