remove util.OptionalBool and related functions (#29513)

and migrate affected code

_last refactoring bits to replace **util.OptionalBool** with
**optional.Option[bool]**_
pull/29532/head^2
6543 9 months ago committed by GitHub
parent 3f081d4b54
commit a3f05d0d98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      models/actions/runner.go
  2. 9
      models/auth/source.go
  3. 15
      models/issues/comment.go
  4. 25
      models/issues/issue_search.go
  5. 8
      models/issues/issue_stats.go
  6. 3
      models/issues/label.go
  7. 3
      models/issues/milestone.go
  8. 8
      models/issues/milestone_list.go
  9. 24
      models/issues/milestone_test.go
  10. 8
      models/issues/review_list.go
  11. 9
      models/issues/tracked_time.go
  12. 8
      models/issues/tracked_time_test.go
  13. 2
      models/packages/nuget/search.go
  14. 25
      models/packages/package_version.go
  15. 10
      models/project/project.go
  16. 7
      models/repo/repo.go
  17. 6
      models/repo/repo_test.go
  18. 8
      models/user/user.go
  19. 7
      models/webhook/webhook.go
  20. 8
      models/webhook/webhook_system.go
  21. 6
      models/webhook/webhook_test.go
  22. 8
      modules/indexer/issues/bleve/bleve.go
  23. 3
      modules/indexer/issues/db/options.go
  24. 8
      modules/indexer/issues/elasticsearch/elasticsearch.go
  25. 10
      modules/indexer/issues/indexer_test.go
  26. 6
      modules/indexer/issues/internal/model.go
  27. 10
      modules/indexer/issues/internal/tests/tests.go
  28. 8
      modules/indexer/issues/meilisearch/meilisearch.go
  29. 51
      modules/util/util.go
  30. 3
      routers/api/packages/cargo/cargo.go
  31. 5
      routers/api/packages/chef/chef.go
  32. 3
      routers/api/packages/composer/composer.go
  33. 3
      routers/api/packages/goproxy/goproxy.go
  34. 5
      routers/api/packages/helm/helm.go
  35. 7
      routers/api/packages/npm/npm.go
  36. 11
      routers/api/packages/nuget/nuget.go
  37. 5
      routers/api/packages/rubygems/rubygems.go
  38. 3
      routers/api/packages/swift/swift.go
  39. 3
      routers/api/v1/admin/hooks.go
  40. 4
      routers/api/v1/packages/package.go
  41. 41
      routers/api/v1/repo/issue.go
  42. 10
      routers/api/v1/repo/issue_comment.go
  43. 6
      routers/api/v1/repo/milestone.go
  44. 4
      routers/web/admin/hooks.go
  45. 4
      routers/web/admin/packages.go
  46. 4
      routers/web/admin/users.go
  47. 8
      routers/web/auth/auth.go
  48. 8
      routers/web/org/projects.go
  49. 4
      routers/web/repo/actions/actions.go
  50. 3
      routers/web/repo/branch.go
  51. 72
      routers/web/repo/issue.go
  52. 6
      routers/web/repo/milestone.go
  53. 4
      routers/web/repo/packages.go
  54. 6
      routers/web/repo/projects.go
  55. 4
      routers/web/shared/packages/packages.go
  56. 3
      routers/web/shared/user/header.go
  57. 15
      routers/web/user/home.go
  58. 19
      routers/web/user/notification.go
  59. 11
      routers/web/user/package.go
  60. 4
      routers/web/user/setting/security/security.go
  61. 4
      services/auth/signin.go
  62. 4
      services/auth/source/oauth2/init.go
  63. 4
      services/auth/source/oauth2/providers.go
  64. 3
      services/auth/sspi.go
  65. 8
      services/migrations/gitea_uploader_test.go
  66. 4
      services/packages/cleanup/cleanup.go
  67. 6
      services/packages/container/cleanup.go
  68. 6
      services/packages/packages.go
  69. 8
      services/pull/review.go
  70. 5
      services/repository/branch.go
  71. 7
      services/webhook/webhook.go

@ -13,6 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/shared/types" "code.gitea.io/gitea/models/shared/types"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -159,7 +160,7 @@ type FindRunnerOptions struct {
OwnerID int64 OwnerID int64
Sort string Sort string
Filter string Filter string
IsOnline util.OptionalBool IsOnline optional.Option[bool]
WithAvailable bool // not only runners belong to, but also runners can be used WithAvailable bool // not only runners belong to, but also runners can be used
} }
@ -186,10 +187,12 @@ func (opts FindRunnerOptions) ToConds() builder.Cond {
cond = cond.And(builder.Like{"name", opts.Filter}) cond = cond.And(builder.Like{"name", opts.Filter})
} }
if opts.IsOnline.IsTrue() { if opts.IsOnline.Has() {
cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()}) if opts.IsOnline.Value() {
} else if opts.IsOnline.IsFalse() { cond = cond.And(builder.Gt{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()}) } else {
cond = cond.And(builder.Lte{"last_online": time.Now().Add(-RunnerOfflineTime).Unix()})
}
} }
return cond return cond
} }

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -243,14 +244,14 @@ func CreateSource(ctx context.Context, source *Source) error {
type FindSourcesOptions struct { type FindSourcesOptions struct {
db.ListOptions db.ListOptions
IsActive util.OptionalBool IsActive optional.Option[bool]
LoginType Type LoginType Type
} }
func (opts FindSourcesOptions) ToConds() builder.Cond { func (opts FindSourcesOptions) ToConds() builder.Cond {
conds := builder.NewCond() conds := builder.NewCond()
if !opts.IsActive.IsNone() { if opts.IsActive.Has() {
conds = conds.And(builder.Eq{"is_active": opts.IsActive.IsTrue()}) conds = conds.And(builder.Eq{"is_active": opts.IsActive.Value()})
} }
if opts.LoginType != NoType { if opts.LoginType != NoType {
conds = conds.And(builder.Eq{"`type`": opts.LoginType}) conds = conds.And(builder.Eq{"`type`": opts.LoginType})
@ -262,7 +263,7 @@ func (opts FindSourcesOptions) ToConds() builder.Cond {
// source of type LoginSSPI // source of type LoginSSPI
func IsSSPIEnabled(ctx context.Context) bool { func IsSSPIEnabled(ctx context.Context) bool {
exist, err := db.Exist[Source](ctx, FindSourcesOptions{ exist, err := db.Exist[Source](ctx, FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
LoginType: SSPI, LoginType: SSPI,
}.ToConds()) }.ToConds())
if err != nil { if err != nil {

@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/references" "code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -1036,8 +1037,8 @@ type FindCommentsOptions struct {
TreePath string TreePath string
Type CommentType Type CommentType
IssueIDs []int64 IssueIDs []int64
Invalidated util.OptionalBool Invalidated optional.Option[bool]
IsPull util.OptionalBool IsPull optional.Option[bool]
} }
// ToConds implements FindOptions interface // ToConds implements FindOptions interface
@ -1069,11 +1070,11 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
if len(opts.TreePath) > 0 { if len(opts.TreePath) > 0 {
cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath}) cond = cond.And(builder.Eq{"comment.tree_path": opts.TreePath})
} }
if !opts.Invalidated.IsNone() { if opts.Invalidated.Has() {
cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.IsTrue()}) cond = cond.And(builder.Eq{"comment.invalidated": opts.Invalidated.Value()})
} }
if opts.IsPull != util.OptionalBoolNone { if opts.IsPull.Has() {
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.IsTrue()}) cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull.Value()})
} }
return cond return cond
} }
@ -1082,7 +1083,7 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) { func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
comments := make([]*Comment, 0, 10) comments := make([]*Comment, 0, 10)
sess := db.GetEngine(ctx).Where(opts.ToConds()) sess := db.GetEngine(ctx).Where(opts.ToConds())
if opts.RepoID > 0 || opts.IsPull != util.OptionalBoolNone { if opts.RepoID > 0 || opts.IsPull.Has() {
sess.Join("INNER", "issue", "issue.id = comment.issue_id") sess.Join("INNER", "issue", "issue.id = comment.issue_id")
} }

@ -13,7 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"xorm.io/builder" "xorm.io/builder"
"xorm.io/xorm" "xorm.io/xorm"
@ -34,8 +34,8 @@ type IssuesOptions struct { //nolint
MilestoneIDs []int64 MilestoneIDs []int64
ProjectID int64 ProjectID int64
ProjectBoardID int64 ProjectBoardID int64
IsClosed util.OptionalBool IsClosed optional.Option[bool]
IsPull util.OptionalBool IsPull optional.Option[bool]
LabelIDs []int64 LabelIDs []int64
IncludedLabelNames []string IncludedLabelNames []string
ExcludedLabelNames []string ExcludedLabelNames []string
@ -46,7 +46,7 @@ type IssuesOptions struct { //nolint
UpdatedBeforeUnix int64 UpdatedBeforeUnix int64
// prioritize issues from this repo // prioritize issues from this repo
PriorityRepoID int64 PriorityRepoID int64
IsArchived util.OptionalBool IsArchived optional.Option[bool]
Org *organization.Organization // issues permission scope Org *organization.Organization // issues permission scope
Team *organization.Team // issues permission scope Team *organization.Team // issues permission scope
User *user_model.User // issues permission scope User *user_model.User // issues permission scope
@ -217,8 +217,8 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
applyRepoConditions(sess, opts) applyRepoConditions(sess, opts)
if !opts.IsClosed.IsNone() { if opts.IsClosed.Has() {
sess.And("issue.is_closed=?", opts.IsClosed.IsTrue()) sess.And("issue.is_closed=?", opts.IsClosed.Value())
} }
if opts.AssigneeID > 0 { if opts.AssigneeID > 0 {
@ -260,21 +260,18 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
applyProjectBoardCondition(sess, opts) applyProjectBoardCondition(sess, opts)
switch opts.IsPull { if opts.IsPull.Has() {
case util.OptionalBoolTrue: sess.And("issue.is_pull=?", opts.IsPull.Value())
sess.And("issue.is_pull=?", true)
case util.OptionalBoolFalse:
sess.And("issue.is_pull=?", false)
} }
if opts.IsArchived != util.OptionalBoolNone { if opts.IsArchived.Has() {
sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.IsTrue()}) sess.And(builder.Eq{"repository.is_archived": opts.IsArchived.Value()})
} }
applyLabelsCondition(sess, opts) applyLabelsCondition(sess, opts)
if opts.User != nil { if opts.User != nil {
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.IsTrue())) sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value()))
} }
return sess return sess

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/util"
"xorm.io/builder" "xorm.io/builder"
"xorm.io/xorm" "xorm.io/xorm"
@ -170,11 +169,8 @@ func applyIssuesOptions(sess *xorm.Session, opts *IssuesOptions, issueIDs []int6
applyReviewedCondition(sess, opts.ReviewedID) applyReviewedCondition(sess, opts.ReviewedID)
} }
switch opts.IsPull { if opts.IsPull.Has() {
case util.OptionalBoolTrue: sess.And("issue.is_pull=?", opts.IsPull.Value())
sess.And("issue.is_pull=?", true)
case util.OptionalBoolFalse:
sess.And("issue.is_pull=?", false)
} }
return sess return sess

