fix: job list response to avoid wrapped body. (#7050)
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7050
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Jaime merino <cobak78@gmail.com>
Co-committed-by: Jaime merino <cobak78@gmail.com>
This commit is contained in:
Jaime merino 2025-02-24 18:14:12 +00:00 committed by Gusted
parent 768f5a9255
commit a4778fc970
6 changed files with 24 additions and 25 deletions

View file

@ -34,13 +34,6 @@ func GetRegistrationToken(ctx *context.APIContext, ownerID, repoID int64) {
ctx.JSON(http.StatusOK, RegistrationToken{Token: token.Token}) 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) { func GetActionRunJobs(ctx *context.APIContext, ownerID, repoID int64) {
labels := strings.Split(ctx.FormTrim("labels"), ",") labels := strings.Split(ctx.FormTrim("labels"), ",")
@ -54,8 +47,7 @@ func GetActionRunJobs(ctx *context.APIContext, ownerID, repoID int64) {
return return
} }
res := new(RunJobList) res := fromRunJobModelToResponse(total, labels)
res.Body = fromRunJobModelToResponse(total, labels)
ctx.JSON(http.StatusOK, res) ctx.JSON(http.StatusOK, res)
} }

View file

@ -32,3 +32,10 @@ type swaggerResponseVariableList struct {
// in:body // in:body
Body []api.ActionVariable `json:"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"`
}

View file

@ -11,7 +11,7 @@ import (
actions_model "code.gitea.io/gitea/models/actions" actions_model "code.gitea.io/gitea/models/actions"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/unittest" "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" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -31,9 +31,9 @@ func TestAPISearchActionJobs_GlobalRunner(t *testing.T) {
).AddTokenAuth(token) ).AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusOK) res := MakeRequest(t, req, http.StatusOK)
var jobs shared.RunJobList var jobs []*api.ActionRunJob
DecodeJSON(t, res, &jobs) DecodeJSON(t, res, &jobs)
assert.Len(t, jobs.Body, 1) assert.Len(t, jobs, 1)
assert.EqualValues(t, job.ID, jobs.Body[0].ID) assert.EqualValues(t, job.ID, jobs[0].ID)
} }

View file

@ -11,7 +11,7 @@ import (
actions_model "code.gitea.io/gitea/models/actions" actions_model "code.gitea.io/gitea/models/actions"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/unittest" "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" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -30,9 +30,9 @@ func TestAPISearchActionJobs_OrgRunner(t *testing.T) {
AddTokenAuth(token) AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusOK) res := MakeRequest(t, req, http.StatusOK)
var jobs shared.RunJobList var jobs []*api.ActionRunJob
DecodeJSON(t, res, &jobs) DecodeJSON(t, res, &jobs)
assert.Len(t, jobs.Body, 1) assert.Len(t, jobs, 1)
assert.EqualValues(t, job.ID, jobs.Body[0].ID) assert.EqualValues(t, job.ID, jobs[0].ID)
} }

View file

@ -12,7 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" 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" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -35,9 +35,9 @@ func TestAPISearchActionJobs_RepoRunner(t *testing.T) {
).AddTokenAuth(token) ).AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusOK) res := MakeRequest(t, req, http.StatusOK)
var jobs shared.RunJobList var jobs []*api.ActionRunJob
DecodeJSON(t, res, &jobs) DecodeJSON(t, res, &jobs)
assert.Len(t, jobs.Body, 1) assert.Len(t, jobs, 1)
assert.EqualValues(t, job.ID, jobs.Body[0].ID) assert.EqualValues(t, job.ID, jobs[0].ID)
} }

View file

@ -11,7 +11,7 @@ import (
actions_model "code.gitea.io/gitea/models/actions" actions_model "code.gitea.io/gitea/models/actions"
auth_model "code.gitea.io/gitea/models/auth" auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/unittest" "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" "code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -30,9 +30,9 @@ func TestAPISearchActionJobs_UserRunner(t *testing.T) {
AddTokenAuth(token) AddTokenAuth(token)
res := MakeRequest(t, req, http.StatusOK) res := MakeRequest(t, req, http.StatusOK)
var jobs shared.RunJobList var jobs []*api.ActionRunJob
DecodeJSON(t, res, &jobs) DecodeJSON(t, res, &jobs)
assert.Len(t, jobs.Body, 1) assert.Len(t, jobs, 1)
assert.EqualValues(t, job.ID, jobs.Body[0].ID) assert.EqualValues(t, job.ID, jobs[0].ID)
} }