diff options
author | 6543 <6543@obermui.de> | 2021-06-17 10:58:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-17 10:58:10 +0200 |
commit | 6ad5d0a3062966515730aa1f8d62db5d2a7704ee (patch) | |
tree | 711b5814e4eb096e88b6f2ccbe597b0b00029275 /modules/context/form.go | |
parent | c9d053f0caa14e6fec4d04c009c79c9a0940c450 (diff) | |
download | gitea-6ad5d0a3062966515730aa1f8d62db5d2a7704ee.tar.gz gitea-6ad5d0a3062966515730aa1f8d62db5d2a7704ee.zip |
[API] ListReleases add filter for draft and pre-releases (#16175)
* invent ctx.QueryOptionalBool
* [API] ListReleases add draft and pre-release filter
* Add X-Total-Count header
* Add a release to fixtures
* Add TEST for API ListReleases
Diffstat (limited to 'modules/context/form.go')
-rw-r--r-- | modules/context/form.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/context/form.go b/modules/context/form.go index c7b76c614c..e3afad0a90 100644 --- a/modules/context/form.go +++ b/modules/context/form.go @@ -13,6 +13,7 @@ import ( "text/template" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/util" ) // Forms a new enhancement of http.Request @@ -225,3 +226,16 @@ func (f *Forms) MustBool(key string, defaults ...bool) bool { } return v } + +// MustOptionalBool returns request form as OptionalBool with default +func (f *Forms) MustOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool { + value := (*http.Request)(f).FormValue(key) + if len(value) == 0 { + return util.OptionalBoolNone + } + v, err := strconv.ParseBool((*http.Request)(f).FormValue(key)) + if len(defaults) > 0 && err != nil { + return defaults[0] + } + return util.OptionalBoolOf(v) +} |