1
1
mirror of https://github.com/go-gitea/gitea synced 2025-12-07 13:28:25 +00:00

Add API endpoints for getting action jobs status

This commit is contained in:
chesterip
2023-08-22 19:58:55 -04:00
parent 8f2e2878e5
commit b8a61a6ba4
5 changed files with 213 additions and 0 deletions
+3
View File
@@ -994,6 +994,9 @@ func Routes() *web.Route {
m.Post("", reqToken(), reqRepoWriter(unit.TypeCode), bind(api.CreateTagOption{}), repo.CreateTag)
m.Delete("/*", reqToken(), repo.DeleteTag)
}, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true))
m.Group("/actions", func() {
m.Get("/tasks", repo.ListActionTasks)
}, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
+69
View File
@@ -0,0 +1,69 @@
// 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"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"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"
page := ctx.FormInt("page")
limit := convert.ToCorrectPageSize(ctx.FormInt("limit"))
opts := actions_model.FindTaskOptions{
RepoID: ctx.Repo.Repository.ID,
ListOptions: db.ListOptions{
Page: page,
PageSize: limit,
},
Status: actions_model.StatusUnknown, // Unknown means all
IDOrderDesc: true,
}
tasks, err := actions_model.FindTasks(ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetTags", err)
return
}
apiActionTasks := make([]*api.ActionTask, len(tasks))
for i := range tasks {
apiActionTasks[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i])
}
ctx.JSON(http.StatusOK, &apiActionTasks)
}