gitea/routers/api/v1/repo/actions.go

81 lines
2.1 KiB
Go
Raw Normal View History

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package repo
import (
"net/http"
actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
2024-04-19 04:19:35 +02:00
"code.gitea.io/gitea/routers/api/v1/utils"
2024-04-03 17:26:01 +02:00
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
)
// ListActionTasks list all the actions of a repository
func ListActionTasks(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/actions/tasks repository ListActionTasks
// ---
// summary: List a repository's action tasks
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: page
// in: query
// description: page number of results to return (1-based)
// type: integer
// - name: limit
// in: query
// description: page size of results, default maximum page size is 50
// type: integer
// responses:
// "200":
// "$ref": "#/responses/TasksList"
2024-04-04 03:34:15 +02:00
// "400":
// "$ref": "#/responses/error"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
// "409":
2024-04-26 15:40:38 +02:00
// "$ref": "#/responses/conflict"
2024-04-04 03:34:15 +02:00
// "422":
// "$ref": "#/responses/validationError"
2024-04-03 17:50:24 +02:00
2024-04-24 01:08:09 +02:00
tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, &actions_model.FindTaskOptions{
ListOptions: utils.GetListOptions(ctx),
RepoID: ctx.Repo.Repository.ID,
})
if err != nil {
2023-08-23 16:13:39 +02:00
ctx.Error(http.StatusInternalServerError, "ListActionTasks", err)
return
}
2023-08-23 16:13:39 +02:00
res := new(api.ActionTaskResponse)
2024-04-03 17:50:24 +02:00
res.TotalCount = total
2023-08-23 16:13:39 +02:00
res.Entries = make([]*api.ActionTask, len(tasks))
for i := range tasks {
2024-04-26 15:40:38 +02:00
convertedTask, err := convert.ToActionTask(ctx, tasks[i])
2024-04-24 04:19:19 +02:00
if err != nil {
ctx.Error(http.StatusInternalServerError, "ToActionTask", err)
return
}
res.Entries[i] = convertedTask
2023-08-23 16:13:39 +02:00
}
ctx.JSON(http.StatusOK, &res)
}