-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(API): add route and implementation for creating/updating reposit…
…ory secret (#26766) spec: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret - Add a new route for creating or updating a secret value in a repository - Create a new file `routers/api/v1/repo/action.go` with the implementation of the `CreateOrUpdateSecret` function - Update the Swagger documentation for the `updateRepoSecret` operation in the `v1_json.tmpl` template file --------- Signed-off-by: Bo-Yi Wu <[email protected]> Co-authored-by: Giteabot <[email protected]>
- Loading branch information
Showing
5 changed files
with
174 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
secret_model "code.gitea.io/gitea/models/secret" | ||
"code.gitea.io/gitea/modules/context" | ||
api "code.gitea.io/gitea/modules/structs" | ||
"code.gitea.io/gitea/modules/web" | ||
"code.gitea.io/gitea/routers/web/shared/actions" | ||
) | ||
|
||
// create or update one secret of the repository | ||
func 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 | ||
// consumes: | ||
// - application/json | ||
// 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: 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" | ||
// "403": | ||
// "$ref": "#/responses/forbidden" | ||
|
||
owner := ctx.Repo.Owner | ||
repo := ctx.Repo.Repository | ||
|
||
secretName := ctx.Params(":secretname") | ||
if err := actions.NameRegexMatch(secretName); err != nil { | ||
ctx.Error(http.StatusBadRequest, "CreateOrUpdateSecret", err) | ||
return | ||
} | ||
opt := web.GetForm(ctx).(*api.CreateOrUpdateSecretOption) | ||
isCreated, err := secret_model.CreateOrUpdateSecret(ctx, owner.ID, repo.ID, secretName, opt.Data) | ||
if err != nil { | ||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateSecret", err) | ||
return | ||
} | ||
if isCreated { | ||
ctx.Status(http.StatusCreated) | ||
return | ||
} | ||
|
||
ctx.Status(http.StatusNoContent) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.