summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorJean-Baptiste Gomond <dev@jbgomond.com>2023-12-25 08:28:59 +0100
committerGitHub <noreply@github.com>2023-12-25 08:28:59 +0100
commitd0f24ff4cad05c1145afeca791e7d02fe146d46a (patch)
treee1da84ade8f14914c7b37c3d29bc917a3cfb7c63 /models
parentRevert "improve possible performance bottleneck (#28547)" (#28593) (diff)
downloadforgejo-d0f24ff4cad05c1145afeca791e7d02fe146d46a.tar.xz
forgejo-d0f24ff4cad05c1145afeca791e7d02fe146d46a.zip
Added instance-level variables (#28115)
This PR adds instance-level variables, and so closes #27726 ![gitea_instance_variables_1](https://github.com/go-gitea/gitea/assets/8344487/ad409cd4-ce36-4c84-a764-34451b0fb63a) ![gitea_instance_variables_2](https://github.com/go-gitea/gitea/assets/8344487/426f0965-dec6-4560-948c-067cdeddd720) ![gitea_instance_variables_3](https://github.com/go-gitea/gitea/assets/8344487/cf1d7776-4938-4825-922e-cbbbf28a5f33)
Diffstat (limited to 'models')
-rw-r--r--models/actions/variable.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/models/actions/variable.go b/models/actions/variable.go
index 030b7bae92..12717e0ae4 100644
--- a/models/actions/variable.go
+++ b/models/actions/variable.go
@@ -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
}