2023-06-21 04:24:15 +05:30
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
actions_model "code.gitea.io/gitea/models/actions"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
"code.gitea.io/gitea/modules/web"
|
2024-03-29 02:10:35 +05:30
|
|
|
actions_service "code.gitea.io/gitea/services/actions"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/context"
|
2023-06-21 04:24:15 +05:30
|
|
|
"code.gitea.io/gitea/services/forms"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetVariablesContext(ctx *context.Context, ownerID, repoID int64) {
|
2023-11-24 09:19:41 +05:30
|
|
|
variables, err := db.Find[actions_model.ActionVariable](ctx, actions_model.FindVariablesOpts{
|
2023-06-21 04:24:15 +05:30
|
|
|
OwnerID: ownerID,
|
|
|
|
RepoID: repoID,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("FindVariables", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["Variables"] = variables
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateVariable(ctx *context.Context, ownerID, repoID int64, redirectURL string) {
|
|
|
|
form := web.GetForm(ctx).(*forms.EditVariableForm)
|
|
|
|
|
2024-03-29 02:10:35 +05:30
|
|
|
v, err := actions_service.CreateVariable(ctx, ownerID, repoID, form.Name, form.Data)
|
2023-06-21 04:24:15 +05:30
|
|
|
if err != nil {
|
2024-03-29 02:10:35 +05:30
|
|
|
log.Error("CreateVariable: %v", err)
|
2023-06-21 04:24:15 +05:30
|
|
|
ctx.JSONError(ctx.Tr("actions.variables.creation.failed"))
|
|
|
|
return
|
|
|
|
}
|
2024-03-29 02:10:35 +05:30
|
|
|
|
2023-06-21 04:24:15 +05:30
|
|
|
ctx.Flash.Success(ctx.Tr("actions.variables.creation.success", v.Name))
|
|
|
|
ctx.JSONRedirect(redirectURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateVariable(ctx *context.Context, redirectURL string) {
|
|
|
|
id := ctx.ParamsInt64(":variable_id")
|
|
|
|
form := web.GetForm(ctx).(*forms.EditVariableForm)
|
|
|
|
|
2024-03-29 02:10:35 +05:30
|
|
|
if ok, err := actions_service.UpdateVariable(ctx, id, form.Name, form.Data); err != nil || !ok {
|
|
|
|
log.Error("UpdateVariable: %v", err)
|
2023-06-21 04:24:15 +05:30
|
|
|
ctx.JSONError(ctx.Tr("actions.variables.update.failed"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("actions.variables.update.success"))
|
|
|
|
ctx.JSONRedirect(redirectURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteVariable(ctx *context.Context, redirectURL string) {
|
|
|
|
id := ctx.ParamsInt64(":variable_id")
|
|
|
|
|
2024-03-29 02:10:35 +05:30
|
|
|
if err := actions_service.DeleteVariableByID(ctx, id); err != nil {
|
2023-06-21 04:24:15 +05:30
|
|
|
log.Error("Delete variable [%d] failed: %v", id, err)
|
|
|
|
ctx.JSONError(ctx.Tr("actions.variables.deletion.failed"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("actions.variables.deletion.success"))
|
|
|
|
ctx.JSONRedirect(redirectURL)
|
|
|
|
}
|