mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07:19 +00:00
remove util.OptionalBool and related functions (#29513)
and migrate affected code _last refactoring bits to replace **util.OptionalBool** with **optional.Option[bool]**_
This commit is contained in:
@ -23,7 +23,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
@ -123,14 +122,14 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
var isClosed util.OptionalBool
|
||||
var isClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = util.OptionalBoolTrue
|
||||
isClosed = optional.Some(true)
|
||||
case "all":
|
||||
isClosed = util.OptionalBoolNone
|
||||
isClosed = optional.None[bool]()
|
||||
default:
|
||||
isClosed = util.OptionalBoolFalse
|
||||
isClosed = optional.Some(false)
|
||||
}
|
||||
|
||||
var (
|
||||
@ -205,14 +204,14 @@ func SearchIssues(ctx *context.APIContext) {
|
||||
keyword = ""
|
||||
}
|
||||
|
||||
var isPull util.OptionalBool
|
||||
var isPull optional.Option[bool]
|
||||
switch ctx.FormString("type") {
|
||||
case "pulls":
|
||||
isPull = util.OptionalBoolTrue
|
||||
isPull = optional.Some(true)
|
||||
case "issues":
|
||||
isPull = util.OptionalBoolFalse
|
||||
isPull = optional.Some(false)
|
||||
default:
|
||||
isPull = util.OptionalBoolNone
|
||||
isPull = optional.None[bool]()
|
||||
}
|
||||
|
||||
var includedAnyLabels []int64
|
||||
@ -397,14 +396,14 @@ func ListIssues(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
var isClosed util.OptionalBool
|
||||
var isClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = util.OptionalBoolTrue
|
||||
isClosed = optional.Some(true)
|
||||
case "all":
|
||||
isClosed = util.OptionalBoolNone
|
||||
isClosed = optional.None[bool]()
|
||||
default:
|
||||
isClosed = util.OptionalBoolFalse
|
||||
isClosed = optional.Some(false)
|
||||
}
|
||||
|
||||
keyword := ctx.FormTrim("q")
|
||||
@ -453,31 +452,29 @@ func ListIssues(ctx *context.APIContext) {
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
var isPull util.OptionalBool
|
||||
isPull := optional.None[bool]()
|
||||
switch ctx.FormString("type") {
|
||||
case "pulls":
|
||||
isPull = util.OptionalBoolTrue
|
||||
isPull = optional.Some(true)
|
||||
case "issues":
|
||||
isPull = util.OptionalBoolFalse
|
||||
default:
|
||||
isPull = util.OptionalBoolNone
|
||||
isPull = optional.Some(false)
|
||||
}
|
||||
|
||||
if isPull != util.OptionalBoolNone && !ctx.Repo.CanReadIssuesOrPulls(isPull.IsTrue()) {
|
||||
if isPull.Has() && !ctx.Repo.CanReadIssuesOrPulls(isPull.Value()) {
|
||||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
|
||||
if isPull == util.OptionalBoolNone {
|
||||
if !isPull.Has() {
|
||||
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues)
|
||||
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests)
|
||||
if !canReadIssues && !canReadPulls {
|
||||
ctx.NotFound()
|
||||
return
|
||||
} else if !canReadIssues {
|
||||
isPull = util.OptionalBoolTrue
|
||||
isPull = optional.Some(true)
|
||||
} else if !canReadPulls {
|
||||
isPull = util.OptionalBoolFalse
|
||||
isPull = optional.Some(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user