aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2024-02-23 03:18:33 +0100
committerGitHub <noreply@github.com>2024-02-23 02:18:33 +0000
commit7fbdb60fc1152acc9a040dc04b1b0f5a3475b081 (patch)
tree9976167d5b05ad1677606bce409d92e83d17a4de /models
parentb748d62b461f9f23823f8772bc708b44b15a23a7 (diff)
downloadgitea-7fbdb60fc1152acc9a040dc04b1b0f5a3475b081.tar.gz
gitea-7fbdb60fc1152acc9a040dc04b1b0f5a3475b081.zip
Start to migrate from `util.OptionalBool` to `optional.Option[bool]` (#29329)
just create transition helper and migrate two structs
Diffstat (limited to 'models')
-rw-r--r--models/git/branch_list.go10
-rw-r--r--models/git/branch_test.go4
-rw-r--r--models/git/protected_branch_list.go4
-rw-r--r--models/user/user.go25
4 files changed, 22 insertions, 21 deletions
diff --git a/models/git/branch_list.go b/models/git/branch_list.go
index 0e8d28038a..8319e5ecd0 100644
--- a/models/git/branch_list.go
+++ b/models/git/branch_list.go
@@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
- "code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/modules/optional"
"xorm.io/builder"
)
@@ -67,7 +67,7 @@ type FindBranchOptions struct {
db.ListOptions
RepoID int64
ExcludeBranchNames []string
- IsDeletedBranch util.OptionalBool
+ IsDeletedBranch optional.Option[bool]
OrderBy string
Keyword string
}
@@ -81,8 +81,8 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
if len(opts.ExcludeBranchNames) > 0 {
cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames))
}
- if !opts.IsDeletedBranch.IsNone() {
- cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
+ if opts.IsDeletedBranch.Has() {
+ cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()})
}
if opts.Keyword != "" {
cond = cond.And(builder.Like{"name", opts.Keyword})
@@ -92,7 +92,7 @@ func (opts FindBranchOptions) ToConds() builder.Cond {
func (opts FindBranchOptions) ToOrders() string {
orderBy := opts.OrderBy
- if !opts.IsDeletedBranch.IsFalse() { // if deleted branch included, put them at the end
+ if opts.IsDeletedBranch.ValueOrDefault(true) { // if deleted branch included, put them at the end
if orderBy != "" {
orderBy += ", "
}
diff --git a/models/git/branch_test.go b/models/git/branch_test.go
index fd5d6519e9..b8ea663e81 100644
--- a/models/git/branch_test.go
+++ b/models/git/branch_test.go
@@ -13,7 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/modules/optional"
"github.com/stretchr/testify/assert"
)
@@ -50,7 +50,7 @@ func TestGetDeletedBranches(t *testing.T) {
branches, err := db.Find[git_model.Branch](db.DefaultContext, git_model.FindBranchOptions{
ListOptions: db.ListOptionsAll,
RepoID: repo.ID,
- IsDeletedBranch: util.OptionalBoolTrue,
+ IsDeletedBranch: optional.Some(true),
})
assert.NoError(t, err)
assert.Len(t, branches, 2)
diff --git a/models/git/protected_branch_list.go b/models/git/protected_branch_list.go
index eeb307e245..613333a5a2 100644
--- a/models/git/protected_branch_list.go
+++ b/models/git/protected_branch_list.go
@@ -8,7 +8,7 @@ import (
"sort"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/modules/optional"
"github.com/gobwas/glob"
)
@@ -56,7 +56,7 @@ func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string)
Page: page,
},
RepoID: repoID,
- IsDeletedBranch: util.OptionalBoolFalse,
+ IsDeletedBranch: optional.Some(false),
})
if err != nil {
return nil, err
diff --git a/models/user/user.go b/models/user/user.go
index f31dfb76bb..e92bbd4d0b 100644
--- a/models/user/user.go
+++ b/models/user/user.go
@@ -25,6 +25,7 @@ import (
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
@@ -573,14 +574,14 @@ func IsUsableUsername(name string) error {
// CreateUserOverwriteOptions are an optional options who overwrite system defaults on user creation
type CreateUserOverwriteOptions struct {
- KeepEmailPrivate util.OptionalBool
+ KeepEmailPrivate optional.Option[bool]
Visibility *structs.VisibleType
- AllowCreateOrganization util.OptionalBool
+ AllowCreateOrganization optional.Option[bool]
EmailNotificationsPreference *string
MaxRepoCreation *int
Theme *string
- IsRestricted util.OptionalBool
- IsActive util.OptionalBool
+ IsRestricted optional.Option[bool]
+ IsActive optional.Option[bool]
}
// CreateUser creates record of a new user.
@@ -607,14 +608,14 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
// overwrite defaults if set
if len(overwriteDefault) != 0 && overwriteDefault[0] != nil {
overwrite := overwriteDefault[0]
- if !overwrite.KeepEmailPrivate.IsNone() {
- u.KeepEmailPrivate = overwrite.KeepEmailPrivate.IsTrue()
+ if overwrite.KeepEmailPrivate.Has() {
+ u.KeepEmailPrivate = overwrite.KeepEmailPrivate.Value()
}
if overwrite.Visibility != nil {
u.Visibility = *overwrite.Visibility
}
- if !overwrite.AllowCreateOrganization.IsNone() {
- u.AllowCreateOrganization = overwrite.AllowCreateOrganization.IsTrue()
+ if overwrite.AllowCreateOrganization.Has() {
+ u.AllowCreateOrganization = overwrite.AllowCreateOrganization.Value()
}
if overwrite.EmailNotificationsPreference != nil {
u.EmailNotificationsPreference = *overwrite.EmailNotificationsPreference
@@ -625,11 +626,11 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
if overwrite.Theme != nil {
u.Theme = *overwrite.Theme
}
- if !overwrite.IsRestricted.IsNone() {
- u.IsRestricted = overwrite.IsRestricted.IsTrue()
+ if overwrite.IsRestricted.Has() {
+ u.IsRestricted = overwrite.IsRestricted.Value()
}
- if !overwrite.IsActive.IsNone() {
- u.IsActive = overwrite.IsActive.IsTrue()
+ if overwrite.IsActive.Has() {
+ u.IsActive = overwrite.IsActive.Value()
}
}