@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/label" "code.gitea.io/gitea/modules/label"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -126,7 +127,7 @@ func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{ counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{
RepoIDs: []int64{repoID}, RepoIDs: []int64{repoID},
LabelIDs: []int64{labelID}, LabelIDs: []int64{labelID},
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}) })
for _, count := range counts { for _, count := range counts {

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/optional"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -302,7 +303,7 @@ func DeleteMilestoneByRepoID(ctx context.Context, repoID, id int64) error {
} }
numClosedMilestones, err := db.Count[Milestone](ctx, FindMilestoneOptions{ numClosedMilestones, err := db.Count[Milestone](ctx, FindMilestoneOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
if err != nil { if err != nil {
return err return err

@ -8,7 +8,7 @@ import (
"strings" "strings"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"xorm.io/builder" "xorm.io/builder"
) )
@ -28,7 +28,7 @@ func (milestones MilestoneList) getMilestoneIDs() []int64 {
type FindMilestoneOptions struct { type FindMilestoneOptions struct {
db.ListOptions db.ListOptions
RepoID int64 RepoID int64
IsClosed util.OptionalBool IsClosed optional.Option[bool]
Name string Name string
SortType string SortType string
RepoCond builder.Cond RepoCond builder.Cond
@ -40,8 +40,8 @@ func (opts FindMilestoneOptions) ToConds() builder.Cond {
if opts.RepoID != 0 { if opts.RepoID != 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
} }
if opts.IsClosed != util.OptionalBoolNone { if opts.IsClosed.Has() {
cond = cond.And(builder.Eq{"is_closed": opts.IsClosed.IsTrue()}) cond = cond.And(builder.Eq{"is_closed": opts.IsClosed.Value()})
} }
if opts.RepoCond != nil && opts.RepoCond.IsValid() { if opts.RepoCond != nil && opts.RepoCond.IsValid() {
cond = cond.And(builder.In("repo_id", builder.Select("id").From("repository").Where(opts.RepoCond))) cond = cond.And(builder.In("repo_id", builder.Select("id").From("repository").Where(opts.RepoCond)))

@ -11,10 +11,10 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -39,10 +39,10 @@ func TestGetMilestoneByRepoID(t *testing.T) {
func TestGetMilestonesByRepoID(t *testing.T) { func TestGetMilestonesByRepoID(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
test := func(repoID int64, state api.StateType) { test := func(repoID int64, state api.StateType) {
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch state { switch state {
case api.StateClosed, api.StateOpen: case api.StateClosed, api.StateOpen:
isClosed = util.OptionalBoolOf(state == api.StateClosed) isClosed = optional.Some(state == api.StateClosed)
} }
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
@ -84,7 +84,7 @@ func TestGetMilestonesByRepoID(t *testing.T) {
milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
RepoID: unittest.NonexistentID, RepoID: unittest.NonexistentID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, milestones, 0) assert.Len(t, milestones, 0)
@ -101,7 +101,7 @@ func TestGetMilestones(t *testing.T) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
SortType: sortType, SortType: sortType,
}) })
assert.NoError(t, err) assert.NoError(t, err)
@ -118,7 +118,7 @@ func TestGetMilestones(t *testing.T) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
Name: "", Name: "",
SortType: sortType, SortType: sortType,
}) })
@ -178,7 +178,7 @@ func TestCountRepoClosedMilestones(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
count, err := db.Count[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ count, err := db.Count[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
RepoID: repoID, RepoID: repoID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, repo.NumClosedMilestones, count) assert.EqualValues(t, repo.NumClosedMilestones, count)
@ -189,7 +189,7 @@ func TestCountRepoClosedMilestones(t *testing.T) {
count, err := db.Count[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ count, err := db.Count[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
RepoID: unittest.NonexistentID, RepoID: unittest.NonexistentID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 0, count) assert.EqualValues(t, 0, count)
@ -206,7 +206,7 @@ func TestCountMilestonesByRepoIDs(t *testing.T) {
openCounts, err := issues_model.CountMilestonesMap(db.DefaultContext, issues_model.FindMilestoneOptions{ openCounts, err := issues_model.CountMilestonesMap(db.DefaultContext, issues_model.FindMilestoneOptions{
RepoIDs: []int64{1, 2}, RepoIDs: []int64{1, 2},
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, repo1OpenCount, openCounts[1]) assert.EqualValues(t, repo1OpenCount, openCounts[1])
@ -215,7 +215,7 @@ func TestCountMilestonesByRepoIDs(t *testing.T) {
closedCounts, err := issues_model.CountMilestonesMap(db.DefaultContext, closedCounts, err := issues_model.CountMilestonesMap(db.DefaultContext,
issues_model.FindMilestoneOptions{ issues_model.FindMilestoneOptions{
RepoIDs: []int64{1, 2}, RepoIDs: []int64{1, 2},
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, repo1ClosedCount, closedCounts[1]) assert.EqualValues(t, repo1ClosedCount, closedCounts[1])
@ -234,7 +234,7 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoIDs: []int64{repo1.ID, repo2.ID}, RepoIDs: []int64{repo1.ID, repo2.ID},
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
SortType: sortType, SortType: sortType,
}) })
assert.NoError(t, err) assert.NoError(t, err)
@ -252,7 +252,7 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoIDs: []int64{repo1.ID, repo2.ID}, RepoIDs: []int64{repo1.ID, repo2.ID},
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
SortType: sortType, SortType: sortType,
}) })
assert.NoError(t, err) assert.NoError(t, err)

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"xorm.io/builder" "xorm.io/builder"
) )
@ -68,7 +68,7 @@ type FindReviewOptions struct {
IssueID int64 IssueID int64
ReviewerID int64 ReviewerID int64
OfficialOnly bool OfficialOnly bool
Dismissed util.OptionalBool Dismissed optional.Option[bool]
} }
func (opts *FindReviewOptions) toCond() builder.Cond { func (opts *FindReviewOptions) toCond() builder.Cond {
@ -85,8 +85,8 @@ func (opts *FindReviewOptions) toCond() builder.Cond {
if opts.OfficialOnly { if opts.OfficialOnly {
cond = cond.And(builder.Eq{"official": true}) cond = cond.And(builder.Eq{"official": true})
} }
if !opts.Dismissed.IsNone() { if opts.Dismissed.Has() {
cond = cond.And(builder.Eq{"dismissed": opts.Dismissed.IsTrue()}) cond = cond.And(builder.Eq{"dismissed": opts.Dismissed.Value()})
} }
return cond return cond
} }

@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -340,7 +341,7 @@ func GetTrackedTimeByID(ctx context.Context, id int64) (*TrackedTime, error) {
} }
// GetIssueTotalTrackedTime returns the total tracked time for issues by given conditions. // GetIssueTotalTrackedTime returns the total tracked time for issues by given conditions.
func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed util.OptionalBool) (int64, error) { func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed optional.Option[bool]) (int64, error) {
if len(opts.IssueIDs) <= MaxQueryParameters { if len(opts.IssueIDs) <= MaxQueryParameters {
return getIssueTotalTrackedTimeChunk(ctx, opts, isClosed, opts.IssueIDs) return getIssueTotalTrackedTimeChunk(ctx, opts, isClosed, opts.IssueIDs)
} }
@ -363,7 +364,7 @@ func GetIssueTotalTrackedTime(ctx context.Context, opts *IssuesOptions, isClosed
return accum, nil return accum, nil
} }
func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isClosed util.OptionalBool, issueIDs []int64) (int64, error) { func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isClosed optional.Option[bool], issueIDs []int64) (int64, error) {
sumSession := func(opts *IssuesOptions, issueIDs []int64) *xorm.Session { sumSession := func(opts *IssuesOptions, issueIDs []int64) *xorm.Session {
sess := db.GetEngine(ctx). sess := db.GetEngine(ctx).
Table("tracked_time"). Table("tracked_time").
@ -378,8 +379,8 @@ func getIssueTotalTrackedTimeChunk(ctx context.Context, opts *IssuesOptions, isC
} }
session := sumSession(opts, issueIDs) session := sumSession(opts, issueIDs)
if !isClosed.IsNone() { if isClosed.Has() {
session = session.And("issue.is_closed = ?", isClosed.IsTrue()) session = session.And("issue.is_closed = ?", isClosed.Value())
} }
return session.SumInt(new(trackedTime), "tracked_time.time") return session.SumInt(new(trackedTime), "tracked_time.time")
} }

@ -11,7 +11,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -120,15 +120,15 @@ func TestTotalTimesForEachUser(t *testing.T) {
func TestGetIssueTotalTrackedTime(t *testing.T) { func TestGetIssueTotalTrackedTime(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
ttt, err := issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolFalse) ttt, err := issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, optional.Some(false))
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 3682, ttt) assert.EqualValues(t, 3682, ttt)
ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolTrue) ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, optional.Some(true))
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 0, ttt) assert.EqualValues(t, 0, ttt)
ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, util.OptionalBoolNone) ttt, err = issues_model.GetIssueTotalTrackedTime(db.DefaultContext, &issues_model.IssuesOptions{MilestoneIDs: []int64{1}}, optional.None[bool]())
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 3682, ttt) assert.EqualValues(t, 3682, ttt)
} }

