@@ -58,13 +58,23 @@ func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data strin
5858
5959type 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
6667func (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
0 commit comments