Skip to content

Commit 7c17d0a

Browse files
lunnywolfogrewxiaoguangGiteaBot
authored
Enhance routers for the Actions variable operations (#33547) (#33553)
Backport #33547 Co-authored-by: Jason Song <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent a014d07 commit 7c17d0a

File tree

9 files changed

+363
-176
lines changed

9 files changed

+363
-176
lines changed

models/actions/variable.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,23 @@ func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data strin
5858

5959
type FindVariablesOpts struct {
6060
db.ListOptions
61+
IDs []int64
6162
RepoID int64
6263
OwnerID int64 // it will be ignored if RepoID is set
6364
Name string
6465
}
6566

6667
func (opts FindVariablesOpts) ToConds() builder.Cond {
6768
cond := builder.NewCond()
69+
70+
if len(opts.IDs) > 0 {
71+
if len(opts.IDs) == 1 {
72+
cond = cond.And(builder.Eq{"id": opts.IDs[0]})
73+
} else {
74+
cond = cond.And(builder.In("id", opts.IDs))
75+
}
76+
}
77+
6878
// Since we now support instance-level variables,
6979
// there is no need to check for null values for `owner_id` and `repo_id`
7080
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
@@ -85,12 +95,12 @@ func FindVariables(ctx context.Context, opts FindVariablesOpts) ([]*ActionVariab
8595
return db.Find[ActionVariable](ctx, opts)
8696
}
8797

88-
func UpdateVariable(ctx context.Context, variable *ActionVariable) (bool, error) {
89-
count, err := db.GetEngine(ctx).ID(variable.ID).Cols("name", "data").
90-
Update(&ActionVariable{
91-
Name: variable.Name,
92-
Data: variable.Data,
93-
})
98+
func UpdateVariableCols(ctx context.Context, variable *ActionVariable, cols ...string) (bool, error) {
99+
variable.Name = strings.ToUpper(variable.Name)
100+
count, err := db.GetEngine(ctx).
101+
ID(variable.ID).
102+
Cols(cols...).
103+
Update(variable)
94104
return count != 0, err
95105
}
96106

routers/api/v1/org/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,11 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
450450
if opt.Name == "" {
451451
opt.Name = ctx.PathParam("variablename")
452452
}
453-
if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil {
453+
454+
v.Name = opt.Name
455+
v.Data = opt.Value
456+
457+
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
454458
if errors.Is(err, util.ErrInvalidArgument) {
455459
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
456460
} else {

routers/api/v1/repo/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ func (Action) UpdateVariable(ctx *context.APIContext) {
414414
if opt.Name == "" {
415415
opt.Name = ctx.PathParam("variablename")
416416
}
417-
if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil {
417+
418+
v.Name = opt.Name
419+
v.Data = opt.Value
420+
421+
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
418422
if errors.Is(err, util.ErrInvalidArgument) {
419423
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
420424
} else {

routers/api/v1/user/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ func UpdateVariable(ctx *context.APIContext) {
212212
if opt.Name == "" {
213213
opt.Name = ctx.PathParam("variablename")
214214
}
215-
if _, err := actions_service.UpdateVariable(ctx, v.ID, opt.Name, opt.Value); err != nil {
215+
216+
v.Name = opt.Name
217+
v.Data = opt.Value
218+
219+
if _, err := actions_service.UpdateVariableNameData(ctx, v); err != nil {
216220
if errors.Is(err, util.ErrInvalidArgument) {
217221
ctx.Error(http.StatusBadRequest, "UpdateVariable", err)
218222
} else {

routers/web/repo/setting/variables.go

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)