@ -55,7 +55,7 @@ func CountPackages(ctx context.Context, opts *packages_model.PackageSearchOption
func toConds(opts *packages_model.PackageSearchOptions) builder.Cond { func toConds(opts *packages_model.PackageSearchOptions) builder.Cond {
var cond builder.Cond = builder.Eq{ var cond builder.Cond = builder.Eq{
"package.is_internal": opts.IsInternal.IsTrue(), "package.is_internal": opts.IsInternal.Value(),
"package.owner_id": opts.OwnerID, "package.owner_id": opts.OwnerID,
"package.type": packages_model.TypeNuGet, "package.type": packages_model.TypeNuGet,
} }

@ -9,6 +9,7 @@ import (
"strings" "strings"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -105,7 +106,7 @@ func getVersionByNameAndVersion(ctx context.Context, ownerID int64, packageType
ExactMatch: true, ExactMatch: true,
Value: version, Value: version,
}, },
IsInternal: util.OptionalBoolOf(isInternal), IsInternal: optional.Some(isInternal),
Paginator: db.NewAbsoluteListOptions(0, 1), Paginator: db.NewAbsoluteListOptions(0, 1),
}) })
if err != nil { if err != nil {
@ -122,7 +123,7 @@ func GetVersionsByPackageType(ctx context.Context, ownerID int64, packageType Ty
pvs, _, err := SearchVersions(ctx, &PackageSearchOptions{ pvs, _, err := SearchVersions(ctx, &PackageSearchOptions{
OwnerID: ownerID, OwnerID: ownerID,
Type: packageType, Type: packageType,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
return pvs, err return pvs, err
} }
@ -136,7 +137,7 @@ func GetVersionsByPackageName(ctx context.Context, ownerID int64, packageType Ty
ExactMatch: true, ExactMatch: true,
Value: name, Value: name,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
return pvs, err return pvs, err
} }
@ -182,18 +183,18 @@ type PackageSearchOptions struct {
Name SearchValue // only results with the specific name are found Name SearchValue // only results with the specific name are found
Version SearchValue // only results with the specific version are found Version SearchValue // only results with the specific version are found
Properties map[string]string // only results are found which contain all listed version properties with the specific value Properties map[string]string // only results are found which contain all listed version properties with the specific value
IsInternal util.OptionalBool IsInternal optional.Option[bool]
HasFileWithName string // only results are found which are associated with a file with the specific name HasFileWithName string // only results are found which are associated with a file with the specific name
HasFiles util.OptionalBool // only results are found which have associated files HasFiles optional.Option[bool] // only results are found which have associated files
Sort VersionSort Sort VersionSort
db.Paginator db.Paginator
} }
func (opts *PackageSearchOptions) ToConds() builder.Cond { func (opts *PackageSearchOptions) ToConds() builder.Cond {
cond := builder.NewCond() cond := builder.NewCond()
if !opts.IsInternal.IsNone() { if opts.IsInternal.Has() {
cond = builder.Eq{ cond = builder.Eq{
"package_version.is_internal": opts.IsInternal.IsTrue(), "package_version.is_internal": opts.IsInternal.Value(),
} }
} }
@ -250,10 +251,10 @@ func (opts *PackageSearchOptions) ToConds() builder.Cond {
cond = cond.And(builder.Exists(builder.Select("package_file.id").From("package_file").Where(fileCond))) cond = cond.And(builder.Exists(builder.Select("package_file.id").From("package_file").Where(fileCond)))
} }
if !opts.HasFiles.IsNone() { if opts.HasFiles.Has() {
filesCond := builder.Exists(builder.Select("package_file.id").From("package_file").Where(builder.Expr("package_file.version_id = package_version.id"))) filesCond := builder.Exists(builder.Select("package_file.id").From("package_file").Where(builder.Expr("package_file.version_id = package_version.id")))
if opts.HasFiles.IsFalse() { if !opts.HasFiles.Value() {
filesCond = builder.Not{filesCond} filesCond = builder.Not{filesCond}
} }
@ -307,8 +308,8 @@ func SearchLatestVersions(ctx context.Context, opts *PackageSearchOptions) ([]*P
And(builder.Expr("pv2.id IS NULL")) And(builder.Expr("pv2.id IS NULL"))
joinCond := builder.Expr("package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))") joinCond := builder.Expr("package_version.package_id = pv2.package_id AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))")
if !opts.IsInternal.IsNone() { if opts.IsInternal.Has() {
joinCond = joinCond.And(builder.Eq{"pv2.is_internal": opts.IsInternal.IsTrue()}) joinCond = joinCond.And(builder.Eq{"pv2.is_internal": opts.IsInternal.Value()})
} }
sess := db.GetEngine(ctx). sess := db.GetEngine(ctx).

@ -12,6 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -196,7 +197,7 @@ type SearchOptions struct {
db.ListOptions db.ListOptions
OwnerID int64 OwnerID int64
RepoID int64 RepoID int64
IsClosed util.OptionalBool IsClosed optional.Option[bool]
OrderBy db.SearchOrderBy OrderBy db.SearchOrderBy
Type Type Type Type
Title string Title string
@ -207,11 +208,8 @@ func (opts SearchOptions) ToConds() builder.Cond {
if opts.RepoID > 0 { if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
} }
switch opts.IsClosed { if opts.IsClosed.Has() {
case util.OptionalBoolTrue: cond = cond.And(builder.Eq{"is_closed": opts.IsClosed.Value()})
cond = cond.And(builder.Eq{"is_closed": true})
case util.OptionalBoolFalse:
cond = cond.And(builder.Eq{"is_closed": false})
} }
if opts.Type > 0 { if opts.Type > 0 {

@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -840,7 +841,7 @@ func (repo *Repository) TemplateRepo(ctx context.Context) *Repository {
type CountRepositoryOptions struct { type CountRepositoryOptions struct {
OwnerID int64 OwnerID int64
Private util.OptionalBool Private optional.Option[bool]
} }
// CountRepositories returns number of repositories. // CountRepositories returns number of repositories.
@ -852,8 +853,8 @@ func CountRepositories(ctx context.Context, opts CountRepositoryOptions) (int64,
if opts.OwnerID > 0 { if opts.OwnerID > 0 {
sess.And("owner_id = ?", opts.OwnerID) sess.And("owner_id = ?", opts.OwnerID)
} }
if !opts.Private.IsNone() { if opts.Private.Has() {
sess.And("is_private=?", opts.Private.IsTrue()) sess.And("is_private=?", opts.Private.Value())
} }
count, err := sess.Count(new(Repository)) count, err := sess.Count(new(Repository))

@ -12,17 +12,17 @@ import (
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var ( var (
countRepospts = repo_model.CountRepositoryOptions{OwnerID: 10} countRepospts = repo_model.CountRepositoryOptions{OwnerID: 10}
countReposptsPublic = repo_model.CountRepositoryOptions{OwnerID: 10, Private: util.OptionalBoolFalse} countReposptsPublic = repo_model.CountRepositoryOptions{OwnerID: 10, Private: optional.Some(false)}
countReposptsPrivate = repo_model.CountRepositoryOptions{OwnerID: 10, Private: util.OptionalBoolTrue} countReposptsPrivate = repo_model.CountRepositoryOptions{OwnerID: 10, Private: optional.Some(true)}
) )
func TestGetRepositoryCount(t *testing.T) { func TestGetRepositoryCount(t *testing.T) {

@ -715,7 +715,7 @@ func CreateUser(ctx context.Context, u *User, overwriteDefault ...*CreateUserOve
// IsLastAdminUser check whether user is the last admin // IsLastAdminUser check whether user is the last admin
func IsLastAdminUser(ctx context.Context, user *User) bool { func IsLastAdminUser(ctx context.Context, user *User) bool {
if user.IsAdmin && CountUsers(ctx, &CountUserFilter{IsAdmin: util.OptionalBoolTrue}) <= 1 { if user.IsAdmin && CountUsers(ctx, &CountUserFilter{IsAdmin: optional.Some(true)}) <= 1 {
return true return true
} }
return false return false
@ -724,7 +724,7 @@ func IsLastAdminUser(ctx context.Context, user *User) bool {
// CountUserFilter represent optional filters for CountUsers // CountUserFilter represent optional filters for CountUsers
type CountUserFilter struct { type CountUserFilter struct {
LastLoginSince *int64 LastLoginSince *int64
IsAdmin util.OptionalBool IsAdmin optional.Option[bool]
} }
// CountUsers returns number of users. // CountUsers returns number of users.
@ -742,8 +742,8 @@ func countUsers(ctx context.Context, opts *CountUserFilter) int64 {
cond = cond.And(builder.Gte{"last_login_unix": *opts.LastLoginSince}) cond = cond.And(builder.Gte{"last_login_unix": *opts.LastLoginSince})
} }
if !opts.IsAdmin.IsNone() { if opts.IsAdmin.Has() {
cond = cond.And(builder.Eq{"is_admin": opts.IsAdmin.IsTrue()}) cond = cond.And(builder.Eq{"is_admin": opts.IsAdmin.Value()})
} }
} }

@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/secret" "code.gitea.io/gitea/modules/secret"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
@ -433,7 +434,7 @@ type ListWebhookOptions struct {
db.ListOptions db.ListOptions
RepoID int64 RepoID int64
OwnerID int64 OwnerID int64
IsActive util.OptionalBool IsActive optional.Option[bool]
} }
func (opts ListWebhookOptions) ToConds() builder.Cond { func (opts ListWebhookOptions) ToConds() builder.Cond {
@ -444,8 +445,8 @@ func (opts ListWebhookOptions) ToConds() builder.Cond {
if opts.OwnerID != 0 { if opts.OwnerID != 0 {
cond = cond.And(builder.Eq{"webhook.owner_id": opts.OwnerID}) cond = cond.And(builder.Eq{"webhook.owner_id": opts.OwnerID})
} }
if !opts.IsActive.IsNone() { if opts.IsActive.Has() {
cond = cond.And(builder.Eq{"webhook.is_active": opts.IsActive.IsTrue()}) cond = cond.And(builder.Eq{"webhook.is_active": opts.IsActive.Value()})
} }
return cond return cond
} }

@ -8,7 +8,7 @@ import (
"fmt" "fmt"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
) )
// GetDefaultWebhooks returns all admin-default webhooks. // GetDefaultWebhooks returns all admin-default webhooks.
@ -34,15 +34,15 @@ func GetSystemOrDefaultWebhook(ctx context.Context, id int64) (*Webhook, error)
} }
// GetSystemWebhooks returns all admin system webhooks. // GetSystemWebhooks returns all admin system webhooks.
func GetSystemWebhooks(ctx context.Context, isActive util.OptionalBool) ([]*Webhook, error) { func GetSystemWebhooks(ctx context.Context, isActive optional.Option[bool]) ([]*Webhook, error) {
webhooks := make([]*Webhook, 0, 5) webhooks := make([]*Webhook, 0, 5)
if isActive.IsNone() { if !isActive.Has() {
return webhooks, db.GetEngine(ctx). return webhooks, db.GetEngine(ctx).
Where("repo_id=? AND owner_id=? AND is_system_webhook=?", 0, 0, true). Where("repo_id=? AND owner_id=? AND is_system_webhook=?", 0, 0, true).
Find(&webhooks) Find(&webhooks)
} }
return webhooks, db.GetEngine(ctx). return webhooks, db.GetEngine(ctx).
Where("repo_id=? AND owner_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.IsTrue()). Where("repo_id=? AND owner_id=? AND is_system_webhook=? AND is_active = ?", 0, 0, true, isActive.Value()).
Find(&webhooks) Find(&webhooks)
} }

@ -11,9 +11,9 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/optional"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -123,7 +123,7 @@ func TestGetWebhookByOwnerID(t *testing.T) {
func TestGetActiveWebhooksByRepoID(t *testing.T) { func TestGetActiveWebhooksByRepoID(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
hooks, err := db.Find[Webhook](db.DefaultContext, ListWebhookOptions{RepoID: 1, IsActive: util.OptionalBoolTrue}) hooks, err := db.Find[Webhook](db.DefaultContext, ListWebhookOptions{RepoID: 1, IsActive: optional.Some(true)})
assert.NoError(t, err) assert.NoError(t, err)
if assert.Len(t, hooks, 1) { if assert.Len(t, hooks, 1) {
assert.Equal(t, int64(1), hooks[0].ID) assert.Equal(t, int64(1), hooks[0].ID)
@ -143,7 +143,7 @@ func TestGetWebhooksByRepoID(t *testing.T) {
func TestGetActiveWebhooksByOwnerID(t *testing.T) { func TestGetActiveWebhooksByOwnerID(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
hooks, err := db.Find[Webhook](db.DefaultContext, ListWebhookOptions{OwnerID: 3, IsActive: util.OptionalBoolTrue}) hooks, err := db.Find[Webhook](db.DefaultContext, ListWebhookOptions{OwnerID: 3, IsActive: optional.Some(true)})
assert.NoError(t, err) assert.NoError(t, err)
if assert.Len(t, hooks, 1) { if assert.Len(t, hooks, 1) {
assert.Equal(t, int64(3), hooks[0].ID) assert.Equal(t, int64(3), hooks[0].ID)

@ -175,11 +175,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
queries = append(queries, bleve.NewDisjunctionQuery(repoQueries...)) queries = append(queries, bleve.NewDisjunctionQuery(repoQueries...))
} }
if !options.IsPull.IsNone() { if options.IsPull.Has() {
queries = append(queries, inner_bleve.BoolFieldQuery(options.IsPull.IsTrue(), "is_pull")) queries = append(queries, inner_bleve.BoolFieldQuery(options.IsPull.Value(), "is_pull"))
} }
if !options.IsClosed.IsNone() { if options.IsClosed.Has() {
queries = append(queries, inner_bleve.BoolFieldQuery(options.IsClosed.IsTrue(), "is_closed")) queries = append(queries, inner_bleve.BoolFieldQuery(options.IsClosed.Value(), "is_closed"))
} }
if options.NoLabelOnly { if options.NoLabelOnly {

@ -11,6 +11,7 @@ import (
issue_model "code.gitea.io/gitea/models/issues" issue_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/indexer/issues/internal" "code.gitea.io/gitea/modules/indexer/issues/internal"
"code.gitea.io/gitea/modules/optional"
) )
func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_model.IssuesOptions, error) { func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_model.IssuesOptions, error) {
@ -75,7 +76,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
UpdatedAfterUnix: convertInt64(options.UpdatedAfterUnix), UpdatedAfterUnix: convertInt64(options.UpdatedAfterUnix),
UpdatedBeforeUnix: convertInt64(options.UpdatedBeforeUnix), UpdatedBeforeUnix: convertInt64(options.UpdatedBeforeUnix),
PriorityRepoID: 0, PriorityRepoID: 0,
IsArchived: 0, IsArchived: optional.None[bool](),
Org: nil, Org: nil,
Team: nil, Team: nil,
User: nil, User: nil,

@ -153,11 +153,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
query.Must(q) query.Must(q)
} }
if !options.IsPull.IsNone() { if options.IsPull.Has() {
query.Must(elastic.NewTermQuery("is_pull", options.IsPull.IsTrue())) query.Must(elastic.NewTermQuery("is_pull", options.IsPull.Value()))
} }
if !options.IsClosed.IsNone() { if options.IsClosed.Has() {
query.Must(elastic.NewTermQuery("is_closed", options.IsClosed.IsTrue())) query.Must(elastic.NewTermQuery("is_closed", options.IsClosed.Value()))
} }
if options.NoLabelOnly { if options.NoLabelOnly {

@ -10,8 +10,8 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/indexer/issues/internal" "code.gitea.io/gitea/modules/indexer/issues/internal"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
_ "code.gitea.io/gitea/models" _ "code.gitea.io/gitea/models"
_ "code.gitea.io/gitea/models/actions" _ "code.gitea.io/gitea/models/actions"
@ -210,13 +210,13 @@ func searchIssueIsPull(t *testing.T) {
}{ }{
{ {
SearchOptions{ SearchOptions{
IsPull: util.OptionalBoolFalse, IsPull: optional.Some(false),
}, },
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 1}, []int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 1},
}, },
{ {
SearchOptions{ SearchOptions{
IsPull: util.OptionalBoolTrue, IsPull: optional.Some(true),
}, },
[]int64{22, 21, 12, 11, 20, 19, 9, 8, 3, 2}, []int64{22, 21, 12, 11, 20, 19, 9, 8, 3, 2},
}, },
@ -237,13 +237,13 @@ func searchIssueIsClosed(t *testing.T) {
}{ }{
{ {
SearchOptions{ SearchOptions{
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}, },
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1}, []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
}, },
{ {
SearchOptions{ SearchOptions{
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}, },
[]int64{5, 4}, []int64{5, 4},
}, },

@ -5,8 +5,8 @@ package internal
import ( import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
) )
// IndexerData data stored in the issue indexer // IndexerData data stored in the issue indexer
@ -77,8 +77,8 @@ type SearchOptions struct {
RepoIDs []int64 // repository IDs which the issues belong to RepoIDs []int64 // repository IDs which the issues belong to
AllPublic bool // if include all public repositories AllPublic bool // if include all public repositories
IsPull util.OptionalBool // if the issues is a pull request IsPull optional.Option[bool] // if the issues is a pull request
IsClosed util.OptionalBool // if the issues is closed IsClosed optional.Option[bool] // if the issues is closed
IncludedLabelIDs []int64 // labels the issues have IncludedLabelIDs []int64 // labels the issues have
ExcludedLabelIDs []int64 // labels the issues don't have ExcludedLabelIDs []int64 // labels the issues don't have

@ -16,8 +16,8 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/indexer/issues/internal" "code.gitea.io/gitea/modules/indexer/issues/internal"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -166,7 +166,7 @@ var cases = []*testIndexerCase{
Paginator: &db.ListOptions{ Paginator: &db.ListOptions{
PageSize: 5, PageSize: 5,
}, },
IsPull: util.OptionalBoolFalse, IsPull: optional.Some(false),
}, },
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) { Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, 5, len(result.Hits)) assert.Equal(t, 5, len(result.Hits))
@ -182,7 +182,7 @@ var cases = []*testIndexerCase{
Paginator: &db.ListOptions{ Paginator: &db.ListOptions{
PageSize: 5, PageSize: 5,
}, },
IsPull: util.OptionalBoolTrue, IsPull: optional.Some(true),
}, },
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) { Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, 5, len(result.Hits)) assert.Equal(t, 5, len(result.Hits))
@ -198,7 +198,7 @@ var cases = []*testIndexerCase{
Paginator: &db.ListOptions{ Paginator: &db.ListOptions{
PageSize: 5, PageSize: 5,
}, },
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}, },
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) { Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, 5, len(result.Hits)) assert.Equal(t, 5, len(result.Hits))
@ -214,7 +214,7 @@ var cases = []*testIndexerCase{
Paginator: &db.ListOptions{ Paginator: &db.ListOptions{
PageSize: 5, PageSize: 5,
}, },
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}, },
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) { Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, 5, len(result.Hits)) assert.Equal(t, 5, len(result.Hits))

@ -131,11 +131,11 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
query.And(q) query.And(q)
} }
if !options.IsPull.IsNone() { if options.IsPull.Has() {
query.And(inner_meilisearch.NewFilterEq("is_pull", options.IsPull.IsTrue())) query.And(inner_meilisearch.NewFilterEq("is_pull", options.IsPull.Value()))
} }
if !options.IsClosed.IsNone() { if options.IsClosed.Has() {
query.And(inner_meilisearch.NewFilterEq("is_closed", options.IsClosed.IsTrue())) query.And(inner_meilisearch.NewFilterEq("is_closed", options.IsClosed.Value()))
} }
if options.NoLabelOnly { if options.NoLabelOnly {

@ -17,57 +17,6 @@ import (
"golang.org/x/text/language" "golang.org/x/text/language"
) )
// OptionalBool a boolean that can be "null"
type OptionalBool byte
const (
// OptionalBoolNone a "null" boolean value
OptionalBoolNone OptionalBool = iota
// OptionalBoolTrue a "true" boolean value
OptionalBoolTrue
// OptionalBoolFalse a "false" boolean value
OptionalBoolFalse
)
// IsTrue return true if equal to OptionalBoolTrue
func (o OptionalBool) IsTrue() bool {
return o == OptionalBoolTrue
}
// IsFalse return true if equal to OptionalBoolFalse
func (o OptionalBool) IsFalse() bool {
return o == OptionalBoolFalse
}
// IsNone return true if equal to OptionalBoolNone
func (o OptionalBool) IsNone() bool {
return o == OptionalBoolNone
}
// ToGeneric converts OptionalBool to optional.Option[bool]
func (o OptionalBool) ToGeneric() optional.Option[bool] {
if o.IsNone() {
return optional.None[bool]()
}
return optional.Some[bool](o.IsTrue())
}
// OptionalBoolFromGeneric converts optional.Option[bool] to OptionalBool
func OptionalBoolFromGeneric(o optional.Option[bool]) OptionalBool {
if o.Has() {
return OptionalBoolOf(o.Value())
}
return OptionalBoolNone
}
// OptionalBoolOf get the corresponding OptionalBool of a bool
func OptionalBoolOf(b bool) OptionalBool {
if b {
return OptionalBoolTrue
}
return OptionalBoolFalse
}
// OptionalBoolParse get the corresponding optional.Option[bool] of a string using strconv.ParseBool // OptionalBoolParse get the corresponding optional.Option[bool] of a string using strconv.ParseBool
func OptionalBoolParse(s string) optional.Option[bool] { func OptionalBoolParse(s string) optional.Option[bool] {
v, e := strconv.ParseBool(s) v, e := strconv.ParseBool(s)

@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
cargo_module "code.gitea.io/gitea/modules/packages/cargo" cargo_module "code.gitea.io/gitea/modules/packages/cargo"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -110,7 +111,7 @@ func SearchPackages(ctx *context.Context) {
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeCargo, Type: packages_model.TypeCargo,
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")}, Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: &paginator, Paginator: &paginator,
}, },
) )

@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
chef_module "code.gitea.io/gitea/modules/packages/chef" chef_module "code.gitea.io/gitea/modules/packages/chef"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -40,7 +41,7 @@ func PackagesUniverse(ctx *context.Context) {
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeChef, Type: packages_model.TypeChef,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)
@ -85,7 +86,7 @@ func EnumeratePackages(ctx *context.Context) {
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeChef, Type: packages_model.TypeChef,
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")}, Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: db.NewAbsoluteListOptions( Paginator: db.NewAbsoluteListOptions(
ctx.FormInt("start"), ctx.FormInt("start"),
ctx.FormInt("items"), ctx.FormInt("items"),

@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
composer_module "code.gitea.io/gitea/modules/packages/composer" composer_module "code.gitea.io/gitea/modules/packages/composer"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -66,7 +67,7 @@ func SearchPackages(ctx *context.Context) {
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeComposer, Type: packages_model.TypeComposer,
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")}, Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: &paginator, Paginator: &paginator,
} }
if ctx.FormTrim("type") != "" { if ctx.FormTrim("type") != "" {

@ -12,6 +12,7 @@ import (
"time" "time"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
goproxy_module "code.gitea.io/gitea/modules/packages/goproxy" goproxy_module "code.gitea.io/gitea/modules/packages/goproxy"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -129,7 +130,7 @@ func resolvePackage(ctx *context.Context, ownerID int64, name, version string) (
Value: name, Value: name,
ExactMatch: true, ExactMatch: true,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Sort: packages_model.SortCreatedDesc, Sort: packages_model.SortCreatedDesc,
}) })
if err != nil { if err != nil {

@ -15,6 +15,7 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
helm_module "code.gitea.io/gitea/modules/packages/helm" helm_module "code.gitea.io/gitea/modules/packages/helm"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -42,7 +43,7 @@ func Index(ctx *context.Context) {
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeHelm, Type: packages_model.TypeHelm,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)
@ -110,7 +111,7 @@ func DownloadPackageFile(ctx *context.Context) {
Value: ctx.Params("package"), Value: ctx.Params("package"),
}, },
HasFileWithName: filename, HasFileWithName: filename,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)

@ -17,6 +17,7 @@ import (
access_model "code.gitea.io/gitea/models/perm/access" access_model "code.gitea.io/gitea/models/perm/access"
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
npm_module "code.gitea.io/gitea/modules/packages/npm" npm_module "code.gitea.io/gitea/modules/packages/npm"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -120,7 +121,7 @@ func DownloadPackageFileByName(ctx *context.Context) {
Value: packageNameFromParams(ctx), Value: packageNameFromParams(ctx),
}, },
HasFileWithName: filename, HasFileWithName: filename,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)
@ -395,7 +396,7 @@ func setPackageTag(ctx std_ctx.Context, tag string, pv *packages_model.PackageVe
Properties: map[string]string{ Properties: map[string]string{
npm_module.TagProperty: tag, npm_module.TagProperty: tag,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
return err return err
@ -431,7 +432,7 @@ func PackageSearch(ctx *context.Context) {
pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{ pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeNpm, Type: packages_model.TypeNpm,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Name: packages_model.SearchValue{ Name: packages_model.SearchValue{
ExactMatch: false, ExactMatch: false,
Value: ctx.FormTrim("text"), Value: ctx.FormTrim("text"),

@ -18,6 +18,7 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
nuget_model "code.gitea.io/gitea/models/packages/nuget" nuget_model "code.gitea.io/gitea/models/packages/nuget"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
nuget_module "code.gitea.io/gitea/modules/packages/nuget" nuget_module "code.gitea.io/gitea/modules/packages/nuget"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -122,7 +123,7 @@ func SearchServiceV2(ctx *context.Context) {
Name: packages_model.SearchValue{ Name: packages_model.SearchValue{
Value: getSearchTerm(ctx), Value: getSearchTerm(ctx),
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: paginator, Paginator: paginator,
}) })
if err != nil { if err != nil {
@ -172,7 +173,7 @@ func SearchServiceV2Count(ctx *context.Context) {
Name: packages_model.SearchValue{ Name: packages_model.SearchValue{
Value: getSearchTerm(ctx), Value: getSearchTerm(ctx),
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)
@ -187,7 +188,7 @@ func SearchServiceV3(ctx *context.Context) {
pvs, count, err := nuget_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, count, err := nuget_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Name: packages_model.SearchValue{Value: ctx.FormTrim("q")}, Name: packages_model.SearchValue{Value: ctx.FormTrim("q")},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: db.NewAbsoluteListOptions( Paginator: db.NewAbsoluteListOptions(
ctx.FormInt("skip"), ctx.FormInt("skip"),
ctx.FormInt("take"), ctx.FormInt("take"),
@ -313,7 +314,7 @@ func EnumeratePackageVersionsV2(ctx *context.Context) {
ExactMatch: true, ExactMatch: true,
Value: packageName, Value: packageName,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: paginator, Paginator: paginator,
}) })
if err != nil { if err != nil {
@ -358,7 +359,7 @@ func EnumeratePackageVersionsV2Count(ctx *context.Context) {
ExactMatch: true, ExactMatch: true,
Value: strings.Trim(ctx.FormTrim("id"), "'"), Value: strings.Trim(ctx.FormTrim("id"), "'"),
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)

@ -13,6 +13,7 @@ import (
"strings" "strings"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
rubygems_module "code.gitea.io/gitea/modules/packages/rubygems" rubygems_module "code.gitea.io/gitea/modules/packages/rubygems"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -43,7 +44,7 @@ func EnumeratePackagesLatest(ctx *context.Context) {
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeRubyGems, Type: packages_model.TypeRubyGems,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)
@ -304,7 +305,7 @@ func getVersionsByFilename(ctx *context.Context, filename string) ([]*packages_m
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages_model.TypeRubyGems, Type: packages_model.TypeRubyGems,
HasFileWithName: filename, HasFileWithName: filename,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
return pvs, err return pvs, err
} }

@ -15,6 +15,7 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
swift_module "code.gitea.io/gitea/modules/packages/swift" swift_module "code.gitea.io/gitea/modules/packages/swift"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -433,7 +434,7 @@ func LookupPackageIdentifiers(ctx *context.Context) {
Properties: map[string]string{ Properties: map[string]string{
swift_module.PropertyRepositoryURL: url, swift_module.PropertyRepositoryURL: url,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -37,7 +38,7 @@ func ListHooks(ctx *context.APIContext) {
// "200": // "200":
// "$ref": "#/responses/HookList" // "$ref": "#/responses/HookList"
sysHooks, err := webhook.GetSystemWebhooks(ctx, util.OptionalBoolNone) sysHooks, err := webhook.GetSystemWebhooks(ctx, optional.None[bool]())
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err) ctx.Error(http.StatusInternalServerError, "GetSystemWebhooks", err)
return return

@ -7,8 +7,8 @@ import (
"net/http" "net/http"
"code.gitea.io/gitea/models/packages" "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/optional"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
@ -60,7 +60,7 @@ func ListPackages(ctx *context.APIContext) {
OwnerID: ctx.Package.Owner.ID, OwnerID: ctx.Package.Owner.ID,
Type: packages.Type(packageType), Type: packages.Type(packageType),
Name: packages.SearchValue{Value: query}, Name: packages.SearchValue{Value: query},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: &listOptions, Paginator: &listOptions,
}) })
if err != nil { if err != nil {

@ -23,7 +23,6 @@ import (
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
@ -123,14 +122,14 @@ func SearchIssues(ctx *context.APIContext) {
return return
} }
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch ctx.FormString("state") { switch ctx.FormString("state") {
case "closed": case "closed":
isClosed = util.OptionalBoolTrue isClosed = optional.Some(true)
case "all": case "all":
isClosed = util.OptionalBoolNone isClosed = optional.None[bool]()
default: default:
isClosed = util.OptionalBoolFalse isClosed = optional.Some(false)
} }
var ( var (
@ -205,14 +204,14 @@ func SearchIssues(ctx *context.APIContext) {
keyword = "" keyword = ""
} }
var isPull util.OptionalBool var isPull optional.Option[bool]
switch ctx.FormString("type") { switch ctx.FormString("type") {
case "pulls": case "pulls":
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
case "issues": case "issues":
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
default: default:
isPull = util.OptionalBoolNone isPull = optional.None[bool]()
} }
var includedAnyLabels []int64 var includedAnyLabels []int64
@ -397,14 +396,14 @@ func ListIssues(ctx *context.APIContext) {
return return
} }
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch ctx.FormString("state") { switch ctx.FormString("state") {
case "closed": case "closed":
isClosed = util.OptionalBoolTrue isClosed = optional.Some(true)
case "all": case "all":
isClosed = util.OptionalBoolNone isClosed = optional.None[bool]()
default: default:
isClosed = util.OptionalBoolFalse isClosed = optional.Some(false)
} }
keyword := ctx.FormTrim("q") keyword := ctx.FormTrim("q")
@ -453,31 +452,29 @@ func ListIssues(ctx *context.APIContext) {
listOptions := utils.GetListOptions(ctx) listOptions := utils.GetListOptions(ctx)
var isPull util.OptionalBool isPull := optional.None[bool]()
switch ctx.FormString("type") { switch ctx.FormString("type") {
case "pulls": case "pulls":
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
case "issues": case "issues":
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
default:
isPull = util.OptionalBoolNone
} }
if isPull != util.OptionalBoolNone && !ctx.Repo.CanReadIssuesOrPulls(isPull.IsTrue()) { if isPull.Has() && !ctx.Repo.CanReadIssuesOrPulls(isPull.Value()) {
ctx.NotFound() ctx.NotFound()
return return
} }
if isPull == util.OptionalBoolNone { if !isPull.Has() {
canReadIssues := ctx.Repo.CanRead(unit.TypeIssues) canReadIssues := ctx.Repo.CanRead(unit.TypeIssues)
canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests) canReadPulls := ctx.Repo.CanRead(unit.TypePullRequests)
if !canReadIssues && !canReadPulls { if !canReadIssues && !canReadPulls {
ctx.NotFound() ctx.NotFound()
return return
} else if !canReadIssues { } else if !canReadIssues {
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
} else if !canReadPulls { } else if !canReadPulls {
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
} }
} }

@ -14,8 +14,8 @@ import (
repo_model "code.gitea.io/gitea/models/repo" repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/optional"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
@ -278,15 +278,15 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return return
} }
var isPull util.OptionalBool var isPull optional.Option[bool]
canReadIssue := ctx.Repo.CanRead(unit.TypeIssues) canReadIssue := ctx.Repo.CanRead(unit.TypeIssues)
canReadPull := ctx.Repo.CanRead(unit.TypePullRequests) canReadPull := ctx.Repo.CanRead(unit.TypePullRequests)
if canReadIssue && canReadPull { if canReadIssue && canReadPull {
isPull = util.OptionalBoolNone isPull = optional.None[bool]()
} else if canReadIssue { } else if canReadIssue {
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
} else if canReadPull { } else if canReadPull {
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
} else { } else {
ctx.NotFound() ctx.NotFound()
return return

@ -11,9 +11,9 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/optional"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils" "code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
@ -61,10 +61,10 @@ func ListMilestones(ctx *context.APIContext) {
// "$ref": "#/responses/notFound" // "$ref": "#/responses/notFound"
state := api.StateType(ctx.FormString("state")) state := api.StateType(ctx.FormString("state"))
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch state { switch state {
case api.StateClosed, api.StateOpen: case api.StateClosed, api.StateOpen:
isClosed = util.OptionalBoolOf(state == api.StateClosed) isClosed = optional.Some(state == api.StateClosed)
} }
milestones, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{ milestones, total, err := db.FindAndCount[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{

@ -8,8 +8,8 @@ import (
"code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
@ -35,7 +35,7 @@ func DefaultOrSystemWebhooks(ctx *context.Context) {
sys["Title"] = ctx.Tr("admin.systemhooks") sys["Title"] = ctx.Tr("admin.systemhooks")
sys["Description"] = ctx.Tr("admin.systemhooks.desc") sys["Description"] = ctx.Tr("admin.systemhooks.desc")
sys["Webhooks"], err = webhook.GetSystemWebhooks(ctx, util.OptionalBoolNone) sys["Webhooks"], err = webhook.GetSystemWebhooks(ctx, optional.None[bool]())
sys["BaseLink"] = setting.AppSubURL + "/admin/hooks" sys["BaseLink"] = setting.AppSubURL + "/admin/hooks"
sys["BaseLinkNew"] = setting.AppSubURL + "/admin/system-hooks" sys["BaseLinkNew"] = setting.AppSubURL + "/admin/system-hooks"
if err != nil { if err != nil {

@ -11,8 +11,8 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup" packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
@ -36,7 +36,7 @@ func Packages(ctx *context.Context) {
Type: packages_model.Type(packageType), Type: packages_model.Type(packageType),
Name: packages_model.SearchValue{Value: query}, Name: packages_model.SearchValue{Value: query},
Sort: sort, Sort: sort,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Paginator: &db.ListOptions{ Paginator: &db.ListOptions{
PageSize: setting.UI.PackagesPagingNum, PageSize: setting.UI.PackagesPagingNum,
Page: page, Page: page,

@ -96,7 +96,7 @@ func NewUser(ctx *context.Context) {
ctx.Data["login_type"] = "0-0" ctx.Data["login_type"] = "0-0"
sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
}) })
if err != nil { if err != nil {
ctx.ServerError("auth.Sources", err) ctx.ServerError("auth.Sources", err)
@ -117,7 +117,7 @@ func NewUserPost(ctx *context.Context) {
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice() ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
}) })
if err != nil { if err != nil {
ctx.ServerError("auth.Sources", err) ctx.ServerError("auth.Sources", err)

@ -163,7 +163,7 @@ func SignIn(ctx *context.Context) {
return return
} }
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, util.OptionalBoolTrue) oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
if err != nil { if err != nil {
ctx.ServerError("UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
@ -186,7 +186,7 @@ func SignIn(ctx *context.Context) {
func SignInPost(ctx *context.Context) { func SignInPost(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in") ctx.Data["Title"] = ctx.Tr("sign_in")
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, util.OptionalBoolTrue) oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
if err != nil { if err != nil {
ctx.ServerError("UserSignIn", err) ctx.ServerError("UserSignIn", err)
return return
@ -410,7 +410,7 @@ func SignUp(ctx *context.Context) {
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up" ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, util.OptionalBoolTrue) oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
if err != nil { if err != nil {
ctx.ServerError("UserSignUp", err) ctx.ServerError("UserSignUp", err)
return return
@ -439,7 +439,7 @@ func SignUpPost(ctx *context.Context) {
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up" ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, util.OptionalBoolTrue) oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
if err != nil { if err != nil {
ctx.ServerError("UserSignUp", err) ctx.ServerError("UserSignUp", err)
return return

@ -18,9 +18,9 @@ import (
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
shared_user "code.gitea.io/gitea/routers/web/shared/user" shared_user "code.gitea.io/gitea/routers/web/shared/user"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
@ -67,7 +67,7 @@ func Projects(ctx *context.Context) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
IsClosed: util.OptionalBoolOf(isShowClosed), IsClosed: optional.Some(isShowClosed),
OrderBy: project_model.GetSearchOrderByBySortType(sortType), OrderBy: project_model.GetSearchOrderByBySortType(sortType),
Type: projectType, Type: projectType,
Title: keyword, Title: keyword,
@ -79,7 +79,7 @@ func Projects(ctx *context.Context) {
opTotal, err := db.Count[project_model.Project](ctx, project_model.SearchOptions{ opTotal, err := db.Count[project_model.Project](ctx, project_model.SearchOptions{
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
IsClosed: util.OptionalBoolOf(!isShowClosed), IsClosed: optional.Some(!isShowClosed),
Type: projectType, Type: projectType,
}) })
if err != nil { if err != nil {
@ -388,7 +388,7 @@ func ViewProject(ctx *context.Context) {
if len(referencedIDs) > 0 { if len(referencedIDs) > 0 {
if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{ if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
IssueIDs: referencedIDs, IssueIDs: referencedIDs,
IsPull: util.OptionalBoolTrue, IsPull: optional.Some(true),
}); err == nil { }); err == nil {
linkedPrsMap[issue.ID] = linkedPrs linkedPrsMap[issue.ID] = linkedPrs
} }

@ -16,8 +16,8 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/web/repo" "code.gitea.io/gitea/routers/web/repo"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert" "code.gitea.io/gitea/services/convert"
@ -78,7 +78,7 @@ func List(ctx *context.Context) {
// Get all runner labels // Get all runner labels
runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{ runners, err := db.Find[actions_model.ActionRunner](ctx, actions_model.FindRunnerOptions{
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsOnline: util.OptionalBoolTrue, IsOnline: optional.Some(true),
WithAvailable: true, WithAvailable: true,
}) })
if err != nil { if err != nil {

@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
@ -53,7 +54,7 @@ func Branches(ctx *context.Context) {
kw := ctx.FormString("q") kw := ctx.FormString("q")
defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, util.OptionalBoolNone, kw, page, pageSize) defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, optional.None[bool](), kw, page, pageSize)
if err != nil { if err != nil {
ctx.ServerError("LoadBranches", err) ctx.ServerError("LoadBranches", err)
return return

@ -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 var err error
viewType := ctx.FormString("type") viewType := ctx.FormString("type")
sortType := ctx.FormString("sort") 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") { switch ctx.FormString("state") {
case "closed": case "closed":
isShowClosed = util.OptionalBoolTrue isShowClosed = optional.Some(true)
case "all": case "all":
isShowClosed = util.OptionalBoolNone isShowClosed = optional.None[bool]()
default: default:
isShowClosed = util.OptionalBoolFalse isShowClosed = optional.Some(false)
} }
// if there are closed issues and no open issues, default to showing all issues // 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 { if len(ctx.FormString("state")) == 0 && issueStats.OpenCount == 0 && issueStats.ClosedCount != 0 {
isShowClosed = util.OptionalBoolNone isShowClosed = optional.None[bool]()
} }
if repo.IsTimetrackerEnabled(ctx) { if repo.IsTimetrackerEnabled(ctx) {
@ -272,10 +272,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
} }
var total int var total int
switch isShowClosed { switch {
case util.OptionalBoolTrue: case isShowClosed.Value():
total = int(issueStats.ClosedCount) total = int(issueStats.ClosedCount)
case util.OptionalBoolNone: case !isShowClosed.Has():
total = int(issueStats.OpenCount + issueStats.ClosedCount) total = int(issueStats.OpenCount + issueStats.ClosedCount)
default: default:
total = int(issueStats.OpenCount) total = int(issueStats.OpenCount)
@ -431,7 +431,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
return return
} }
pinned, err := issues_model.GetPinnedIssues(ctx, repo.ID, isPullOption.IsTrue()) pinned, err := issues_model.GetPinnedIssues(ctx, repo.ID, isPullOption.Value())
if err != nil { if err != nil {
ctx.ServerError("GetPinnedIssues", err) ctx.ServerError("GetPinnedIssues", err)
return return
@ -461,10 +461,10 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
ctx.Data["AssigneeID"] = assigneeID ctx.Data["AssigneeID"] = assigneeID
ctx.Data["PosterID"] = posterID ctx.Data["PosterID"] = posterID
ctx.Data["Keyword"] = keyword ctx.Data["Keyword"] = keyword
switch isShowClosed { switch {
case util.OptionalBoolTrue: case isShowClosed.Value():
ctx.Data["State"] = "closed" ctx.Data["State"] = "closed"
case util.OptionalBoolNone: case !isShowClosed.Has():
ctx.Data["State"] = "all" ctx.Data["State"] = "all"
default: default:
ctx.Data["State"] = "open" 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) 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() { if ctx.Written() {
return return
} }
@ -555,7 +555,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R
var err error var err error
ctx.Data["OpenMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{ ctx.Data["OpenMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.ServerError("GetMilestones", err) 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{ ctx.Data["ClosedMilestones"], err = db.Find[issues_model.Milestone](ctx, issues_model.FindMilestoneOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
if err != nil { if err != nil {
ctx.ServerError("GetMilestones", err) 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{ projects, err := db.Find[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
Type: project_model.TypeRepository, Type: project_model.TypeRepository,
}) })
if err != nil { 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{ projects2, err := db.Find[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
OwnerID: repo.OwnerID, OwnerID: repo.OwnerID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
Type: repoOwnerType, Type: repoOwnerType,
}) })
if err != nil { 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{ projects, err = db.Find[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
Type: project_model.TypeRepository, Type: project_model.TypeRepository,
}) })
if err != nil { 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{ projects2, err = db.Find[project_model.Project](ctx, project_model.SearchOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
OwnerID: repo.OwnerID, OwnerID: repo.OwnerID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
Type: repoOwnerType, Type: repoOwnerType,
}) })
if err != nil { if err != nil {
@ -2502,14 +2502,14 @@ func SearchIssues(ctx *context.Context) {
return return
} }
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch ctx.FormString("state") { switch ctx.FormString("state") {
case "closed": case "closed":
isClosed = util.OptionalBoolTrue isClosed = optional.Some(true)
case "all": case "all":
isClosed = util.OptionalBoolNone isClosed = optional.None[bool]()
default: default:
isClosed = util.OptionalBoolFalse isClosed = optional.Some(false)
} }
var ( var (
@ -2584,14 +2584,12 @@ func SearchIssues(ctx *context.Context) {
keyword = "" keyword = ""
} }
var isPull util.OptionalBool isPull := optional.None[bool]()
switch ctx.FormString("type") { switch ctx.FormString("type") {
case "pulls": case "pulls":
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
case "issues": case "issues":
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
default:
isPull = util.OptionalBoolNone
} }
var includedAnyLabels []int64 var includedAnyLabels []int64
@ -2726,14 +2724,14 @@ func ListIssues(ctx *context.Context) {
return return
} }
var isClosed util.OptionalBool var isClosed optional.Option[bool]
switch ctx.FormString("state") { switch ctx.FormString("state") {
case "closed": case "closed":
isClosed = util.OptionalBoolTrue isClosed = optional.Some(true)
case "all": case "all":
isClosed = util.OptionalBoolNone isClosed = optional.None[bool]()
default: default:
isClosed = util.OptionalBoolFalse isClosed = optional.Some(false)
} }
keyword := ctx.FormTrim("q") keyword := ctx.FormTrim("q")
@ -2785,14 +2783,12 @@ func ListIssues(ctx *context.Context) {
projectID = &v projectID = &v
} }
var isPull util.OptionalBool isPull := optional.None[bool]()
switch ctx.FormString("type") { switch ctx.FormString("type") {
case "pulls": case "pulls":
isPull = util.OptionalBoolTrue isPull = optional.Some(true)
case "issues": case "issues":
isPull = util.OptionalBoolFalse isPull = optional.Some(false)
default:
isPull = util.OptionalBoolNone
} }
// FIXME: we should be more efficient here // FIXME: we should be more efficient here

@ -14,9 +14,9 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
@ -51,7 +51,7 @@ func Milestones(ctx *context.Context) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
IsClosed: util.OptionalBoolOf(isShowClosed), IsClosed: optional.Some(isShowClosed),
SortType: sortType, SortType: sortType,
Name: keyword, Name: keyword,
}) })
@ -292,7 +292,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) {
ctx.Data["Title"] = milestone.Name ctx.Data["Title"] = milestone.Name
ctx.Data["Milestone"] = milestone ctx.Data["Milestone"] = milestone
issues(ctx, milestoneID, projectID, util.OptionalBoolNone) issues(ctx, milestoneID, projectID, optional.None[bool]())
ret := issue.ParseTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo) ret := issue.ParseTemplatesFromDefaultBranch(ctx.Repo.Repository, ctx.Repo.GitRepo)
ctx.Data["NewIssueChooseTemplate"] = len(ret.IssueTemplates) > 0 ctx.Data["NewIssueChooseTemplate"] = len(ret.IssueTemplates) > 0

@ -10,8 +10,8 @@ import (
"code.gitea.io/gitea/models/packages" "code.gitea.io/gitea/models/packages"
"code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
@ -37,7 +37,7 @@ func Packages(ctx *context.Context) {
RepoID: ctx.Repo.Repository.ID, RepoID: ctx.Repo.Repository.ID,
Type: packages.Type(packageType), Type: packages.Type(packageType),
Name: packages.SearchValue{Value: query}, Name: packages.SearchValue{Value: query},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.ServerError("SearchLatestVersions", err) ctx.ServerError("SearchLatestVersions", err)

@ -20,8 +20,8 @@ import (
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
@ -78,7 +78,7 @@ func Projects(ctx *context.Context) {
Page: page, Page: page,
}, },
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolOf(isShowClosed), IsClosed: optional.Some(isShowClosed),
OrderBy: project_model.GetSearchOrderByBySortType(sortType), OrderBy: project_model.GetSearchOrderByBySortType(sortType),
Type: project_model.TypeRepository, Type: project_model.TypeRepository,
Title: keyword, Title: keyword,
@ -349,7 +349,7 @@ func ViewProject(ctx *context.Context) {
if len(referencedIDs) > 0 { if len(referencedIDs) > 0 {
if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{ if linkedPrs, err := issues_model.Issues(ctx, &issues_model.IssuesOptions{
IssueIDs: referencedIDs, IssueIDs: referencedIDs,
IsPull: util.OptionalBoolTrue, IsPull: optional.Some(true),
}); err == nil { }); err == nil {
linkedPrsMap[issue.ID] = linkedPrs linkedPrsMap[issue.ID] = linkedPrs
} }

@ -13,7 +13,7 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/forms"
@ -157,7 +157,7 @@ func SetRulePreviewContext(ctx *context.Context, owner *user_model.User) {
for _, p := range packages { for _, p := range packages {
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
PackageID: p.ID, PackageID: p.ID,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Sort: packages_model.SortCreatedDesc, Sort: packages_model.SortCreatedDesc,
Paginator: db.NewAbsoluteListOptions(pcr.KeepCount, 200), Paginator: db.NewAbsoluteListOptions(pcr.KeepCount, 200),
}) })

@ -18,7 +18,6 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
@ -131,7 +130,7 @@ func LoadHeaderCount(ctx *context.Context) error {
} }
projectCount, err := db.Count[project_model.Project](ctx, project_model.SearchOptions{ projectCount, err := db.Count[project_model.Project](ctx, project_model.SearchOptions{
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
IsClosed: util.OptionalBoolOf(false), IsClosed: optional.Some(false),
Type: projectType, Type: projectType,
}) })
if err != nil { if err != nil {

@ -30,7 +30,6 @@ import (
"code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/web/feed" "code.gitea.io/gitea/routers/web/feed"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
issue_service "code.gitea.io/gitea/services/issue" issue_service "code.gitea.io/gitea/services/issue"
@ -215,7 +214,7 @@ func Milestones(ctx *context.Context) {
counts, err := issues_model.CountMilestonesMap(ctx, issues_model.FindMilestoneOptions{ counts, err := issues_model.CountMilestonesMap(ctx, issues_model.FindMilestoneOptions{
RepoCond: userRepoCond, RepoCond: userRepoCond,
Name: keyword, Name: keyword,
IsClosed: util.OptionalBoolOf(isShowClosed), IsClosed: optional.Some(isShowClosed),
}) })
if err != nil { if err != nil {
ctx.ServerError("CountMilestonesByRepoIDs", err) ctx.ServerError("CountMilestonesByRepoIDs", err)
@ -228,7 +227,7 @@ func Milestones(ctx *context.Context) {
PageSize: setting.UI.IssuePagingNum, PageSize: setting.UI.IssuePagingNum,
}, },
RepoCond: repoCond, RepoCond: repoCond,
IsClosed: util.OptionalBoolOf(isShowClosed), IsClosed: optional.Some(isShowClosed),
SortType: sortType, SortType: sortType,
Name: keyword, Name: keyword,
}) })
@ -440,9 +439,9 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
isPullList := unitType == unit.TypePullRequests isPullList := unitType == unit.TypePullRequests
opts := &issues_model.IssuesOptions{ opts := &issues_model.IssuesOptions{
IsPull: util.OptionalBoolOf(isPullList), IsPull: optional.Some(isPullList),
SortType: sortType, SortType: sortType,
IsArchived: util.OptionalBoolFalse, IsArchived: optional.Some(false),
Org: org, Org: org,
Team: team, Team: team,
User: ctx.Doer, User: ctx.Doer,
@ -516,7 +515,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// Educated guess: Do or don't show closed issues. // Educated guess: Do or don't show closed issues.
isShowClosed := ctx.FormString("state") == "closed" isShowClosed := ctx.FormString("state") == "closed"
opts.IsClosed = util.OptionalBoolOf(isShowClosed) opts.IsClosed = optional.Some(isShowClosed)
// Make sure page number is at least 1. Will be posted to ctx.Data. // Make sure page number is at least 1. Will be posted to ctx.Data.
page := ctx.FormInt("page") page := ctx.FormInt("page")
@ -800,12 +799,12 @@ func getUserIssueStats(ctx *context.Context, ctxUser *user_model.User, filterMod
case issues_model.FilterModeReviewed: case issues_model.FilterModeReviewed:
openClosedOpts.ReviewedID = &doerID openClosedOpts.ReviewedID = &doerID
} }
openClosedOpts.IsClosed = util.OptionalBoolFalse openClosedOpts.IsClosed = optional.Some(false)
ret.OpenCount, err = issue_indexer.CountIssues(ctx, openClosedOpts) ret.OpenCount, err = issue_indexer.CountIssues(ctx, openClosedOpts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
openClosedOpts.IsClosed = util.OptionalBoolTrue openClosedOpts.IsClosed = optional.Some(true)
ret.ClosedCount, err = issue_indexer.CountIssues(ctx, openClosedOpts) ret.ClosedCount, err = issue_indexer.CountIssues(ctx, openClosedOpts)
if err != nil { if err != nil {
return nil, err return nil, err

@ -233,26 +233,25 @@ func NotificationSubscriptions(ctx *context.Context) {
if !util.SliceContainsString([]string{"all", "open", "closed"}, state, true) { if !util.SliceContainsString([]string{"all", "open", "closed"}, state, true) {
state = "all" state = "all"
} }
ctx.Data["State"] = state ctx.Data["State"] = state
var showClosed util.OptionalBool // default state filter is "all"
showClosed := optional.None[bool]()
switch state { switch state {
case "all":
showClosed = util.OptionalBoolNone
case "closed": case "closed":
showClosed = util.OptionalBoolTrue showClosed = optional.Some(true)
case "open": case "open":
showClosed = util.OptionalBoolFalse showClosed = optional.Some(false)
} }
var issueTypeBool util.OptionalBool
issueType := ctx.FormString("issueType") issueType := ctx.FormString("issueType")
// default issue type is no filter
issueTypeBool := optional.None[bool]()
switch issueType { switch issueType {
case "issues": case "issues":
issueTypeBool = util.OptionalBoolFalse issueTypeBool = optional.Some(false)
case "pulls": case "pulls":
issueTypeBool = util.OptionalBoolTrue issueTypeBool = optional.Some(true)
default:
issueTypeBool = util.OptionalBoolNone
} }
ctx.Data["IssueType"] = issueType ctx.Data["IssueType"] = issueType

@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
alpine_module "code.gitea.io/gitea/modules/packages/alpine" alpine_module "code.gitea.io/gitea/modules/packages/alpine"
debian_module "code.gitea.io/gitea/modules/packages/debian" debian_module "code.gitea.io/gitea/modules/packages/debian"
rpm_module "code.gitea.io/gitea/modules/packages/rpm" rpm_module "code.gitea.io/gitea/modules/packages/rpm"
@ -54,7 +55,7 @@ func ListPackages(ctx *context.Context) {
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
Type: packages_model.Type(packageType), Type: packages_model.Type(packageType),
Name: packages_model.SearchValue{Value: query}, Name: packages_model.SearchValue{Value: query},
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.ServerError("SearchLatestVersions", err) ctx.ServerError("SearchLatestVersions", err)
@ -145,7 +146,7 @@ func RedirectToLastVersion(ctx *context.Context) {
pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
PackageID: p.ID, PackageID: p.ID,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
ctx.ServerError("GetPackageByName", err) ctx.ServerError("GetPackageByName", err)
@ -255,7 +256,7 @@ func ViewPackageVersion(ctx *context.Context) {
pvs, total, err = packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, total, err = packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
Paginator: db.NewAbsoluteListOptions(0, 5), Paginator: db.NewAbsoluteListOptions(0, 5),
PackageID: pd.Package.ID, PackageID: pd.Package.ID,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
} }
if err != nil { if err != nil {
@ -359,7 +360,7 @@ func ListPackageVersions(ctx *context.Context) {
ExactMatch: false, ExactMatch: false,
Value: query, Value: query,
}, },
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Sort: sort, Sort: sort,
}) })
if err != nil { if err != nil {
@ -467,7 +468,7 @@ func PackageSettingsPost(ctx *context.Context) {
redirectURL := ctx.Package.Owner.HomeLink() + "/-/packages" redirectURL := ctx.Package.Owner.HomeLink() + "/-/packages"
// redirect to the package if there are still versions available // redirect to the package if there are still versions available
if has, _ := packages_model.ExistVersion(ctx, &packages_model.PackageSearchOptions{PackageID: ctx.Package.Descriptor.Package.ID, IsInternal: util.OptionalBoolFalse}); has { if has, _ := packages_model.ExistVersion(ctx, &packages_model.PackageSearchOptions{PackageID: ctx.Package.Descriptor.Package.ID, IsInternal: optional.Some(false)}); has {
redirectURL = ctx.Package.Descriptor.PackageWebLink() redirectURL = ctx.Package.Descriptor.PackageWebLink()
} }

@ -12,8 +12,8 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/oauth2"
"code.gitea.io/gitea/services/context" "code.gitea.io/gitea/services/context"
) )
@ -112,7 +112,7 @@ func loadSecurityData(ctx *context.Context) {
ctx.Data["AccountLinks"] = sources ctx.Data["AccountLinks"] = sources
authSources, err := db.Find[auth_model.Source](ctx, auth_model.FindSourcesOptions{ authSources, err := db.Find[auth_model.Source](ctx, auth_model.FindSourcesOptions{
IsActive: util.OptionalBoolNone, IsActive: optional.None[bool](),
LoginType: auth_model.OAuth2, LoginType: auth_model.OAuth2,
}) })
if err != nil { if err != nil {

@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/auth/source/oauth2"
"code.gitea.io/gitea/services/auth/source/smtp" "code.gitea.io/gitea/services/auth/source/smtp"
@ -87,7 +87,7 @@ func UserSignIn(ctx context.Context, username, password string) (*user_model.Use
} }
sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
}) })
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

@ -12,8 +12,8 @@ import (
"code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
@ -66,7 +66,7 @@ func ResetOAuth2(ctx context.Context) error {
// initOAuth2Sources is used to load and register all active OAuth2 providers // initOAuth2Sources is used to load and register all active OAuth2 providers
func initOAuth2Sources(ctx context.Context) error { func initOAuth2Sources(ctx context.Context) error {
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
LoginType: auth.OAuth2, LoginType: auth.OAuth2,
}) })
if err != nil { if err != nil {

@ -15,8 +15,8 @@ import (
"code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/markbates/goth" "github.com/markbates/goth"
) )
@ -107,7 +107,7 @@ func CreateProviderFromSource(source *auth.Source) (Provider, error) {
} }
// GetOAuth2Providers returns the list of configured OAuth2 providers // GetOAuth2Providers returns the list of configured OAuth2 providers
func GetOAuth2Providers(ctx context.Context, isActive util.OptionalBool) ([]Provider, error) { func GetOAuth2Providers(ctx context.Context, isActive optional.Option[bool]) ([]Provider, error) {
authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ authSources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: isActive, IsActive: isActive,
LoginType: auth.OAuth2, LoginType: auth.OAuth2,

@ -17,7 +17,6 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/auth/source/sspi" "code.gitea.io/gitea/services/auth/source/sspi"
gitea_context "code.gitea.io/gitea/services/context" gitea_context "code.gitea.io/gitea/services/context"
@ -132,7 +131,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore,
// getConfig retrieves the SSPI configuration from login sources // getConfig retrieves the SSPI configuration from login sources
func (s *SSPI) getConfig(ctx context.Context) (*sspi.Source, error) { func (s *SSPI) getConfig(ctx context.Context) (*sspi.Source, error) {
sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{ sources, err := db.Find[auth.Source](ctx, auth.FindSourcesOptions{
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
LoginType: auth.SSPI, LoginType: auth.SSPI,
}) })
if err != nil { if err != nil {

@ -23,9 +23,9 @@ import (
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration" base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -68,14 +68,14 @@ func TestGiteaUploadRepo(t *testing.T) {
milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolFalse, IsClosed: optional.Some(false),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, milestones, 1) assert.Len(t, milestones, 1)
milestones, err = db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{ milestones, err = db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsClosed: util.OptionalBoolTrue, IsClosed: optional.Some(true),
}) })
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, milestones) assert.Empty(t, milestones)
@ -108,7 +108,7 @@ func TestGiteaUploadRepo(t *testing.T) {
issues, err := issues_model.Issues(db.DefaultContext, &issues_model.IssuesOptions{ issues, err := issues_model.Issues(db.DefaultContext, &issues_model.IssuesOptions{
RepoIDs: []int64{repo.ID}, RepoIDs: []int64{repo.ID},
IsPull: util.OptionalBoolFalse, IsPull: optional.Some(false),
SortType: "oldest", SortType: "oldest",
}) })
assert.NoError(t, err) assert.NoError(t, err)

@ -12,8 +12,8 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
"code.gitea.io/gitea/modules/util"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
alpine_service "code.gitea.io/gitea/services/packages/alpine" alpine_service "code.gitea.io/gitea/services/packages/alpine"
cargo_service "code.gitea.io/gitea/services/packages/cargo" cargo_service "code.gitea.io/gitea/services/packages/cargo"
@ -60,7 +60,7 @@ func ExecuteCleanupRules(outerCtx context.Context) error {
for _, p := range packages { for _, p := range packages {
pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{ pvs, _, err := packages_model.SearchVersions(ctx, &packages_model.PackageSearchOptions{
PackageID: p.ID, PackageID: p.ID,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
Sort: packages_model.SortCreatedDesc, Sort: packages_model.SortCreatedDesc,
Paginator: db.NewAbsoluteListOptions(pcr.KeepCount, 200), Paginator: db.NewAbsoluteListOptions(pcr.KeepCount, 200),
}) })

@ -9,8 +9,8 @@ import (
packages_model "code.gitea.io/gitea/models/packages" packages_model "code.gitea.io/gitea/models/packages"
container_model "code.gitea.io/gitea/models/packages/container" container_model "code.gitea.io/gitea/models/packages/container"
"code.gitea.io/gitea/modules/optional"
container_module "code.gitea.io/gitea/modules/packages/container" container_module "code.gitea.io/gitea/modules/packages/container"
"code.gitea.io/gitea/modules/util"
packages_service "code.gitea.io/gitea/services/packages" packages_service "code.gitea.io/gitea/services/packages"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
@ -59,8 +59,8 @@ func cleanupExpiredUploadedBlobs(ctx context.Context, olderThan time.Duration) e
ExactMatch: true, ExactMatch: true,
Value: container_model.UploadVersion, Value: container_model.UploadVersion,
}, },
IsInternal: util.OptionalBoolTrue, IsInternal: optional.Some(true),
HasFiles: util.OptionalBoolFalse, HasFiles: optional.Some(false),
}) })
if err != nil { if err != nil {
return err return err

@ -18,10 +18,10 @@ import (
user_model "code.gitea.io/gitea/models/user" user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
packages_module "code.gitea.io/gitea/modules/packages" packages_module "code.gitea.io/gitea/modules/packages"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify" notify_service "code.gitea.io/gitea/services/notify"
) )
@ -330,7 +330,7 @@ func CheckCountQuotaExceeded(ctx context.Context, doer, owner *user_model.User)
if setting.Packages.LimitTotalOwnerCount > -1 { if setting.Packages.LimitTotalOwnerCount > -1 {
totalCount, err := packages_model.CountVersions(ctx, &packages_model.PackageSearchOptions{ totalCount, err := packages_model.CountVersions(ctx, &packages_model.PackageSearchOptions{
OwnerID: owner.ID, OwnerID: owner.ID,
IsInternal: util.OptionalBoolFalse, IsInternal: optional.Some(false),
}) })
if err != nil { if err != nil {
log.Error("CountVersions failed: %v", err) log.Error("CountVersions failed: %v", err)
@ -640,7 +640,7 @@ func RemoveAllPackages(ctx context.Context, userID int64) (int, error) {
Page: 1, Page: 1,
}, },
OwnerID: userID, OwnerID: userID,
IsInternal: util.OptionalBoolNone, IsInternal: optional.None[bool](),
}) })
if err != nil { if err != nil {
return count, fmt.Errorf("GetOwnedPackages[%d]: %w", userID, err) return count, fmt.Errorf("GetOwnedPackages[%d]: %w", userID, err)

@ -18,8 +18,8 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
notify_service "code.gitea.io/gitea/services/notify" notify_service "code.gitea.io/gitea/services/notify"
) )
@ -56,7 +56,7 @@ func InvalidateCodeComments(ctx context.Context, prs issues_model.PullRequestLis
ListAll: true, ListAll: true,
}, },
Type: issues_model.CommentTypeCode, Type: issues_model.CommentTypeCode,
Invalidated: util.OptionalBoolFalse, Invalidated: optional.Some(false),
IssueIDs: issueIDs, IssueIDs: issueIDs,
}) })
if err != nil { if err != nil {
@ -327,7 +327,7 @@ func DismissApprovalReviews(ctx context.Context, doer *user_model.User, pull *is
}, },
IssueID: pull.IssueID, IssueID: pull.IssueID,
Type: issues_model.ReviewTypeApprove, Type: issues_model.ReviewTypeApprove,
Dismissed: util.OptionalBoolFalse, Dismissed: optional.Some(false),
}) })
if err != nil { if err != nil {
return err return err
@ -394,7 +394,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
reviews, err := issues_model.FindReviews(ctx, issues_model.FindReviewOptions{ reviews, err := issues_model.FindReviews(ctx, issues_model.FindReviewOptions{
IssueID: review.IssueID, IssueID: review.IssueID,
ReviewerID: review.ReviewerID, ReviewerID: review.ReviewerID,
Dismissed: util.OptionalBoolFalse, Dismissed: optional.Some(false),
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -24,7 +24,6 @@ import (
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository" repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook" webhook_module "code.gitea.io/gitea/modules/webhook"
notify_service "code.gitea.io/gitea/services/notify" notify_service "code.gitea.io/gitea/services/notify"
files_service "code.gitea.io/gitea/services/repository/files" files_service "code.gitea.io/gitea/services/repository/files"
@ -54,7 +53,7 @@ type Branch struct {
} }
// LoadBranches loads branches from the repository limited by page & pageSize. // LoadBranches loads branches from the repository limited by page & pageSize.
func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch util.OptionalBool, keyword string, page, pageSize int) (*Branch, []*Branch, int64, error) { func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch optional.Option[bool], keyword string, page, pageSize int) (*Branch, []*Branch, int64, error) {
defaultDBBranch, err := git_model.GetBranch(ctx, repo.ID, repo.DefaultBranch) defaultDBBranch, err := git_model.GetBranch(ctx, repo.ID, repo.DefaultBranch)
if err != nil { if err != nil {
return nil, nil, 0, err return nil, nil, 0, err
@ -62,7 +61,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
branchOpts := git_model.FindBranchOptions{ branchOpts := git_model.FindBranchOptions{
RepoID: repo.ID, RepoID: repo.ID,
IsDeletedBranch: isDeletedBranch.ToGeneric(), IsDeletedBranch: isDeletedBranch,
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: page, Page: page,
PageSize: pageSize, PageSize: pageSize,

@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/queue" "code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs"
@ -225,7 +226,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_modu
if source.Repository != nil { if source.Repository != nil {
repoHooks, err := db.Find[webhook_model.Webhook](ctx, webhook_model.ListWebhookOptions{ repoHooks, err := db.Find[webhook_model.Webhook](ctx, webhook_model.ListWebhookOptions{
RepoID: source.Repository.ID, RepoID: source.Repository.ID,
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
}) })
if err != nil { if err != nil {
return fmt.Errorf("ListWebhooksByOpts: %w", err) return fmt.Errorf("ListWebhooksByOpts: %w", err)
@ -239,7 +240,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_modu
if owner != nil { if owner != nil {
ownerHooks, err := db.Find[webhook_model.Webhook](ctx, webhook_model.ListWebhookOptions{ ownerHooks, err := db.Find[webhook_model.Webhook](ctx, webhook_model.ListWebhookOptions{
OwnerID: owner.ID, OwnerID: owner.ID,
IsActive: util.OptionalBoolTrue, IsActive: optional.Some(true),
}) })
if err != nil { if err != nil {
return fmt.Errorf("ListWebhooksByOpts: %w", err) return fmt.Errorf("ListWebhooksByOpts: %w", err)
@ -248,7 +249,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_modu
} }
// Add any admin-defined system webhooks // Add any admin-defined system webhooks
systemHooks, err := webhook_model.GetSystemWebhooks(ctx, util.OptionalBoolTrue) systemHooks, err := webhook_model.GetSystemWebhooks(ctx, optional.Some(true))
if err != nil { if err != nil {
return fmt.Errorf("GetSystemWebhooks: %w", err) return fmt.Errorf("GetSystemWebhooks: %w", err)
} }

Loading…
Cancel
Save