Skip to content

Commit c7eb9e6

Browse files
committed
use "optional" correctly
1 parent f9dfaa2 commit c7eb9e6

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

models/issues/issue_search.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
353353
}
354354

355355
func applyAssigneeCondition(sess *xorm.Session, assigneeID optional.Option[int64]) {
356-
if assigneeID == nil || assigneeID.Value() == 0 {
356+
// old logic: 0 is also treated as "not filtering assignee", because the "assignee" was read as FormInt64
357+
if !assigneeID.Has() || assigneeID.Value() == 0 {
357358
return
358359
}
359360
if assigneeID.Value() == db.NoConditionID {
@@ -365,7 +366,7 @@ func applyAssigneeCondition(sess *xorm.Session, assigneeID optional.Option[int64
365366
}
366367

367368
func applyPosterCondition(sess *xorm.Session, posterID optional.Option[int64]) {
368-
if posterID == nil {
369+
if !posterID.Has() {
369370
return
370371
}
371372
// poster doesn't need to support db.NoConditionID(-1), so just use the value as-is

routers/web/org/projects.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func ViewProject(ctx *context.Context) {
339339
if ctx.Written() {
340340
return
341341
}
342-
assigneeID := ctx.FormInt64("assignee")
342+
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
343343

344344
issuesMap, err := issues_model.LoadIssuesFromColumnList(ctx, columns, &issues_model.IssuesOptions{
345345
LabelIDs: labelIDs,

routers/web/repo/issue_list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
488488
viewType = "all"
489489
}
490490

491-
assigneeID := ctx.FormInt64("assignee")
491+
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
492492
posterUsername := ctx.FormString("poster")
493493
posterUserID := shared_user.GetFilterUserIDByName(ctx, posterUsername)
494494
var mentionedID, reviewRequestedID, reviewedID int64

routers/web/repo/projects.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func ViewProject(ctx *context.Context) {
310310

311311
labelIDs := issue.PrepareFilterIssueLabels(ctx, ctx.Repo.Repository.ID, ctx.Repo.Owner)
312312

313-
assigneeID := ctx.FormInt64("assignee")
313+
assigneeID := ctx.FormInt64("assignee") // TODO: use "optional" but not 0 in the future
314314

315315
issuesMap, err := issues_model.LoadIssuesFromColumnList(ctx, columns, &issues_model.IssuesOptions{
316316
LabelIDs: labelIDs,

routers/web/shared/user/helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
3939
// * some(NonExistingID): match no issue (due to the user doesn't exist)
4040
func GetFilterUserIDByName(ctx context.Context, name string) optional.Option[int64] {
4141
if name == "" {
42-
return nil
42+
return optional.None[int64]()
4343
}
4444
u, err := user.GetUserByName(ctx, name)
4545
if err != nil {

0 commit comments

Comments
 (0)