From 21839e6e6444e14c329e9c4d74dc69a4ffd3e579 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 23 Apr 2024 14:07:08 +0800 Subject: [PATCH 1/8] feat: enhance Actions Secrets Management API - Add endpoint to list repository action secrets in API routes - Implement `ListActionsSecrets` function to retrieve action secrets from the database - Update Swagger documentation to include the new `/repos/{owner}/{repo}/actions/secrets` endpoint Signed-off-by: Bo-Yi Wu --- routers/api/v1/api.go | 1 + routers/api/v1/repo/action.go | 60 ++++++++++++++++++++++++++++++++++ templates/swagger/v1_json.tmpl | 50 +++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 5358906f27d51..93942ea854c48 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1075,6 +1075,7 @@ func Routes() *web.Route { }, reqToken()) m.Group("/actions", func() { m.Group("/secrets", func() { + m.Get("", reqToken(), reqOwner(), repo.ListActionsSecrets) m.Combo("/{secretname}"). Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret). Delete(reqToken(), reqOwner(), repo.DeleteSecret) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 03321d956d7cb..bdee0befa78f4 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -9,6 +9,7 @@ import ( actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" + secret_model "code.gitea.io/gitea/models/secret" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" @@ -18,6 +19,65 @@ import ( secret_service "code.gitea.io/gitea/services/secrets" ) +// ListActionsSecrets list an repo's actions secrets +func ListActionsSecrets(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/actions/secrets repository repoListActionsSecrets + // --- + // summary: List an repo's actions secrets + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repository + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repository + // 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 + // type: integer + // responses: + // "200": + // "$ref": "#/responses/SecretList" + // "404": + // "$ref": "#/responses/notFound" + + owner := ctx.Repo.Owner + repo := ctx.Repo.Repository + + opts := &secret_model.FindSecretsOptions{ + OwnerID: owner.ID, + RepoID: repo.ID, + ListOptions: utils.GetListOptions(ctx), + } + + secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts) + if err != nil { + ctx.InternalServerError(err) + return + } + + apiSecrets := make([]*api.Secret, len(secrets)) + for k, v := range secrets { + apiSecrets[k] = &api.Secret{ + Name: v.Name, + Created: v.CreatedUnix.AsTime(), + } + } + + ctx.SetTotalCountHeader(count) + ctx.JSON(http.StatusOK, apiSecrets) +} + // create or update one secret of the repository func CreateOrUpdateSecret(ctx *context.APIContext) { // swagger:operation PUT /repos/{owner}/{repo}/actions/secrets/{secretname} repository updateRepoSecret diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index faf57454d7a62..afb303edb0f66 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3843,6 +3843,54 @@ } } }, + "/repos/{owner}/{repo}/actions/secrets": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "List an repo's actions secrets", + "operationId": "repoListActionsSecrets", + "parameters": [ + { + "type": "string", + "description": "owner of the repository", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repository", + "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", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/SecretList" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/actions/secrets/{secretname}": { "put": { "consumes": [ @@ -25631,4 +25679,4 @@ "TOTPHeader": [] } ] -} +} \ No newline at end of file From 37287d3836aa45664e79916904efd2e057da8ca3 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 23 Apr 2024 14:18:51 +0800 Subject: [PATCH 2/8] refactor: refactor Secrets Management Logic - Remove owner variable and direct owner ID reference in `ListActionsSecrets` function. Signed-off-by: Bo-Yi Wu --- routers/api/v1/repo/action.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index bdee0befa78f4..5a9856bc17fb5 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -51,11 +51,9 @@ func ListActionsSecrets(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - owner := ctx.Repo.Owner repo := ctx.Repo.Repository opts := &secret_model.FindSecretsOptions{ - OwnerID: owner.ID, RepoID: repo.ID, ListOptions: utils.GetListOptions(ctx), } From 40d720f57437211f3f9afde10438df4e566871af Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 23 Apr 2024 14:25:09 +0800 Subject: [PATCH 3/8] test: enhance API testing and secret management - Add a new test case for listing repository secrets in the API integration tests Signed-off-by: Bo-Yi Wu --- tests/integration/api_repo_secrets_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integration/api_repo_secrets_test.go b/tests/integration/api_repo_secrets_test.go index feb9bae2b22c7..a38345e71d431 100644 --- a/tests/integration/api_repo_secrets_test.go +++ b/tests/integration/api_repo_secrets_test.go @@ -24,6 +24,12 @@ func TestAPIRepoSecrets(t *testing.T) { session := loginUser(t, user.Name) token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) + t.Run("List", func(t *testing.T) { + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/secrets", repo.FullName())). + AddTokenAuth(token) + MakeRequest(t, req, http.StatusOK) + }) + t.Run("Create", func(t *testing.T) { cases := []struct { Name string From b05f712cbc8169f203266e4e71fd075cdf4cfa48 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 23 Apr 2024 15:59:40 +0800 Subject: [PATCH 4/8] refactor: refactor GitHub Actions API Routing - Refactor API routing for actions, secrets, variables, and runners into a new `actionsGroup` function - Introduce a new `actionAPI` struct to encapsulate action-related API functions Signed-off-by: Bo-Yi Wu --- routers/api/v1/api.go | 113 +++++++++++++++++++++------------ templates/swagger/v1_json.tmpl | 2 +- 2 files changed, 72 insertions(+), 43 deletions(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 93942ea854c48..12fca09882a58 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -1073,27 +1073,21 @@ func Routes() *web.Route { m.Post("/accept", repo.AcceptTransfer) m.Post("/reject", repo.RejectTransfer) }, reqToken()) - m.Group("/actions", func() { - m.Group("/secrets", func() { - m.Get("", reqToken(), reqOwner(), repo.ListActionsSecrets) - m.Combo("/{secretname}"). - Put(reqToken(), reqOwner(), bind(api.CreateOrUpdateSecretOption{}), repo.CreateOrUpdateSecret). - Delete(reqToken(), reqOwner(), repo.DeleteSecret) - }) - - m.Group("/variables", func() { - m.Get("", reqToken(), reqOwner(), repo.ListVariables) - m.Combo("/{variablename}"). - Get(reqToken(), reqOwner(), repo.GetVariable). - Delete(reqToken(), reqOwner(), repo.DeleteVariable). - Post(reqToken(), reqOwner(), bind(api.CreateVariableOption{}), repo.CreateVariable). - Put(reqToken(), reqOwner(), bind(api.UpdateVariableOption{}), repo.UpdateVariable) - }) - - m.Group("/runners", func() { - m.Get("/registration-token", reqToken(), reqOwner(), repo.GetRegistrationToken) - }) - }) + actionsGroup( + m, + reqOwner(), + actionAPI{ + repo.ListActionsSecrets, + repo.CreateOrUpdateSecret, + repo.DeleteSecret, + repo.ListVariables, + repo.GetVariable, + repo.DeleteVariable, + repo.CreateVariable, + repo.UpdateVariable, + repo.GetRegistrationToken, + }, + ) m.Group("/hooks/git", func() { m.Combo("").Get(repo.ListGitHooks) m.Group("/{id}", func() { @@ -1461,27 +1455,21 @@ func Routes() *web.Route { m.Combo("/{username}").Get(reqToken(), org.IsMember). Delete(reqToken(), reqOrgOwnership(), org.DeleteMember) }) - m.Group("/actions", func() { - m.Group("/secrets", func() { - m.Get("", reqToken(), reqOrgOwnership(), org.ListActionsSecrets) - m.Combo("/{secretname}"). - Put(reqToken(), reqOrgOwnership(), bind(api.CreateOrUpdateSecretOption{}), org.CreateOrUpdateSecret). - Delete(reqToken(), reqOrgOwnership(), org.DeleteSecret) - }) - - m.Group("/variables", func() { - m.Get("", reqToken(), reqOrgOwnership(), org.ListVariables) - m.Combo("/{variablename}"). - Get(reqToken(), reqOrgOwnership(), org.GetVariable). - Delete(reqToken(), reqOrgOwnership(), org.DeleteVariable). - Post(reqToken(), reqOrgOwnership(), bind(api.CreateVariableOption{}), org.CreateVariable). - Put(reqToken(), reqOrgOwnership(), bind(api.UpdateVariableOption{}), org.UpdateVariable) - }) - - m.Group("/runners", func() { - m.Get("/registration-token", reqToken(), reqOrgOwnership(), org.GetRegistrationToken) - }) - }) + actionsGroup( + m, + reqOrgOwnership(), + actionAPI{ + org.ListActionsSecrets, + org.CreateOrUpdateSecret, + org.DeleteSecret, + org.ListVariables, + org.GetVariable, + org.DeleteVariable, + org.CreateVariable, + org.UpdateVariable, + org.GetRegistrationToken, + }, + ) m.Group("/public_members", func() { m.Get("", org.ListPublicMembers) m.Combo("/{username}").Get(org.IsPublicMember). @@ -1597,6 +1585,47 @@ func Routes() *web.Route { return m } +// actionAPI is a struct that holds the actions API +type actionAPI struct { + ListActionsSecrets func(ctx *context.APIContext) + CreateOrUpdateSecret func(ctx *context.APIContext) + DeleteSecret func(ctx *context.APIContext) + ListVariables func(ctx *context.APIContext) + GetVariable func(ctx *context.APIContext) + DeleteVariable func(ctx *context.APIContext) + CreateVariable func(ctx *context.APIContext) + UpdateVariable func(ctx *context.APIContext) + GetRegistrationToken func(ctx *context.APIContext) +} + +func actionsGroup( + m *web.Route, + reqChecker func(ctx *context.APIContext), + act actionAPI, +) { + m.Group("/actions", func() { + m.Group("/secrets", func() { + m.Get("", reqToken(), reqChecker, act.ListActionsSecrets) + m.Combo("/{secretname}"). + Put(reqToken(), reqChecker, bind(api.CreateOrUpdateSecretOption{}), act.CreateOrUpdateSecret). + Delete(reqToken(), reqChecker, act.DeleteSecret) + }) + + m.Group("/variables", func() { + m.Get("", reqToken(), reqChecker, act.ListVariables) + m.Combo("/{variablename}"). + Get(reqToken(), reqChecker, act.GetVariable). + Delete(reqToken(), reqChecker, act.DeleteVariable). + Post(reqToken(), reqChecker, bind(api.CreateVariableOption{}), act.CreateVariable). + Put(reqToken(), reqChecker, bind(api.UpdateVariableOption{}), act.UpdateVariable) + }) + + m.Group("/runners", func() { + m.Get("/registration-token", reqToken(), reqChecker, act.GetRegistrationToken) + }) + }) +} + func securityHeaders() func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index afb303edb0f66..3ed4e43e6d896 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -25679,4 +25679,4 @@ "TOTPHeader": [] } ] -} \ No newline at end of file +} From 01e1edfc1d15581c7397d071dda2efa005238d8e Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 24 Apr 2024 14:57:42 +0800 Subject: [PATCH 5/8] refactor: refactor action APIs and consolidate models - Add `actions` package import and define new routes for actions, secrets, variables, and runners in `api.go`. - Refactor action-related API functions into `Action` struct methods in `org/action.go` and `repo/action.go`. - Remove `actionAPI` struct and related functions, replacing them with `NewAction()` calls. - Rename `variables.go` to `action.go` in `org` directory. - Delete `runners.go` and `secrets.go` in both `org` and `repo` directories, consolidating their content into `action.go`. - Update copyright year and add new imports in `org/action.go`. - Implement `API` interface in `services/actions/interface.go` for action-related methods. - Remove individual action-related functions and replace them with methods on the `Action` struct in `repo/action.go`. Signed-off-by: Bo-Yi Wu --- routers/api/v1/api.go | 98 +++------ .../api/v1/org/{variables.go => action.go} | 193 +++++++++++++++++- routers/api/v1/org/runners.go | 31 --- routers/api/v1/org/secrets.go | 166 --------------- routers/api/v1/repo/action.go | 51 ++++- routers/api/v1/repo/runners.go | 34 --- services/actions/interface.go | 18 ++ 7 files changed, 281 insertions(+), 310 deletions(-) rename routers/api/v1/org/{variables.go => action.go} (58%) delete mode 100644 routers/api/v1/org/runners.go delete mode 100644 routers/api/v1/org/secrets.go delete mode 100644 routers/api/v1/repo/runners.go create mode 100644 services/actions/interface.go diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 12fca09882a58..73071aa8df7ee 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -93,6 +93,7 @@ import ( "code.gitea.io/gitea/routers/api/v1/settings" "code.gitea.io/gitea/routers/api/v1/user" "code.gitea.io/gitea/routers/common" + "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/forms" @@ -835,6 +836,34 @@ func Routes() *web.Route { SignInRequired: setting.Service.RequireSignInView, })) + addActionsRoutes := func( + m *web.Route, + reqChecker func(ctx *context.APIContext), + act actions.API, + ) { + m.Group("/actions", func() { + m.Group("/secrets", func() { + m.Get("", reqToken(), reqChecker, act.ListActionsSecrets) + m.Combo("/{secretname}"). + Put(reqToken(), reqChecker, bind(api.CreateOrUpdateSecretOption{}), act.CreateOrUpdateSecret). + Delete(reqToken(), reqChecker, act.DeleteSecret) + }) + + m.Group("/variables", func() { + m.Get("", reqToken(), reqChecker, act.ListVariables) + m.Combo("/{variablename}"). + Get(reqToken(), reqChecker, act.GetVariable). + Delete(reqToken(), reqChecker, act.DeleteVariable). + Post(reqToken(), reqChecker, bind(api.CreateVariableOption{}), act.CreateVariable). + Put(reqToken(), reqChecker, bind(api.UpdateVariableOption{}), act.UpdateVariable) + }) + + m.Group("/runners", func() { + m.Get("/registration-token", reqToken(), reqChecker, act.GetRegistrationToken) + }) + }) + } + m.Group("", func() { // Miscellaneous (no scope required) if setting.API.EnableSwagger { @@ -1073,20 +1102,10 @@ func Routes() *web.Route { m.Post("/accept", repo.AcceptTransfer) m.Post("/reject", repo.RejectTransfer) }, reqToken()) - actionsGroup( + addActionsRoutes( m, reqOwner(), - actionAPI{ - repo.ListActionsSecrets, - repo.CreateOrUpdateSecret, - repo.DeleteSecret, - repo.ListVariables, - repo.GetVariable, - repo.DeleteVariable, - repo.CreateVariable, - repo.UpdateVariable, - repo.GetRegistrationToken, - }, + repo.NewAction(), ) m.Group("/hooks/git", func() { m.Combo("").Get(repo.ListGitHooks) @@ -1455,20 +1474,10 @@ func Routes() *web.Route { m.Combo("/{username}").Get(reqToken(), org.IsMember). Delete(reqToken(), reqOrgOwnership(), org.DeleteMember) }) - actionsGroup( + addActionsRoutes( m, reqOrgOwnership(), - actionAPI{ - org.ListActionsSecrets, - org.CreateOrUpdateSecret, - org.DeleteSecret, - org.ListVariables, - org.GetVariable, - org.DeleteVariable, - org.CreateVariable, - org.UpdateVariable, - org.GetRegistrationToken, - }, + org.NewAction(), ) m.Group("/public_members", func() { m.Get("", org.ListPublicMembers) @@ -1585,47 +1594,6 @@ func Routes() *web.Route { return m } -// actionAPI is a struct that holds the actions API -type actionAPI struct { - ListActionsSecrets func(ctx *context.APIContext) - CreateOrUpdateSecret func(ctx *context.APIContext) - DeleteSecret func(ctx *context.APIContext) - ListVariables func(ctx *context.APIContext) - GetVariable func(ctx *context.APIContext) - DeleteVariable func(ctx *context.APIContext) - CreateVariable func(ctx *context.APIContext) - UpdateVariable func(ctx *context.APIContext) - GetRegistrationToken func(ctx *context.APIContext) -} - -func actionsGroup( - m *web.Route, - reqChecker func(ctx *context.APIContext), - act actionAPI, -) { - m.Group("/actions", func() { - m.Group("/secrets", func() { - m.Get("", reqToken(), reqChecker, act.ListActionsSecrets) - m.Combo("/{secretname}"). - Put(reqToken(), reqChecker, bind(api.CreateOrUpdateSecretOption{}), act.CreateOrUpdateSecret). - Delete(reqToken(), reqChecker, act.DeleteSecret) - }) - - m.Group("/variables", func() { - m.Get("", reqToken(), reqChecker, act.ListVariables) - m.Combo("/{variablename}"). - Get(reqToken(), reqChecker, act.GetVariable). - Delete(reqToken(), reqChecker, act.DeleteVariable). - Post(reqToken(), reqChecker, bind(api.CreateVariableOption{}), act.CreateVariable). - Put(reqToken(), reqChecker, bind(api.UpdateVariableOption{}), act.UpdateVariable) - }) - - m.Group("/runners", func() { - m.Get("/registration-token", reqToken(), reqChecker, act.GetRegistrationToken) - }) - }) -} - func securityHeaders() func(http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { diff --git a/routers/api/v1/org/variables.go b/routers/api/v1/org/action.go similarity index 58% rename from routers/api/v1/org/variables.go rename to routers/api/v1/org/action.go index eaf7bdc45ba0f..14b64ed41ae9c 100644 --- a/routers/api/v1/org/variables.go +++ b/routers/api/v1/org/action.go @@ -1,4 +1,4 @@ -// Copyright 2024 The Gitea Authors. All rights reserved. +// Copyright 2023 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package org @@ -9,16 +9,188 @@ import ( actions_model "code.gitea.io/gitea/models/actions" "code.gitea.io/gitea/models/db" + secret_model "code.gitea.io/gitea/models/secret" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/routers/api/v1/shared" "code.gitea.io/gitea/routers/api/v1/utils" actions_service "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/context" + secret_service "code.gitea.io/gitea/services/secrets" ) +// ListActionsSecrets list an organization's actions secrets +func (a *Action) ListActionsSecrets(ctx *context.APIContext) { + // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets + // --- + // summary: List an organization's actions secrets + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of the organization + // 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 + // type: integer + // responses: + // "200": + // "$ref": "#/responses/SecretList" + // "404": + // "$ref": "#/responses/notFound" + + opts := &secret_model.FindSecretsOptions{ + OwnerID: ctx.Org.Organization.ID, + ListOptions: utils.GetListOptions(ctx), + } + + secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts) + if err != nil { + ctx.InternalServerError(err) + return + } + + apiSecrets := make([]*api.Secret, len(secrets)) + for k, v := range secrets { + apiSecrets[k] = &api.Secret{ + Name: v.Name, + Created: v.CreatedUnix.AsTime(), + } + } + + ctx.SetTotalCountHeader(count) + ctx.JSON(http.StatusOK, apiSecrets) +} + +// create or update one secret of the organization +func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { + // swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret + // --- + // summary: Create or Update a secret value in an organization + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of organization + // type: string + // required: true + // - name: secretname + // in: path + // description: name of the secret + // type: string + // required: true + // - name: body + // in: body + // schema: + // "$ref": "#/definitions/CreateOrUpdateSecretOption" + // responses: + // "201": + // description: response when creating a secret + // "204": + // description: response when updating a secret + // "400": + // "$ref": "#/responses/error" + // "404": + // "$ref": "#/responses/notFound" + + opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) + + _, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname"), opt.Data) + if err != nil { + if errors.Is(err, util.ErrInvalidArgument) { + ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err) + } else if errors.Is(err, util.ErrNotExist) { + ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err) + } else { + ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err) + } + return + } + + if created { + ctx.Status(http.StatusCreated) + } else { + ctx.Status(http.StatusNoContent) + } +} + +// DeleteSecret delete one secret of the organization +func (a *Action) DeleteSecret(ctx *context.APIContext) { + // swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret + // --- + // summary: Delete a secret in an organization + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of organization + // type: string + // required: true + // - name: secretname + // in: path + // description: name of the secret + // type: string + // required: true + // responses: + // "204": + // description: delete one secret of the organization + // "400": + // "$ref": "#/responses/error" + // "404": + // "$ref": "#/responses/notFound" + + err := secret_service.DeleteSecretByName(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname")) + if err != nil { + if errors.Is(err, util.ErrInvalidArgument) { + ctx.Error(http.StatusBadRequest, "DeleteSecret", err) + } else if errors.Is(err, util.ErrNotExist) { + ctx.Error(http.StatusNotFound, "DeleteSecret", err) + } else { + ctx.Error(http.StatusInternalServerError, "DeleteSecret", err) + } + return + } + + ctx.Status(http.StatusNoContent) +} + +// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization +// GetRegistrationToken returns the token to register org runners +func (a *Action) GetRegistrationToken(ctx *context.APIContext) { + // swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken + // --- + // summary: Get an organization's actions runner registration token + // produces: + // - application/json + // parameters: + // - name: org + // in: path + // description: name of the organization + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/RegistrationToken" + + shared.GetRegistrationToken(ctx, ctx.Org.Organization.ID, 0) +} + // ListVariables list org-level variables -func ListVariables(ctx *context.APIContext) { +func (a *Action) ListVariables(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/variables organization getOrgVariablesList // --- // summary: Get an org-level variables list @@ -70,7 +242,7 @@ func ListVariables(ctx *context.APIContext) { } // GetVariable get an org-level variable -func GetVariable(ctx *context.APIContext) { +func (a *Action) GetVariable(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/variables/{variablename} organization getOrgVariable // --- // summary: Get an org-level variable @@ -119,7 +291,7 @@ func GetVariable(ctx *context.APIContext) { } // DeleteVariable delete an org-level variable -func DeleteVariable(ctx *context.APIContext) { +func (a *Action) DeleteVariable(ctx *context.APIContext) { // swagger:operation DELETE /orgs/{org}/actions/variables/{variablename} organization deleteOrgVariable // --- // summary: Delete an org-level variable @@ -163,7 +335,7 @@ func DeleteVariable(ctx *context.APIContext) { } // CreateVariable create an org-level variable -func CreateVariable(ctx *context.APIContext) { +func (a *Action) CreateVariable(ctx *context.APIContext) { // swagger:operation POST /orgs/{org}/actions/variables/{variablename} organization createOrgVariable // --- // summary: Create an org-level variable @@ -227,7 +399,7 @@ func CreateVariable(ctx *context.APIContext) { } // UpdateVariable update an org-level variable -func UpdateVariable(ctx *context.APIContext) { +func (a *Action) UpdateVariable(ctx *context.APIContext) { // swagger:operation PUT /orgs/{org}/actions/variables/{variablename} organization updateOrgVariable // --- // summary: Update an org-level variable @@ -289,3 +461,12 @@ func UpdateVariable(ctx *context.APIContext) { ctx.Status(http.StatusNoContent) } + +var _ actions_service.API = new(Action) + +type Action struct{} + +// NewAction creates a new Action service +func NewAction() actions_service.API { + return &Action{} +} diff --git a/routers/api/v1/org/runners.go b/routers/api/v1/org/runners.go deleted file mode 100644 index 2a52bd8778f7e..0000000000000 --- a/routers/api/v1/org/runners.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package org - -import ( - "code.gitea.io/gitea/routers/api/v1/shared" - "code.gitea.io/gitea/services/context" -) - -// https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization - -// GetRegistrationToken returns the token to register org runners -func GetRegistrationToken(ctx *context.APIContext) { - // swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken - // --- - // summary: Get an organization's actions runner registration token - // produces: - // - application/json - // parameters: - // - name: org - // in: path - // description: name of the organization - // type: string - // required: true - // responses: - // "200": - // "$ref": "#/responses/RegistrationToken" - - shared.GetRegistrationToken(ctx, ctx.Org.Organization.ID, 0) -} diff --git a/routers/api/v1/org/secrets.go b/routers/api/v1/org/secrets.go deleted file mode 100644 index abb6bb26c433f..0000000000000 --- a/routers/api/v1/org/secrets.go +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package org - -import ( - "errors" - "net/http" - - "code.gitea.io/gitea/models/db" - secret_model "code.gitea.io/gitea/models/secret" - api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/util" - "code.gitea.io/gitea/modules/web" - "code.gitea.io/gitea/routers/api/v1/utils" - "code.gitea.io/gitea/services/context" - secret_service "code.gitea.io/gitea/services/secrets" -) - -// ListActionsSecrets list an organization's actions secrets -func ListActionsSecrets(ctx *context.APIContext) { - // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets - // --- - // summary: List an organization's actions secrets - // produces: - // - application/json - // parameters: - // - name: org - // in: path - // description: name of the organization - // 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 - // type: integer - // responses: - // "200": - // "$ref": "#/responses/SecretList" - // "404": - // "$ref": "#/responses/notFound" - - opts := &secret_model.FindSecretsOptions{ - OwnerID: ctx.Org.Organization.ID, - ListOptions: utils.GetListOptions(ctx), - } - - secrets, count, err := db.FindAndCount[secret_model.Secret](ctx, opts) - if err != nil { - ctx.InternalServerError(err) - return - } - - apiSecrets := make([]*api.Secret, len(secrets)) - for k, v := range secrets { - apiSecrets[k] = &api.Secret{ - Name: v.Name, - Created: v.CreatedUnix.AsTime(), - } - } - - ctx.SetTotalCountHeader(count) - ctx.JSON(http.StatusOK, apiSecrets) -} - -// create or update one secret of the organization -func CreateOrUpdateSecret(ctx *context.APIContext) { - // swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret - // --- - // summary: Create or Update a secret value in an organization - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: org - // in: path - // description: name of organization - // type: string - // required: true - // - name: secretname - // in: path - // description: name of the secret - // type: string - // required: true - // - name: body - // in: body - // schema: - // "$ref": "#/definitions/CreateOrUpdateSecretOption" - // responses: - // "201": - // description: response when creating a secret - // "204": - // description: response when updating a secret - // "400": - // "$ref": "#/responses/error" - // "404": - // "$ref": "#/responses/notFound" - - opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) - - _, created, err := secret_service.CreateOrUpdateSecret(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname"), opt.Data) - if err != nil { - if errors.Is(err, util.ErrInvalidArgument) { - ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err) - } else if errors.Is(err, util.ErrNotExist) { - ctx.Error(http.StatusNotFound, "CreateOrUpdateSecret", err) - } else { - ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err) - } - return - } - - if created { - ctx.Status(http.StatusCreated) - } else { - ctx.Status(http.StatusNoContent) - } -} - -// DeleteSecret delete one secret of the organization -func DeleteSecret(ctx *context.APIContext) { - // swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret - // --- - // summary: Delete a secret in an organization - // consumes: - // - application/json - // produces: - // - application/json - // parameters: - // - name: org - // in: path - // description: name of organization - // type: string - // required: true - // - name: secretname - // in: path - // description: name of the secret - // type: string - // required: true - // responses: - // "204": - // description: delete one secret of the organization - // "400": - // "$ref": "#/responses/error" - // "404": - // "$ref": "#/responses/notFound" - - err := secret_service.DeleteSecretByName(ctx, ctx.Org.Organization.ID, 0, ctx.Params("secretname")) - if err != nil { - if errors.Is(err, util.ErrInvalidArgument) { - ctx.Error(http.StatusBadRequest, "DeleteSecret", err) - } else if errors.Is(err, util.ErrNotExist) { - ctx.Error(http.StatusNotFound, "DeleteSecret", err) - } else { - ctx.Error(http.StatusInternalServerError, "DeleteSecret", err) - } - return - } - - ctx.Status(http.StatusNoContent) -} diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 5a9856bc17fb5..76a5f1ec73242 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -13,6 +13,7 @@ import ( api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/routers/api/v1/shared" "code.gitea.io/gitea/routers/api/v1/utils" actions_service "code.gitea.io/gitea/services/actions" "code.gitea.io/gitea/services/context" @@ -20,7 +21,7 @@ import ( ) // ListActionsSecrets list an repo's actions secrets -func ListActionsSecrets(ctx *context.APIContext) { +func (a *Action) ListActionsSecrets(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/secrets repository repoListActionsSecrets // --- // summary: List an repo's actions secrets @@ -77,7 +78,7 @@ func ListActionsSecrets(ctx *context.APIContext) { } // create or update one secret of the repository -func CreateOrUpdateSecret(ctx *context.APIContext) { +func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { // swagger:operation PUT /repos/{owner}/{repo}/actions/secrets/{secretname} repository updateRepoSecret // --- // summary: Create or Update a secret value in a repository @@ -140,7 +141,7 @@ func CreateOrUpdateSecret(ctx *context.APIContext) { } // DeleteSecret delete one secret of the repository -func DeleteSecret(ctx *context.APIContext) { +func (a *Action) DeleteSecret(ctx *context.APIContext) { // swagger:operation DELETE /repos/{owner}/{repo}/actions/secrets/{secretname} repository deleteRepoSecret // --- // summary: Delete a secret in a repository @@ -191,7 +192,7 @@ func DeleteSecret(ctx *context.APIContext) { } // GetVariable get a repo-level variable -func GetVariable(ctx *context.APIContext) { +func (a *Action) GetVariable(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/variables/{variablename} repository getRepoVariable // --- // summary: Get a repo-level variable @@ -244,7 +245,7 @@ func GetVariable(ctx *context.APIContext) { } // DeleteVariable delete a repo-level variable -func DeleteVariable(ctx *context.APIContext) { +func (a *Action) DeleteVariable(ctx *context.APIContext) { // swagger:operation DELETE /repos/{owner}/{repo}/actions/variables/{variablename} repository deleteRepoVariable // --- // summary: Delete a repo-level variable @@ -293,7 +294,7 @@ func DeleteVariable(ctx *context.APIContext) { } // CreateVariable create a repo-level variable -func CreateVariable(ctx *context.APIContext) { +func (a *Action) CreateVariable(ctx *context.APIContext) { // swagger:operation POST /repos/{owner}/{repo}/actions/variables/{variablename} repository createRepoVariable // --- // summary: Create a repo-level variable @@ -360,7 +361,7 @@ func CreateVariable(ctx *context.APIContext) { } // UpdateVariable update a repo-level variable -func UpdateVariable(ctx *context.APIContext) { +func (a *Action) UpdateVariable(ctx *context.APIContext) { // swagger:operation PUT /repos/{owner}/{repo}/actions/variables/{variablename} repository updateRepoVariable // --- // summary: Update a repo-level variable @@ -427,7 +428,7 @@ func UpdateVariable(ctx *context.APIContext) { } // ListVariables list repo-level variables -func ListVariables(ctx *context.APIContext) { +func (a *Action) ListVariables(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/variables repository getRepoVariablesList // --- // summary: Get repo-level variables list @@ -481,3 +482,37 @@ func ListVariables(ctx *context.APIContext) { ctx.SetTotalCountHeader(count) ctx.JSON(http.StatusOK, variables) } + +// GetRegistrationToken returns the token to register repo runners +func (a *Action) GetRegistrationToken(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/runners/registration-token repository repoGetRunnerRegistrationToken + // --- + // summary: Get a repository's actions runner registration token + // 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 + // responses: + // "200": + // "$ref": "#/responses/RegistrationToken" + + shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID) +} + +var _ actions_service.API = new(Action) + +type Action struct{} + +// NewAction creates a new Action service +func NewAction() actions_service.API { + return &Action{} +} diff --git a/routers/api/v1/repo/runners.go b/routers/api/v1/repo/runners.go deleted file mode 100644 index fe133b311d503..0000000000000 --- a/routers/api/v1/repo/runners.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package repo - -import ( - "code.gitea.io/gitea/routers/api/v1/shared" - "code.gitea.io/gitea/services/context" -) - -// GetRegistrationToken returns the token to register repo runners -func GetRegistrationToken(ctx *context.APIContext) { - // swagger:operation GET /repos/{owner}/{repo}/runners/registration-token repository repoGetRunnerRegistrationToken - // --- - // summary: Get a repository's actions runner registration token - // 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 - // responses: - // "200": - // "$ref": "#/responses/RegistrationToken" - - shared.GetRegistrationToken(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.ID) -} diff --git a/services/actions/interface.go b/services/actions/interface.go new file mode 100644 index 0000000000000..079b937824aeb --- /dev/null +++ b/services/actions/interface.go @@ -0,0 +1,18 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package actions + +import "code.gitea.io/gitea/services/context" + +type API interface { + ListActionsSecrets(*context.APIContext) + CreateOrUpdateSecret(*context.APIContext) + DeleteSecret(*context.APIContext) + ListVariables(*context.APIContext) + GetVariable(*context.APIContext) + DeleteVariable(*context.APIContext) + CreateVariable(*context.APIContext) + UpdateVariable(*context.APIContext) + GetRegistrationToken(*context.APIContext) +} From 2f94488c5e7ad98156d03fb4feefa3e6e64df7dd Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 24 Apr 2024 16:43:24 +0800 Subject: [PATCH 6/8] chore: update copyright year --- routers/api/v1/org/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index 14b64ed41ae9c..b7a68e462bf3d 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -1,4 +1,4 @@ -// Copyright 2023 The Gitea Authors. All rights reserved. +// Copyright 2024 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT package org From 01b57717aa5f8662d765bce4f6982aa4fcb7e0c0 Mon Sep 17 00:00:00 2001 From: appleboy Date: Wed, 24 Apr 2024 21:15:36 +0800 Subject: [PATCH 7/8] refactor: refactor method signatures and comments - Update method receiver from `*Action` to `Action` - Update method signatures to remove receiver argument - Update swagger operation comments to reflect changes Signed-off-by: appleboy --- routers/api/v1/org/action.go | 21 +++++++++++---------- routers/api/v1/repo/action.go | 21 +++++++++++---------- services/actions/interface.go | 10 ++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/routers/api/v1/org/action.go b/routers/api/v1/org/action.go index b7a68e462bf3d..03a1fa8ccc368 100644 --- a/routers/api/v1/org/action.go +++ b/routers/api/v1/org/action.go @@ -21,7 +21,7 @@ import ( ) // ListActionsSecrets list an organization's actions secrets -func (a *Action) ListActionsSecrets(ctx *context.APIContext) { +func (Action) ListActionsSecrets(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/secrets organization orgListActionsSecrets // --- // summary: List an organization's actions secrets @@ -71,7 +71,7 @@ func (a *Action) ListActionsSecrets(ctx *context.APIContext) { } // create or update one secret of the organization -func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { +func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { // swagger:operation PUT /orgs/{org}/actions/secrets/{secretname} organization updateOrgSecret // --- // summary: Create or Update a secret value in an organization @@ -126,7 +126,7 @@ func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { } // DeleteSecret delete one secret of the organization -func (a *Action) DeleteSecret(ctx *context.APIContext) { +func (Action) DeleteSecret(ctx *context.APIContext) { // swagger:operation DELETE /orgs/{org}/actions/secrets/{secretname} organization deleteOrgSecret // --- // summary: Delete a secret in an organization @@ -170,7 +170,7 @@ func (a *Action) DeleteSecret(ctx *context.APIContext) { // https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization // GetRegistrationToken returns the token to register org runners -func (a *Action) GetRegistrationToken(ctx *context.APIContext) { +func (Action) GetRegistrationToken(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/runners/registration-token organization orgGetRunnerRegistrationToken // --- // summary: Get an organization's actions runner registration token @@ -190,7 +190,7 @@ func (a *Action) GetRegistrationToken(ctx *context.APIContext) { } // ListVariables list org-level variables -func (a *Action) ListVariables(ctx *context.APIContext) { +func (Action) ListVariables(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/variables organization getOrgVariablesList // --- // summary: Get an org-level variables list @@ -242,7 +242,7 @@ func (a *Action) ListVariables(ctx *context.APIContext) { } // GetVariable get an org-level variable -func (a *Action) GetVariable(ctx *context.APIContext) { +func (Action) GetVariable(ctx *context.APIContext) { // swagger:operation GET /orgs/{org}/actions/variables/{variablename} organization getOrgVariable // --- // summary: Get an org-level variable @@ -291,7 +291,7 @@ func (a *Action) GetVariable(ctx *context.APIContext) { } // DeleteVariable delete an org-level variable -func (a *Action) DeleteVariable(ctx *context.APIContext) { +func (Action) DeleteVariable(ctx *context.APIContext) { // swagger:operation DELETE /orgs/{org}/actions/variables/{variablename} organization deleteOrgVariable // --- // summary: Delete an org-level variable @@ -335,7 +335,7 @@ func (a *Action) DeleteVariable(ctx *context.APIContext) { } // CreateVariable create an org-level variable -func (a *Action) CreateVariable(ctx *context.APIContext) { +func (Action) CreateVariable(ctx *context.APIContext) { // swagger:operation POST /orgs/{org}/actions/variables/{variablename} organization createOrgVariable // --- // summary: Create an org-level variable @@ -399,7 +399,7 @@ func (a *Action) CreateVariable(ctx *context.APIContext) { } // UpdateVariable update an org-level variable -func (a *Action) UpdateVariable(ctx *context.APIContext) { +func (Action) UpdateVariable(ctx *context.APIContext) { // swagger:operation PUT /orgs/{org}/actions/variables/{variablename} organization updateOrgVariable // --- // summary: Update an org-level variable @@ -464,9 +464,10 @@ func (a *Action) UpdateVariable(ctx *context.APIContext) { var _ actions_service.API = new(Action) +// Action implements actions_service.API type Action struct{} // NewAction creates a new Action service func NewAction() actions_service.API { - return &Action{} + return Action{} } diff --git a/routers/api/v1/repo/action.go b/routers/api/v1/repo/action.go index 76a5f1ec73242..311cfca6e91ba 100644 --- a/routers/api/v1/repo/action.go +++ b/routers/api/v1/repo/action.go @@ -21,7 +21,7 @@ import ( ) // ListActionsSecrets list an repo's actions secrets -func (a *Action) ListActionsSecrets(ctx *context.APIContext) { +func (Action) ListActionsSecrets(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/secrets repository repoListActionsSecrets // --- // summary: List an repo's actions secrets @@ -78,7 +78,7 @@ func (a *Action) ListActionsSecrets(ctx *context.APIContext) { } // create or update one secret of the repository -func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { +func (Action) CreateOrUpdateSecret(ctx *context.APIContext) { // swagger:operation PUT /repos/{owner}/{repo}/actions/secrets/{secretname} repository updateRepoSecret // --- // summary: Create or Update a secret value in a repository @@ -141,7 +141,7 @@ func (a *Action) CreateOrUpdateSecret(ctx *context.APIContext) { } // DeleteSecret delete one secret of the repository -func (a *Action) DeleteSecret(ctx *context.APIContext) { +func (Action) DeleteSecret(ctx *context.APIContext) { // swagger:operation DELETE /repos/{owner}/{repo}/actions/secrets/{secretname} repository deleteRepoSecret // --- // summary: Delete a secret in a repository @@ -192,7 +192,7 @@ func (a *Action) DeleteSecret(ctx *context.APIContext) { } // GetVariable get a repo-level variable -func (a *Action) GetVariable(ctx *context.APIContext) { +func (Action) GetVariable(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/variables/{variablename} repository getRepoVariable // --- // summary: Get a repo-level variable @@ -245,7 +245,7 @@ func (a *Action) GetVariable(ctx *context.APIContext) { } // DeleteVariable delete a repo-level variable -func (a *Action) DeleteVariable(ctx *context.APIContext) { +func (Action) DeleteVariable(ctx *context.APIContext) { // swagger:operation DELETE /repos/{owner}/{repo}/actions/variables/{variablename} repository deleteRepoVariable // --- // summary: Delete a repo-level variable @@ -294,7 +294,7 @@ func (a *Action) DeleteVariable(ctx *context.APIContext) { } // CreateVariable create a repo-level variable -func (a *Action) CreateVariable(ctx *context.APIContext) { +func (Action) CreateVariable(ctx *context.APIContext) { // swagger:operation POST /repos/{owner}/{repo}/actions/variables/{variablename} repository createRepoVariable // --- // summary: Create a repo-level variable @@ -361,7 +361,7 @@ func (a *Action) CreateVariable(ctx *context.APIContext) { } // UpdateVariable update a repo-level variable -func (a *Action) UpdateVariable(ctx *context.APIContext) { +func (Action) UpdateVariable(ctx *context.APIContext) { // swagger:operation PUT /repos/{owner}/{repo}/actions/variables/{variablename} repository updateRepoVariable // --- // summary: Update a repo-level variable @@ -428,7 +428,7 @@ func (a *Action) UpdateVariable(ctx *context.APIContext) { } // ListVariables list repo-level variables -func (a *Action) ListVariables(ctx *context.APIContext) { +func (Action) ListVariables(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/actions/variables repository getRepoVariablesList // --- // summary: Get repo-level variables list @@ -484,7 +484,7 @@ func (a *Action) ListVariables(ctx *context.APIContext) { } // GetRegistrationToken returns the token to register repo runners -func (a *Action) GetRegistrationToken(ctx *context.APIContext) { +func (Action) GetRegistrationToken(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/runners/registration-token repository repoGetRunnerRegistrationToken // --- // summary: Get a repository's actions runner registration token @@ -510,9 +510,10 @@ func (a *Action) GetRegistrationToken(ctx *context.APIContext) { var _ actions_service.API = new(Action) +// Action implements actions_service.API type Action struct{} // NewAction creates a new Action service func NewAction() actions_service.API { - return &Action{} + return Action{} } diff --git a/services/actions/interface.go b/services/actions/interface.go index 079b937824aeb..d4fa782fec797 100644 --- a/services/actions/interface.go +++ b/services/actions/interface.go @@ -5,14 +5,24 @@ package actions import "code.gitea.io/gitea/services/context" +// API for actions of a repository or organization type API interface { + // ListActionsSecrets list secrets ListActionsSecrets(*context.APIContext) + // CreateOrUpdateSecret create or update a secret CreateOrUpdateSecret(*context.APIContext) + // DeleteSecret delete a secret DeleteSecret(*context.APIContext) + // ListVariables list variables ListVariables(*context.APIContext) + // GetVariable get a variable GetVariable(*context.APIContext) + // DeleteVariable delete a variable DeleteVariable(*context.APIContext) + // CreateVariable create a variable CreateVariable(*context.APIContext) + // UpdateVariable update a variable UpdateVariable(*context.APIContext) + // GetRegistrationToken get registration token GetRegistrationToken(*context.APIContext) } From 5f353058bc41730a1d42f519f92849e01f66b92d Mon Sep 17 00:00:00 2001 From: appleboy Date: Wed, 24 Apr 2024 22:03:00 +0800 Subject: [PATCH 8/8] test: refactor error handling across multiple files - Change the expected status from `http.StatusNotFound` to `http.StatusMethodNotAllowed` in the APIRepoSecrets test. Signed-off-by: appleboy --- tests/integration/api_repo_secrets_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/api_repo_secrets_test.go b/tests/integration/api_repo_secrets_test.go index a38345e71d431..c3074d9eceedd 100644 --- a/tests/integration/api_repo_secrets_test.go +++ b/tests/integration/api_repo_secrets_test.go @@ -37,7 +37,7 @@ func TestAPIRepoSecrets(t *testing.T) { }{ { Name: "", - ExpectedStatus: http.StatusNotFound, + ExpectedStatus: http.StatusMethodNotAllowed, }, { Name: "-",