From b8a61a6ba45413dfce0425af37b96487e036daeb Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 22 Aug 2023 19:58:55 -0400 Subject: [PATCH 01/28] Add API endpoints for getting action jobs status --- modules/structs/repo_actions.go | 23 ++++++++ routers/api/v1/api.go | 3 + routers/api/v1/repo/actions.go | 69 +++++++++++++++++++++++ services/convert/convert.go | 19 +++++++ templates/swagger/v1_json.tmpl | 99 +++++++++++++++++++++++++++++++++ 5 files changed, 213 insertions(+) create mode 100644 modules/structs/repo_actions.go create mode 100644 routers/api/v1/repo/actions.go diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go new file mode 100644 index 0000000000000..ca894c14f9aff --- /dev/null +++ b/modules/structs/repo_actions.go @@ -0,0 +1,23 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package structs + +import ( + "time" +) + +// Tag represents a repository tag +type ActionTask struct { + ID int64 `json:"id"` + JobName string `json:"job_name"` + WorkflowID string `json:"workflow_id"` + Title string `json:"title"` + Status string `json:"status"` + Commit string `json:"commit"` + Duration string `json:"duration"` + // swagger:strfmt date-time + Started time.Time `json:"started,omitempty"` + // swagger:strfmt date-time + Stopped time.Time `json:"stopped,omitempty"` +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 9613bd610dc58..f441db5ffd31c 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -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) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go new file mode 100644 index 0000000000000..fbf863ac5edb9 --- /dev/null +++ b/routers/api/v1/repo/actions.go @@ -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) +} diff --git a/services/convert/convert.go b/services/convert/convert.go index a7a777e8bd6ba..8ca215938d793 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -11,6 +11,7 @@ import ( "strings" "time" + actions_model "code.gitea.io/gitea/models/actions" asymkey_model "code.gitea.io/gitea/models/asymkey" "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" @@ -179,6 +180,24 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { } } +// ToActionTask convert a actions_model.ActionTask to an api.ActionTask +func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_model.ActionTask) *api.ActionTask { + if err := t.LoadAttributes(ctx); err != nil { + log.Warn("LoadAttributes of ActionTask: %v", err) + } + return &api.ActionTask{ + ID: t.ID, + JobName: t.Job.Name, + WorkflowID: t.Job.Run.WorkflowID, + Title: t.Job.Run.Title, + Status: t.Status.String(), + Commit: t.CommitSHA, + Duration: t.Duration().String(), + Started: t.Started.AsLocalTime(), + Stopped: t.Stopped.AsLocalTime(), + } +} + // ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification func ToVerification(ctx context.Context, c *git.Commit) *api.PayloadCommitVerification { verif := asymkey_model.ParseCommitWithSignature(ctx, c) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 5e75f6f8b460b..1765879c9255a 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -12313,6 +12313,51 @@ } } }, + "/repos/{owner}/{repo}/actions/tasks": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repository's actions tasks", + "operationId": "ListActionTasks", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, default maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/TasksList" + } + } + } + }, "/repos/{owner}/{repo}/teams": { "get": { "produces": [ @@ -21414,6 +21459,51 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "Task": { + "description": "Task represents a task", + "type": "object", + "properties": { + "id": { + "type": "string", + "x-go-name": "ID" + }, + "job_name": { + "type": "string", + "x-go-name": "JobName" + }, + "workflow_id": { + "type": "string", + "x-go-name": "WorkflowID" + }, + "title": { + "type": "string", + "x-go-name": "Title" + }, + "status": { + "type": "string", + "x-go-name": "Status" + }, + "commit": { + "type": "string", + "x-go-name": "Commit" + }, + "duration": { + "type": "string", + "x-go-name": "Duration" + }, + "started": { + "type": "string", + "format": "date-time", + "x-go-name": "Started" + }, + "stopped": { + "type": "string", + "format": "date-time", + "x-go-name": "Stopped" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "ServerVersion": { "description": "ServerVersion wraps the version of the server", "type": "object", @@ -23000,6 +23090,15 @@ } } }, + "TasksList": { + "description": "TasksList", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Task" + } + } + }, "ServerVersion": { "description": "ServerVersion", "schema": { From 8b5443acdb0aac7bb4c56faf6aad7487b82d0aa0 Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 22 Aug 2023 20:00:59 -0400 Subject: [PATCH 02/28] Fix template --- services/convert/convert.go | 2 +- templates/swagger/v1_json.tmpl | 144 +++++++++++---------------------- 2 files changed, 46 insertions(+), 100 deletions(-) diff --git a/services/convert/convert.go b/services/convert/convert.go index 8ca215938d793..e83a0067e75d5 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -186,7 +186,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m log.Warn("LoadAttributes of ActionTask: %v", err) } return &api.ActionTask{ - ID: t.ID, + ID: t.Job.RunID, JobName: t.Job.Name, WorkflowID: t.Job.Run.WorkflowID, Title: t.Job.Run.Title, diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 1765879c9255a..35e095fd68b89 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3184,6 +3184,51 @@ } } }, + "/repos/{owner}/{repo}/actions/tasks": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repository's action tasks", + "operationId": "ListActionTasks", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, default maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/TasksList" + } + } + } + }, "/repos/{owner}/{repo}/activities/feeds": { "get": { "produces": [ @@ -12313,51 +12358,6 @@ } } }, - "/repos/{owner}/{repo}/actions/tasks": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "repository" - ], - "summary": "List a repository's actions tasks", - "operationId": "ListActionTasks", - "parameters": [ - { - "type": "string", - "description": "owner of the repo", - "name": "owner", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repo", - "name": "repo", - "in": "path", - "required": true - }, - { - "type": "integer", - "description": "page number of results to return (1-based)", - "name": "page", - "in": "query" - }, - { - "type": "integer", - "description": "page size of results, default maximum page size is 50", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "$ref": "#/responses/TasksList" - } - } - } - }, "/repos/{owner}/{repo}/teams": { "get": { "produces": [ @@ -21459,51 +21459,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "Task": { - "description": "Task represents a task", - "type": "object", - "properties": { - "id": { - "type": "string", - "x-go-name": "ID" - }, - "job_name": { - "type": "string", - "x-go-name": "JobName" - }, - "workflow_id": { - "type": "string", - "x-go-name": "WorkflowID" - }, - "title": { - "type": "string", - "x-go-name": "Title" - }, - "status": { - "type": "string", - "x-go-name": "Status" - }, - "commit": { - "type": "string", - "x-go-name": "Commit" - }, - "duration": { - "type": "string", - "x-go-name": "Duration" - }, - "started": { - "type": "string", - "format": "date-time", - "x-go-name": "Started" - }, - "stopped": { - "type": "string", - "format": "date-time", - "x-go-name": "Stopped" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "ServerVersion": { "description": "ServerVersion wraps the version of the server", "type": "object", @@ -23090,15 +23045,6 @@ } } }, - "TasksList": { - "description": "TasksList", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Task" - } - } - }, "ServerVersion": { "description": "ServerVersion", "schema": { From 6870e1a60cf0da621609ce1bd442c1e17f5243b2 Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 22 Aug 2023 20:07:37 -0400 Subject: [PATCH 03/28] Use the run index instead, since it's the number used in FE --- services/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/convert/convert.go b/services/convert/convert.go index e83a0067e75d5..85b017aa29f0b 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -186,7 +186,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m log.Warn("LoadAttributes of ActionTask: %v", err) } return &api.ActionTask{ - ID: t.Job.RunID, + ID: t.Job.Run.Index, JobName: t.Job.Name, WorkflowID: t.Job.Run.WorkflowID, Title: t.Job.Run.Title, From 8f787dfe66d7da3389f186dcd865e19fc9fe8fab Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 22 Aug 2023 20:11:40 -0400 Subject: [PATCH 04/28] Update copyright message --- modules/structs/repo_actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index ca894c14f9aff..a39cb3d19e9bb 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2023 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package structs From 246873acc08d2daa3f8aaf50a84523a61ba8213e Mon Sep 17 00:00:00 2001 From: Chester Date: Wed, 23 Aug 2023 09:42:07 -0400 Subject: [PATCH 05/28] Update routers/api/v1/api.go Co-authored-by: yp05327 <576951401@qq.com> --- routers/api/v1/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index f441db5ffd31c..3ec1b8a1faa53 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -996,7 +996,7 @@ func Routes() *web.Route { }, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true)) m.Group("/actions", func() { m.Get("/tasks", repo.ListActionTasks) - }, reqRepoReader(unit.TypeCode), context.ReferencesGitRepo(true)) + }, reqRepoReader(unit.TypeActions), context.ReferencesGitRepo(true)) m.Group("/keys", func() { m.Combo("").Get(repo.ListDeployKeys). Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey) From 5ebefc85ca6a6892abe446d5deb400a99afb3d33 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 23 Aug 2023 10:13:39 -0400 Subject: [PATCH 06/28] align with GitHub Actions --- modules/structs/repo_actions.go | 31 +++++++++++++++++++++---------- routers/api/v1/repo/actions.go | 21 +++++++++++++++++---- services/convert/convert.go | 23 ++++++++++++++--------- 3 files changed, 52 insertions(+), 23 deletions(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index a39cb3d19e9bb..b60ec8ad17b8b 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -7,17 +7,28 @@ import ( "time" ) -// Tag represents a repository tag +// ActionTask represents a ActionTask type ActionTask struct { - ID int64 `json:"id"` - JobName string `json:"job_name"` - WorkflowID string `json:"workflow_id"` - Title string `json:"title"` - Status string `json:"status"` - Commit string `json:"commit"` - Duration string `json:"duration"` + Id int64 `json:"id"` + Name string `json:"name"` + HeadBranch string `json:"head_branch"` + HeadSha string `json:"head_sha"` + RunNumber int64 `json:"run_number"` + Event string `json:"event"` + DisplayTitle string `json:"display_title"` + Status string `json:"status"` + WorkflowID string `json:"workflow_id"` + Url string `json:"url"` // swagger:strfmt date-time - Started time.Time `json:"started,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` // swagger:strfmt date-time - Stopped time.Time `json:"stopped,omitempty"` + UpdatedAt time.Time `json:"updated_at,omitempty"` + // swagger:strfmt date-time + RunStartedAt time.Time `json:"run_started_at,omitempty"` +} + +// ActionTaskResponse returns a ActionTask +type ActionTaskResponse struct { + Entries []*ActionTask `json:"workflow_runs"` + TotalCount int64 `json:"total_count"` } diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index fbf863ac5edb9..878a62af31642 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -56,14 +56,27 @@ func ListActionTasks(ctx *context.APIContext) { } tasks, err := actions_model.FindTasks(ctx, opts) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetTags", err) + ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return } - apiActionTasks := make([]*api.ActionTask, len(tasks)) + res := new(api.ActionTaskResponse) + + res.Entries = make([]*api.ActionTask, len(tasks)) for i := range tasks { - apiActionTasks[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) + res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) + } + + opts = actions_model.FindTaskOptions{ + RepoID: ctx.Repo.Repository.ID, + Status: actions_model.StatusUnknown, // Unknown means all + IDOrderDesc: true, + } + res.TotalCount, err = actions_model.CountTasks(ctx, opts) + if err != nil { + ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) + return } - ctx.JSON(http.StatusOK, &apiActionTasks) + ctx.JSON(http.StatusOK, &res) } diff --git a/services/convert/convert.go b/services/convert/convert.go index 85b017aa29f0b..13a6041e07299 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -185,16 +185,21 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m if err := t.LoadAttributes(ctx); err != nil { log.Warn("LoadAttributes of ActionTask: %v", err) } + return &api.ActionTask{ - ID: t.Job.Run.Index, - JobName: t.Job.Name, - WorkflowID: t.Job.Run.WorkflowID, - Title: t.Job.Run.Title, - Status: t.Status.String(), - Commit: t.CommitSHA, - Duration: t.Duration().String(), - Started: t.Started.AsLocalTime(), - Stopped: t.Stopped.AsLocalTime(), + Id: t.ID, + Name: t.Job.Name, + HeadBranch: t.Job.Run.PrettyRef(), + HeadSha: t.Job.CommitSHA, + RunNumber: t.Job.Run.Index, + Event: t.Job.Run.TriggerEvent, + DisplayTitle: t.Job.Run.Title, + Status: t.Status.String(), + WorkflowID: t.Job.Run.WorkflowID, + Url: t.GetRunLink(), + CreatedAt: t.Created.AsLocalTime(), + UpdatedAt: t.Updated.AsLocalTime(), + RunStartedAt: t.Started.AsLocalTime(), } } From 5625bc505bd3d7c8ad0e2d2fefac391d37214259 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 23 Aug 2023 10:22:33 -0400 Subject: [PATCH 07/28] Update Swagger template --- templates/swagger/v1_json.tmpl | 71 ++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 35e095fd68b89..6fd133e2ade37 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21527,6 +21527,68 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "Task": { + "description": "Task represents a task", + "type": "object", + "properties": { + "id": { + "type": "integer", + "x-go-name": "Id" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "head_branch": { + "type": "string", + "x-go-name": "HeadBranch" + }, + "head_sha": { + "type": "string", + "x-go-name": "HeadSha" + }, + "run_number": { + "type": "integer", + "x-go-name": "RunNumber" + }, + "event": { + "type": "string", + "x-go-name": "Event" + }, + "display_title": { + "type": "string", + "x-go-name": "DisplayTitle" + }, + "status": { + "type": "string", + "x-go-name": "Status" + }, + "workflow_id": { + "type": "string", + "x-go-name": "WorkflowID" + }, + "url": { + "type": "string", + "x-go-name": "Url" + }, + "created_at":{ + "type": "string", + "format": "date-time", + "x-go-name":"CreatedAt" + }, + "updated_at":{ + "type": "string", + "format": "date-time", + "x-go-name":"UpdatedAt" + }, + "run_started_at":{ + "type": "string", + "format": "date-time", + "x-go-name":"RunStartedAt" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "Tag": { "description": "Tag represents a repository tag", "type": "object", @@ -23075,6 +23137,15 @@ } } }, + "TasksList": { + "description": "TasksList", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Task" + } + } + }, "Tag": { "description": "Tag", "schema": { From 1ba57015364ed035f5851be3635353c37590c097 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 30 Aug 2023 11:34:01 -0400 Subject: [PATCH 08/28] Fix var-naming --- modules/structs/repo_actions.go | 4 ++-- services/convert/convert.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index b60ec8ad17b8b..ca51ca4ea5bc7 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -9,7 +9,7 @@ import ( // ActionTask represents a ActionTask type ActionTask struct { - Id int64 `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` HeadBranch string `json:"head_branch"` HeadSha string `json:"head_sha"` @@ -18,7 +18,7 @@ type ActionTask struct { DisplayTitle string `json:"display_title"` Status string `json:"status"` WorkflowID string `json:"workflow_id"` - Url string `json:"url"` + URL string `json:"url"` // swagger:strfmt date-time CreatedAt time.Time `json:"created_at,omitempty"` // swagger:strfmt date-time diff --git a/services/convert/convert.go b/services/convert/convert.go index 13a6041e07299..f308cca2b744c 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -187,7 +187,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m } return &api.ActionTask{ - Id: t.ID, + ID: t.ID, Name: t.Job.Name, HeadBranch: t.Job.Run.PrettyRef(), HeadSha: t.Job.CommitSHA, @@ -196,7 +196,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m DisplayTitle: t.Job.Run.Title, Status: t.Status.String(), WorkflowID: t.Job.Run.WorkflowID, - Url: t.GetRunLink(), + URL: t.GetRunLink(), CreatedAt: t.Created.AsLocalTime(), UpdatedAt: t.Updated.AsLocalTime(), RunStartedAt: t.Started.AsLocalTime(), From 4d9a23191249486c1f0e4666622139f2db8e9bf4 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 30 Aug 2023 11:38:46 -0400 Subject: [PATCH 09/28] Fix template --- templates/swagger/v1_json.tmpl | 75 +--------------------------------- 1 file changed, 2 insertions(+), 73 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index eb2298c7794f2..b600a96f22d57 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21,7 +21,7 @@ }, "version": "{{AppVer | JSEscape | Safe}}" }, - "basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1", + "basePath": "/api/v1", "paths": { "/activitypub/user-id/{user-id}": { "get": { @@ -21630,68 +21630,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "Task": { - "description": "Task represents a task", - "type": "object", - "properties": { - "id": { - "type": "integer", - "x-go-name": "Id" - }, - "name": { - "type": "string", - "x-go-name": "Name" - }, - "head_branch": { - "type": "string", - "x-go-name": "HeadBranch" - }, - "head_sha": { - "type": "string", - "x-go-name": "HeadSha" - }, - "run_number": { - "type": "integer", - "x-go-name": "RunNumber" - }, - "event": { - "type": "string", - "x-go-name": "Event" - }, - "display_title": { - "type": "string", - "x-go-name": "DisplayTitle" - }, - "status": { - "type": "string", - "x-go-name": "Status" - }, - "workflow_id": { - "type": "string", - "x-go-name": "WorkflowID" - }, - "url": { - "type": "string", - "x-go-name": "Url" - }, - "created_at":{ - "type": "string", - "format": "date-time", - "x-go-name":"CreatedAt" - }, - "updated_at":{ - "type": "string", - "format": "date-time", - "x-go-name":"UpdatedAt" - }, - "run_started_at":{ - "type": "string", - "format": "date-time", - "x-go-name":"RunStartedAt" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "Tag": { "description": "Tag represents a repository tag", "type": "object", @@ -23240,15 +23178,6 @@ } } }, - "TasksList": { - "description": "TasksList", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/Task" - } - } - }, "Tag": { "description": "Tag", "schema": { @@ -23512,4 +23441,4 @@ "TOTPHeader": [] } ] -} +} \ No newline at end of file From a9cdb7ea9bfd8c81468b436d3232f9b9c08cbd02 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 30 Aug 2023 11:40:03 -0400 Subject: [PATCH 10/28] Fix template --- templates/swagger/v1_json.tmpl | 49 ++-------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index b600a96f22d57..78491de2e1028 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21,7 +21,7 @@ }, "version": "{{AppVer | JSEscape | Safe}}" }, - "basePath": "/api/v1", + "basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1", "paths": { "/activitypub/user-id/{user-id}": { "get": { @@ -3289,51 +3289,6 @@ } } }, - "/repos/{owner}/{repo}/actions/tasks": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "repository" - ], - "summary": "List a repository's action tasks", - "operationId": "ListActionTasks", - "parameters": [ - { - "type": "string", - "description": "owner of the repo", - "name": "owner", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repo", - "name": "repo", - "in": "path", - "required": true - }, - { - "type": "integer", - "description": "page number of results to return (1-based)", - "name": "page", - "in": "query" - }, - { - "type": "integer", - "description": "page size of results, default maximum page size is 50", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "$ref": "#/responses/TasksList" - } - } - } - }, "/repos/{owner}/{repo}/activities/feeds": { "get": { "produces": [ @@ -23441,4 +23396,4 @@ "TOTPHeader": [] } ] -} \ No newline at end of file +} From 6928b37ab3947a6f7554814a9b564bebc0d813c5 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 30 Aug 2023 11:50:25 -0400 Subject: [PATCH 11/28] Update template using generate swagger --- routers/api/v1/swagger/repo.go | 7 ++ templates/swagger/v1_json.tmpl | 134 +++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index 3e23aa4d5a5ac..3784826c20a07 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -414,3 +414,10 @@ type swaggerRepoNewIssuePinsAllowed struct { // in:body Body api.NewIssuePinsAllowed `json:"body"` } + +// TasksList +// swagger:response TasksList +type swaggerRepoTasksList struct { + // in:body + Body api.ActionTaskResponse `json:"body"` +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 78491de2e1028..d70fca1fca85b 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3289,6 +3289,51 @@ } } }, + "/repos/{owner}/{repo}/actions/tasks": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repository's action tasks", + "operationId": "ListActionTasks", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, default maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/TasksList" + } + } + } + }, "/repos/{owner}/{repo}/activities/feeds": { "get": { "produces": [ @@ -15926,6 +15971,89 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "ActionTask": { + "description": "ActionTask represents a ActionTask", + "type": "object", + "properties": { + "created_at": { + "type": "string", + "format": "date-time", + "x-go-name": "CreatedAt" + }, + "display_title": { + "type": "string", + "x-go-name": "DisplayTitle" + }, + "event": { + "type": "string", + "x-go-name": "Event" + }, + "head_branch": { + "type": "string", + "x-go-name": "HeadBranch" + }, + "head_sha": { + "type": "string", + "x-go-name": "HeadSha" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "name": { + "type": "string", + "x-go-name": "Name" + }, + "run_number": { + "type": "integer", + "format": "int64", + "x-go-name": "RunNumber" + }, + "run_started_at": { + "type": "string", + "format": "date-time", + "x-go-name": "RunStartedAt" + }, + "status": { + "type": "string", + "x-go-name": "Status" + }, + "updated_at": { + "type": "string", + "format": "date-time", + "x-go-name": "UpdatedAt" + }, + "url": { + "type": "string", + "x-go-name": "URL" + }, + "workflow_id": { + "type": "string", + "x-go-name": "WorkflowID" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, + "ActionTaskResponse": { + "description": "ActionTaskResponse returns a ActionTask", + "type": "object", + "properties": { + "total_count": { + "type": "integer", + "format": "int64", + "x-go-name": "TotalCount" + }, + "workflow_runs": { + "type": "array", + "items": { + "$ref": "#/definitions/ActionTask" + }, + "x-go-name": "Entries" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "Activity": { "type": "object", "properties": { @@ -23148,6 +23276,12 @@ } } }, + "TasksList": { + "description": "TasksList", + "schema": { + "$ref": "#/definitions/ActionTaskResponse" + } + }, "Team": { "description": "Team", "schema": { From a348da4cfd0914acdfe1881e5b559292d7ad43c3 Mon Sep 17 00:00:00 2001 From: Chester Date: Mon, 11 Sep 2023 14:24:18 -0400 Subject: [PATCH 12/28] Update modules/structs/repo_actions.go Co-authored-by: puni9869 <80308335+puni9869@users.noreply.github.com> --- modules/structs/repo_actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index ca51ca4ea5bc7..e3829f5cfb823 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -22,7 +22,7 @@ type ActionTask struct { // swagger:strfmt date-time CreatedAt time.Time `json:"created_at,omitempty"` // swagger:strfmt date-time - UpdatedAt time.Time `json:"updated_at,omitempty"` + UpdatedAt time.Time `json:"updated_at"` // swagger:strfmt date-time RunStartedAt time.Time `json:"run_started_at,omitempty"` } From b94cbda0bc269e2c34b044a3c43c354608f0778f Mon Sep 17 00:00:00 2001 From: Chester Date: Mon, 11 Sep 2023 14:24:25 -0400 Subject: [PATCH 13/28] Update modules/structs/repo_actions.go Co-authored-by: puni9869 <80308335+puni9869@users.noreply.github.com> --- modules/structs/repo_actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index e3829f5cfb823..60db99298d63c 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -20,7 +20,7 @@ type ActionTask struct { WorkflowID string `json:"workflow_id"` URL string `json:"url"` // swagger:strfmt date-time - CreatedAt time.Time `json:"created_at,omitempty"` + CreatedAt time.Time `json:"created_at"` // swagger:strfmt date-time UpdatedAt time.Time `json:"updated_at"` // swagger:strfmt date-time From 878eeedde8e31156bf19dce5fdc31bde96faf144 Mon Sep 17 00:00:00 2001 From: Chester Date: Mon, 11 Sep 2023 14:24:32 -0400 Subject: [PATCH 14/28] Update modules/structs/repo_actions.go Co-authored-by: puni9869 <80308335+puni9869@users.noreply.github.com> --- modules/structs/repo_actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index 60db99298d63c..7efb692c2dac4 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -24,7 +24,7 @@ type ActionTask struct { // swagger:strfmt date-time UpdatedAt time.Time `json:"updated_at"` // swagger:strfmt date-time - RunStartedAt time.Time `json:"run_started_at,omitempty"` + RunStartedAt time.Time `json:"run_started_at"` } // ActionTaskResponse returns a ActionTask From e05fc9ab458ccc8ae27cfd52be7a297fb5c72518 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 3 Apr 2024 11:15:04 -0400 Subject: [PATCH 15/28] Fix broken json after resolving merge conflict --- templates/swagger/v1_json.tmpl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 151503075a0ef..8f26ea1307c60 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17986,6 +17986,9 @@ "$ref": "#/definitions/ActionTask" }, "x-go-name": "Entries" + } + } + } "ActionVariable": { "description": "ActionVariable return value of the query API", "type": "object", From 2c8249ba1e1a749fd8706380bb86d4141de37199 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 3 Apr 2024 11:26:01 -0400 Subject: [PATCH 16/28] More fixes after mreging from main --- routers/api/v1/repo/actions.go | 2 +- templates/swagger/v1_json.tmpl | 95 +++++++++++++++++----------------- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 878a62af31642..15d88f1c8727c 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -8,8 +8,8 @@ import ( 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/context" "code.gitea.io/gitea/services/convert" ) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 8f26ea1307c60..1b674f0e5e1fe 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3949,6 +3949,51 @@ } } }, + "/repos/{owner}/{repo}/actions/tasks": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List a repository's action tasks", + "operationId": "ListActionTasks", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, default maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/TasksList" + } + } + } + }, "/repos/{owner}/{repo}/actions/variables": { "get": { "produces": [ @@ -4204,51 +4249,6 @@ } } }, - "/repos/{owner}/{repo}/actions/tasks": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "repository" - ], - "summary": "List a repository's action tasks", - "operationId": "ListActionTasks", - "parameters": [ - { - "type": "string", - "description": "owner of the repo", - "name": "owner", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "name of the repo", - "name": "repo", - "in": "path", - "required": true - }, - { - "type": "integer", - "description": "page number of results to return (1-based)", - "name": "page", - "in": "query" - }, - { - "type": "integer", - "description": "page size of results, default maximum page size is 50", - "name": "limit", - "in": "query" - } - ], - "responses": { - "200": { - "$ref": "#/responses/TasksList" - } - } - } - }, "/repos/{owner}/{repo}/activities/feeds": { "get": { "produces": [ @@ -17987,8 +17987,9 @@ }, "x-go-name": "Entries" } - } - } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "ActionVariable": { "description": "ActionVariable return value of the query API", "type": "object", From 1028eefe4839d914e8a17705dc1067e092f26fb4 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 3 Apr 2024 11:37:06 -0400 Subject: [PATCH 17/28] move to db.find --- routers/api/v1/repo/actions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 15d88f1c8727c..f3c7bb0154f46 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -54,7 +54,7 @@ func ListActionTasks(ctx *context.APIContext) { Status: actions_model.StatusUnknown, // Unknown means all IDOrderDesc: true, } - tasks, err := actions_model.FindTasks(ctx, opts) + tasks, err := db.Find[actions_model.ActionTask](ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return @@ -72,7 +72,7 @@ func ListActionTasks(ctx *context.APIContext) { Status: actions_model.StatusUnknown, // Unknown means all IDOrderDesc: true, } - res.TotalCount, err = actions_model.CountTasks(ctx, opts) + tasks, res.TotalCount, err = db.FindAndCount[actions_model.ActionTask](ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return From 4310284a80e744e37a5a97d6984d3e4b59b12085 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 3 Apr 2024 11:50:24 -0400 Subject: [PATCH 18/28] Reducing queries --- routers/api/v1/repo/actions.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index f3c7bb0154f46..3326f4e5c077a 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -54,29 +54,20 @@ func ListActionTasks(ctx *context.APIContext) { Status: actions_model.StatusUnknown, // Unknown means all IDOrderDesc: true, } - tasks, err := db.Find[actions_model.ActionTask](ctx, opts) + + tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, opts) if err != nil { ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return } res := new(api.ActionTaskResponse) + res.TotalCount = total res.Entries = make([]*api.ActionTask, len(tasks)) for i := range tasks { res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) } - opts = actions_model.FindTaskOptions{ - RepoID: ctx.Repo.Repository.ID, - Status: actions_model.StatusUnknown, // Unknown means all - IDOrderDesc: true, - } - tasks, res.TotalCount, err = db.FindAndCount[actions_model.ActionTask](ctx, opts) - if err != nil { - ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) - return - } - ctx.JSON(http.StatusOK, &res) } From ad16583181f483c5819c7ce3305b1e4737f423e5 Mon Sep 17 00:00:00 2001 From: chesterip Date: Wed, 3 Apr 2024 21:34:15 -0400 Subject: [PATCH 19/28] Add error res to swagger --- routers/api/v1/repo/actions.go | 10 ++++++++++ templates/swagger/v1_json.tmpl | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 3326f4e5c077a..67d858f02c89d 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -42,6 +42,16 @@ func ListActionTasks(ctx *context.APIContext) { // responses: // "200": // "$ref": "#/responses/TasksList" + // "400": + // "$ref": "#/responses/error" + // "403": + // "$ref": "#/responses/forbidden" + // "404": + // "$ref": "#/responses/notFound" + // "409": + // "$ref": "#/responses/error" + // "422": + // "$ref": "#/responses/validationError" page := ctx.FormInt("page") limit := convert.ToCorrectPageSize(ctx.FormInt("limit")) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 1b674f0e5e1fe..fb8eef5bde9fb 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3990,6 +3990,21 @@ "responses": { "200": { "$ref": "#/responses/TasksList" + }, + "400": { + "$ref": "#/responses/error" + }, + "403": { + "$ref": "#/responses/forbidden" + }, + "404": { + "$ref": "#/responses/notFound" + }, + "409": { + "$ref": "#/responses/error" + }, + "422": { + "$ref": "#/responses/validationError" } } } From 34777376d68bcc15debc8ebb4e4dbf0912e809c1 Mon Sep 17 00:00:00 2001 From: chesterip Date: Thu, 18 Apr 2024 22:19:35 -0400 Subject: [PATCH 20/28] Use GetListOptions() and panic() --- routers/api/v1/repo/actions.go | 14 ++------------ services/convert/convert.go | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 67d858f02c89d..2930091ffc1b3 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -9,6 +9,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/convert" ) @@ -52,18 +53,7 @@ func ListActionTasks(ctx *context.APIContext) { // "$ref": "#/responses/error" // "422": // "$ref": "#/responses/validationError" - 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, - } + opts := utils.GetListOptions(ctx) tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, opts) if err != nil { diff --git a/services/convert/convert.go b/services/convert/convert.go index f23c0b853a215..b51db0ea345bf 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -183,7 +183,7 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { // ToActionTask convert a actions_model.ActionTask to an api.ActionTask func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_model.ActionTask) *api.ActionTask { if err := t.LoadAttributes(ctx); err != nil { - log.Warn("LoadAttributes of ActionTask: %v", err) + panic(fmt.Sprintf("failed to execute ActionTask.LoadAttributes(): %v", err)) } return &api.ActionTask{ From 87ef8b75b175b1c941bb407f7b2fa3983e81b552 Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 23 Apr 2024 19:08:09 -0400 Subject: [PATCH 21/28] Fix list options --- routers/api/v1/repo/actions.go | 7 +++++-- services/convert/convert.go | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 2930091ffc1b3..39dc9f339dbe4 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -53,9 +53,12 @@ func ListActionTasks(ctx *context.APIContext) { // "$ref": "#/responses/error" // "422": // "$ref": "#/responses/validationError" - opts := utils.GetListOptions(ctx) - tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, opts) + tasks, total, err := db.FindAndCount[actions_model.ActionTask](ctx, &actions_model.FindTaskOptions{ + ListOptions: utils.GetListOptions(ctx), + RepoID: ctx.Repo.Repository.ID, + }) + if err != nil { ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return diff --git a/services/convert/convert.go b/services/convert/convert.go index a0c7259ec0050..e1243692f0b65 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -25,6 +25,7 @@ import ( "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/gitdiff" @@ -200,6 +201,8 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m panic(fmt.Sprintf("failed to execute ActionTask.LoadAttributes(): %v", err)) } + url := fmt.Sprintf("%s%s", setting.AppURL, t.GetRunLink()) + return &api.ActionTask{ ID: t.ID, Name: t.Job.Name, @@ -210,7 +213,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m DisplayTitle: t.Job.Run.Title, Status: t.Status.String(), WorkflowID: t.Job.Run.WorkflowID, - URL: t.GetRunLink(), + URL: url, CreatedAt: t.Created.AsLocalTime(), UpdatedAt: t.Updated.AsLocalTime(), RunStartedAt: t.Started.AsLocalTime(), From e0e094161f4d8c5edad348f4ebf5ba44f9c2b99b Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 23 Apr 2024 19:09:43 -0400 Subject: [PATCH 22/28] Fix URL --- services/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/convert/convert.go b/services/convert/convert.go index e1243692f0b65..1fd46f6bdc899 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -201,7 +201,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m panic(fmt.Sprintf("failed to execute ActionTask.LoadAttributes(): %v", err)) } - url := fmt.Sprintf("%s%s", setting.AppURL, t.GetRunLink()) + url := strings.TrimSuffix(setting.AppURL, "/") + t.GetRunLink() return &api.ActionTask{ ID: t.ID, From 5f26e8a6345d5093bf502238a7904b632ebc239e Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 23 Apr 2024 20:08:07 -0400 Subject: [PATCH 23/28] Fix format --- routers/api/v1/repo/actions.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 39dc9f339dbe4..4034cb19a6d79 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -58,7 +58,6 @@ func ListActionTasks(ctx *context.APIContext) { ListOptions: utils.GetListOptions(ctx), RepoID: ctx.Repo.Repository.ID, }) - if err != nil { ctx.Error(http.StatusInternalServerError, "ListActionTasks", err) return From 2d530411575b5b35cf8113a103aa76a2611cbe2a Mon Sep 17 00:00:00 2001 From: chesterip Date: Tue, 23 Apr 2024 22:19:19 -0400 Subject: [PATCH 24/28] Return err in ToActionTask --- routers/api/v1/repo/actions.go | 7 ++++++- services/convert/convert.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 4034cb19a6d79..6f0568f71260d 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -68,7 +68,12 @@ func ListActionTasks(ctx *context.APIContext) { res.Entries = make([]*api.ActionTask, len(tasks)) for i := range tasks { - res.Entries[i] = convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) + convertedTask, err := convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) + if err != nil { + ctx.Error(http.StatusInternalServerError, "ToActionTask", err) + return + } + res.Entries[i] = convertedTask } ctx.JSON(http.StatusOK, &res) diff --git a/services/convert/convert.go b/services/convert/convert.go index 1fd46f6bdc899..37f203b116877 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -196,9 +196,9 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { } // ToActionTask convert a actions_model.ActionTask to an api.ActionTask -func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_model.ActionTask) *api.ActionTask { +func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_model.ActionTask) (*api.ActionTask, error) { if err := t.LoadAttributes(ctx); err != nil { - panic(fmt.Sprintf("failed to execute ActionTask.LoadAttributes(): %v", err)) + return nil, err } url := strings.TrimSuffix(setting.AppURL, "/") + t.GetRunLink() @@ -217,7 +217,7 @@ func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_m CreatedAt: t.Created.AsLocalTime(), UpdatedAt: t.Updated.AsLocalTime(), RunStartedAt: t.Started.AsLocalTime(), - } + }, nil } // ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification From f954f208ba78c50b54b9b664968bf5c2dbfe634b Mon Sep 17 00:00:00 2001 From: Chester Date: Fri, 26 Apr 2024 09:38:34 -0400 Subject: [PATCH 25/28] Update modules/structs/repo_actions.go Co-authored-by: yp05327 <576951401@qq.com> --- modules/structs/repo_actions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/structs/repo_actions.go b/modules/structs/repo_actions.go index 7efb692c2dac4..b13f34473861f 100644 --- a/modules/structs/repo_actions.go +++ b/modules/structs/repo_actions.go @@ -12,7 +12,7 @@ type ActionTask struct { ID int64 `json:"id"` Name string `json:"name"` HeadBranch string `json:"head_branch"` - HeadSha string `json:"head_sha"` + HeadSHA string `json:"head_sha"` RunNumber int64 `json:"run_number"` Event string `json:"event"` DisplayTitle string `json:"display_title"` From 86493c27cf11e47af78cab4b499ef5b03981ac21 Mon Sep 17 00:00:00 2001 From: chesterip Date: Fri, 26 Apr 2024 09:40:38 -0400 Subject: [PATCH 26/28] Fix as suggested --- routers/api/v1/repo/actions.go | 4 ++-- services/convert/convert.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/actions.go b/routers/api/v1/repo/actions.go index 6f0568f71260d..635cb4e138252 100644 --- a/routers/api/v1/repo/actions.go +++ b/routers/api/v1/repo/actions.go @@ -50,7 +50,7 @@ func ListActionTasks(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" // "409": - // "$ref": "#/responses/error" + // "$ref": "#/responses/conflict" // "422": // "$ref": "#/responses/validationError" @@ -68,7 +68,7 @@ func ListActionTasks(ctx *context.APIContext) { res.Entries = make([]*api.ActionTask, len(tasks)) for i := range tasks { - convertedTask, err := convert.ToActionTask(ctx, ctx.Repo.Repository, tasks[i]) + convertedTask, err := convert.ToActionTask(ctx, tasks[i]) if err != nil { ctx.Error(http.StatusInternalServerError, "ToActionTask", err) return diff --git a/services/convert/convert.go b/services/convert/convert.go index 37f203b116877..67578ad73a9cc 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -196,7 +196,7 @@ func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag { } // ToActionTask convert a actions_model.ActionTask to an api.ActionTask -func ToActionTask(ctx context.Context, repo *repo_model.Repository, t *actions_model.ActionTask) (*api.ActionTask, error) { +func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.ActionTask, error) { if err := t.LoadAttributes(ctx); err != nil { return nil, err } From 04abcc7cbd6df0093c1cdb9f18e306f757ec61a2 Mon Sep 17 00:00:00 2001 From: chesterip Date: Fri, 26 Apr 2024 09:41:41 -0400 Subject: [PATCH 27/28] Fix letter case --- services/convert/convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/convert/convert.go b/services/convert/convert.go index 67578ad73a9cc..c44179632e673 100644 --- a/services/convert/convert.go +++ b/services/convert/convert.go @@ -207,7 +207,7 @@ func ToActionTask(ctx context.Context, t *actions_model.ActionTask) (*api.Action ID: t.ID, Name: t.Job.Name, HeadBranch: t.Job.Run.PrettyRef(), - HeadSha: t.Job.CommitSHA, + HeadSHA: t.Job.CommitSHA, RunNumber: t.Job.Run.Index, Event: t.Job.Run.TriggerEvent, DisplayTitle: t.Job.Run.Title, From fc3dc33906921c2d6cb317530f4c72cc9376ee2e Mon Sep 17 00:00:00 2001 From: chesterip Date: Fri, 26 Apr 2024 09:56:31 -0400 Subject: [PATCH 28/28] Fix template --- templates/swagger/v1_json.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 4257f1dd8525a..f69679d3f3c26 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4049,7 +4049,7 @@ "$ref": "#/responses/notFound" }, "409": { - "$ref": "#/responses/error" + "$ref": "#/responses/conflict" }, "422": { "$ref": "#/responses/validationError" @@ -18036,7 +18036,7 @@ }, "head_sha": { "type": "string", - "x-go-name": "HeadSha" + "x-go-name": "HeadSHA" }, "id": { "type": "integer",