diff options
author | 6543 <6543@obermui.de> | 2024-02-28 06:39:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-28 13:39:12 +0800 |
commit | 274c0aea2e88db9bc41690c90e13e8aedf6193d4 (patch) | |
tree | aed6cf5f0c72cc2b04e5cb3b0d758fb5aa95d68e /services/context | |
parent | db545b208b4bd3d1961c519da66ee2b4421afa5c (diff) | |
download | gitea-274c0aea2e88db9bc41690c90e13e8aedf6193d4.tar.gz gitea-274c0aea2e88db9bc41690c90e13e8aedf6193d4.zip |
Let ctx.FormOptionalBool() return optional.Option[bool] (#29461)
just some refactoring bits towards replacing **util.OptionalBool** with
**optional.Option[bool]**
Diffstat (limited to 'services/context')
-rw-r--r-- | services/context/base.go | 12 | ||||
-rw-r--r-- | services/context/repo.go | 2 |
2 files changed, 7 insertions, 7 deletions
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 { |