Added instance-level variables (#28115)

This PR adds instance-level variables, and so closes #27726



![gitea_instance_variables_1](ad409cd4-ce36-4c84-a764-34451b0fb63a)

![gitea_instance_variables_2](426f0965-dec6-4560-948c-067cdeddd720)

![gitea_instance_variables_3](cf1d7776-4938-4825-922e-cbbbf28a5f33)
This commit is contained in:
Jean-Baptiste Gomond 2023-12-25 08:28:59 +01:00 committed by GitHub
parent 0407a402bb
commit d0f24ff4ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 18 deletions

View file

@ -31,8 +31,8 @@ func init() {
}
func (v *ActionVariable) Validate() error {
if v.OwnerID == 0 && v.RepoID == 0 {
return errors.New("the variable is not bound to any scope")
if v.OwnerID != 0 && v.RepoID != 0 {
return errors.New("a variable should not be bound to an owner and a repository at the same time")
}
return nil
}
@ -58,12 +58,8 @@ type FindVariablesOpts struct {
func (opts FindVariablesOpts) ToConds() builder.Cond {
cond := builder.NewCond()
if opts.OwnerID > 0 {
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
}
if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
}
cond = cond.And(builder.Eq{"owner_id": opts.OwnerID})
cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
return cond
}