diff options
author | 6543 <6543@obermui.de> | 2024-02-23 03:18:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-23 02:18:33 +0000 |
commit | 7fbdb60fc1152acc9a040dc04b1b0f5a3475b081 (patch) | |
tree | 9976167d5b05ad1677606bce409d92e83d17a4de /modules | |
parent | b748d62b461f9f23823f8772bc708b44b15a23a7 (diff) | |
download | gitea-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 'modules')
-rw-r--r-- | modules/context/repo.go | 3 | ||||
-rw-r--r-- | modules/optional/option_test.go | 5 | ||||
-rw-r--r-- | modules/util/util.go | 18 |
3 files changed, 22 insertions, 4 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index 3ff7209c4c..8508d46cf4 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -27,6 +27,7 @@ import ( "code.gitea.io/gitea/modules/gitrepo" code_indexer "code.gitea.io/gitea/modules/indexer/code" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/optional" repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -671,7 +672,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { branchOpts := git_model.FindBranchOptions{ RepoID: ctx.Repo.Repository.ID, - IsDeletedBranch: util.OptionalBoolFalse, + IsDeletedBranch: optional.Some(false), ListOptions: db.ListOptionsAll, } branchesTotal, err := db.Count[git_model.Branch](ctx, branchOpts) diff --git a/modules/optional/option_test.go b/modules/optional/option_test.go index 7ec345b6ba..bfc4577dbe 100644 --- a/modules/optional/option_test.go +++ b/modules/optional/option_test.go @@ -6,8 +6,6 @@ package optional import ( "testing" - "code.gitea.io/gitea/modules/util" - "github.com/stretchr/testify/assert" ) @@ -30,7 +28,8 @@ func TestOption(t *testing.T) { var ptr *int assert.False(t, FromPtr(ptr).Has()) - opt1 := FromPtr(util.ToPointer(1)) + int1 := 1 + opt1 := FromPtr(&int1) assert.True(t, opt1.Has()) assert.Equal(t, int(1), opt1.Value()) diff --git a/modules/util/util.go b/modules/util/util.go index 0e5c6a4e64..28b549f405 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -11,6 +11,8 @@ import ( "strconv" "strings" + "code.gitea.io/gitea/modules/optional" + "golang.org/x/text/cases" "golang.org/x/text/language" ) @@ -42,6 +44,22 @@ func (o OptionalBool) IsNone() bool { return o == OptionalBoolNone } +// ToGeneric converts OptionalBool to optional.Option[bool] +func (o OptionalBool) ToGeneric() optional.Option[bool] { + if o.IsNone() { + return optional.None[bool]() + } + return optional.Some[bool](o.IsTrue()) +} + +// OptionalBoolFromGeneric converts optional.Option[bool] to OptionalBool +func OptionalBoolFromGeneric(o optional.Option[bool]) OptionalBool { + if o.Has() { + return OptionalBoolOf(o.Value()) + } + return OptionalBoolNone +} + // OptionalBoolOf get the corresponding OptionalBool of a bool func OptionalBoolOf(b bool) OptionalBool { if b { |