From 274c0aea2e88db9bc41690c90e13e8aedf6193d4 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 28 Feb 2024 06:39:12 +0100 Subject: Let ctx.FormOptionalBool() return optional.Option[bool] (#29461) just some refactoring bits towards replacing **util.OptionalBool** with **optional.Option[bool]** --- services/context/base.go | 12 ++++++------ services/context/repo.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'services/context') diff --git a/services/context/base.go b/services/context/base.go index ddd04f4767..c4aa467ff4 100644 --- a/services/context/base.go +++ b/services/context/base.go @@ -17,8 +17,8 @@ import ( "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/translation" - "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web/middleware" "github.com/go-chi/chi/v5" @@ -207,17 +207,17 @@ func (b *Base) FormBool(key string) bool { return v } -// FormOptionalBool returns an OptionalBoolTrue or OptionalBoolFalse if the value -// for the provided key exists in the form else it returns OptionalBoolNone -func (b *Base) FormOptionalBool(key string) util.OptionalBool { +// FormOptionalBool returns an optional.Some(true) or optional.Some(false) if the value +// for the provided key exists in the form else it returns optional.None[bool]() +func (b *Base) FormOptionalBool(key string) optional.Option[bool] { value := b.Req.FormValue(key) if len(value) == 0 { - return util.OptionalBoolNone + return optional.None[bool]() } s := b.Req.FormValue(key) v, _ := strconv.ParseBool(s) v = v || strings.EqualFold(s, "on") - return util.OptionalBoolOf(v) + return optional.Some(v) } func (b *Base) SetFormString(key, value string) { diff --git a/services/context/repo.go b/services/context/repo.go index a73d09ee21..d6a68c0c1a 100644 --- a/services/context/repo.go +++ b/services/context/repo.go @@ -546,7 +546,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.Data["NumTags"], err = db.Count[repo_model.Release](ctx, repo_model.FindReleasesOptions{ IncludeDrafts: true, IncludeTags: true, - HasSha1: util.OptionalBoolTrue, // only draft releases which are created with existing tags + HasSha1: optional.Some(true), // only draft releases which are created with existing tags RepoID: ctx.Repo.Repository.ID, }) if err != nil { -- cgit v1.2.3