mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 00:38:36 +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:
@@ -140,7 +140,7 @@ func MustAllowPulls(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption util.OptionalBool) {
|
||||
func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption optional.Option[bool]) {
|
||||
var err error
|
||||
viewType := ctx.FormString("type")
|
||||
sortType := ctx.FormString("sort")
|
||||
@@ -241,18 +241,18 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
}
|
||||
}
|
||||
|
||||
var isShowClosed util.OptionalBool
|
||||
var isShowClosed optional.Option[bool]
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isShowClosed = util.OptionalBoolTrue
|
||||
isShowClosed = optional.Some(true)
|
||||
case "all":
|
||||
isShowClosed = util.OptionalBoolNone
|
||||
isShowClosed = optional.None[bool]()
|
||||
default:
|
||||
isShowClosed = util.OptionalBoolFalse
|
||||
isShowClosed = optional.Some(false)
|
||||
}
|
||||
// if there are closed issues and no open issues, default to showing all issues
|
||||
if len(ctx.FormString("state")) == 0 && issueStats.OpenCount == 0 && issueStats.ClosedCount != 0 {
|
||||
isShowClosed = util.OptionalBoolNone
|
||||
isShowClosed = optional.None[bool]()
|
||||
}
|
||||
|
||||
if repo.IsTimetrackerEnabled(ctx) {
|
||||
@@ -272,10 +272,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
}
|
||||
|
||||
var total int
|
||||
switch isShowClosed {
|
||||
case util.OptionalBoolTrue:
|
||||
switch {
|
||||
case isShowClosed.Value():
|
||||
total = int(issueStats.ClosedCount)
|
||||
case util.OptionalBoolNone:
|
||||
case !isShowClosed.Has():
|
||||
total = int(issueStats.OpenCount + issueStats.ClosedCount)
|
||||
default:
|
||||
total = int(issueStats.OpenCount)
|
||||
@@ -431,7 +431,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
return
|
||||
}
|
||||
|
||||
pinned, err := issues_model.GetPinnedIssues(ctx, repo.ID, isPullOption.IsTrue())
|
||||
pinned, err := issues_model.GetPinnedIssues(ctx, repo.ID, isPullOption.Value())
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPinnedIssues", err)
|
||||
return
|
||||
@@ -461,10 +461,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
|
||||
ctx.Data["AssigneeID"] = assigneeID
|
||||
ctx.Data["PosterID"] = posterID
|
||||
ctx.Data["Keyword"] = keyword
|
||||
switch isShowClosed {
|
||||
case util.OptionalBoolTrue:
|
||||
switch {
|
||||
case isShowClosed.Value():
|
||||
ctx.Data["State"] = "closed"
|
||||
case util.OptionalBoolNone:
|
||||
case !isShowClosed.Has():
|
||||
ctx.Data["State"] = "all"
|
||||
default:
|
||||
ctx.Data["State"] = "open"
|
||||
@@ -513,7 +513,7 @@ func Issues(ctx *context.Context) {
|
||||
ctx.Data["NewIssueChooseTemplate"] = issue_service.HasTemplatesOrContactLinks(ctx.Repo.Repository, ctx.Repo.GitRepo)
|
||||
}
|
||||
|
||||
issues(ctx, ctx.FormInt64("milestone"), ctx.FormInt64("project"), util.OptionalBoolOf(isPullList))
|
||||
issues(ctx, ctx.FormInt64("milestone"), ctx.FormInt64("project"), optional.Some(isPullList))
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
@@ -555,7 +555,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
|
||||
var err error
|
||||
ctx.Data["OpenMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
|
||||
RepoID: repo.ID,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
IsClosed: optional.Some(false),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetMilestones", err)
|
||||
@@ -563,7 +563,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
|
||||
}
|
||||
ctx.Data["ClosedMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
|
||||
RepoID: repo.ID,
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
IsClosed: optional.Some(true),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetMilestones", err)
|
||||
@@ -591,7 +591,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
||||
projects, err := db.Find[project_model.Project](ctx, project_model.SearchOptions{
|
||||
ListOptions: db.ListOptionsAll,
|
||||
RepoID: repo.ID,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
IsClosed: optional.Some(false),
|
||||
Type: project_model.TypeRepository,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -601,7 +601,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
||||
projects2, err := db.Find[project_model.Project](ctx, project_model.SearchOptions{
|
||||
ListOptions: db.ListOptionsAll,
|
||||
OwnerID: repo.OwnerID,
|
||||
IsClosed: util.OptionalBoolFalse,
|
||||
IsClosed: optional.Some(false),
|
||||
Type: repoOwnerType,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -614,7 +614,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
||||
projects, err = db.Find[project_model.Project](ctx, project_model.SearchOptions{
|
||||
ListOptions: db.ListOptionsAll,
|
||||
RepoID: repo.ID,
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
IsClosed: optional.Some(true),
|
||||
Type: project_model.TypeRepository,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -624,7 +624,7 @@ func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) {
|
||||
projects2, err = db.Find[project_model.Project](ctx, project_model.SearchOptions{
|
||||
ListOptions: db.ListOptionsAll,
|
||||
OwnerID: repo.OwnerID,
|
||||
IsClosed: util.OptionalBoolTrue,
|
||||
IsClosed: optional.Some(true),
|
||||
Type: repoOwnerType,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -2502,14 +2502,14 @@ func SearchIssues(ctx *context.Context) {
|
||||
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 (
|
||||
@@ -2584,14 +2584,12 @@ func SearchIssues(ctx *context.Context) {
|
||||
keyword = ""
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
var includedAnyLabels []int64
|
||||
@@ -2726,14 +2724,14 @@ func ListIssues(ctx *context.Context) {
|
||||
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")
|
||||
@@ -2785,14 +2783,12 @@ func ListIssues(ctx *context.Context) {
|
||||
projectID = &v
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// FIXME: we should be more efficient here
|
||||
|
Reference in New Issue
Block a user