mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	[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
This commit is contained in:
		@@ -27,6 +27,7 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/modules/setting"
 | 
			
		||||
	"code.gitea.io/gitea/modules/templates"
 | 
			
		||||
	"code.gitea.io/gitea/modules/translation"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
	"code.gitea.io/gitea/modules/web/middleware"
 | 
			
		||||
	"code.gitea.io/gitea/services/auth"
 | 
			
		||||
 | 
			
		||||
@@ -319,6 +320,11 @@ func (ctx *Context) QueryBool(key string, defaults ...bool) bool {
 | 
			
		||||
	return (*Forms)(ctx.Req).MustBool(key, defaults...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// QueryOptionalBool returns request form as OptionalBool with default
 | 
			
		||||
func (ctx *Context) QueryOptionalBool(key string, defaults ...util.OptionalBool) util.OptionalBool {
 | 
			
		||||
	return (*Forms)(ctx.Req).MustOptionalBool(key, defaults...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// HandleText handles HTTP status code
 | 
			
		||||
func (ctx *Context) HandleText(status int, title string) {
 | 
			
		||||
	if (status/100 == 4) || (status/100 == 5) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user