@@ -359,7 +359,7 @@ func UserOrgPublicUnitRepoCond(userID, orgID int64) builder.Cond {
359
359
}
360
360
361
361
// SearchRepositoryCondition creates a query condition according search repository options
362
- func SearchRepositoryCondition (opts * SearchRepoOptions ) builder.Cond {
362
+ func SearchRepositoryCondition (opts SearchRepoOptions ) builder.Cond {
363
363
cond := builder .NewCond ()
364
364
365
365
if opts .Private {
@@ -551,18 +551,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
551
551
552
552
// SearchRepository returns repositories based on search options,
553
553
// it returns results in given range and number of total results.
554
- func SearchRepository (ctx context.Context , opts * SearchRepoOptions ) (RepositoryList , int64 , error ) {
554
+ func SearchRepository (ctx context.Context , opts SearchRepoOptions ) (RepositoryList , int64 , error ) {
555
555
cond := SearchRepositoryCondition (opts )
556
556
return SearchRepositoryByCondition (ctx , opts , cond , true )
557
557
}
558
558
559
559
// CountRepository counts repositories based on search options,
560
- func CountRepository (ctx context.Context , opts * SearchRepoOptions ) (int64 , error ) {
560
+ func CountRepository (ctx context.Context , opts SearchRepoOptions ) (int64 , error ) {
561
561
return db .GetEngine (ctx ).Where (SearchRepositoryCondition (opts )).Count (new (Repository ))
562
562
}
563
563
564
564
// SearchRepositoryByCondition search repositories by condition
565
- func SearchRepositoryByCondition (ctx context.Context , opts * SearchRepoOptions , cond builder.Cond , loadAttributes bool ) (RepositoryList , int64 , error ) {
565
+ func SearchRepositoryByCondition (ctx context.Context , opts SearchRepoOptions , cond builder.Cond , loadAttributes bool ) (RepositoryList , int64 , error ) {
566
566
sess , count , err := searchRepositoryByCondition (ctx , opts , cond )
567
567
if err != nil {
568
568
return nil , 0 , err
@@ -590,23 +590,25 @@ func SearchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
590
590
return repos , count , nil
591
591
}
592
592
593
- func searchRepositoryByCondition (ctx context.Context , opts * SearchRepoOptions , cond builder.Cond ) (db.Engine , int64 , error ) {
594
- if opts .Page <= 0 {
595
- opts .Page = 1
593
+ func searchRepositoryByCondition (ctx context.Context , opts SearchRepoOptions , cond builder.Cond ) (db.Engine , int64 , error ) {
594
+ page := opts .Page
595
+ if page <= 0 {
596
+ page = 1
596
597
}
597
598
598
- if len (opts .OrderBy ) == 0 {
599
- opts .OrderBy = db .SearchOrderByAlphabetically
599
+ orderBy := opts .OrderBy
600
+ if len (orderBy ) == 0 {
601
+ orderBy = db .SearchOrderByAlphabetically
600
602
}
601
603
602
604
args := make ([]any , 0 )
603
605
if opts .PriorityOwnerID > 0 {
604
- opts . OrderBy = db .SearchOrderBy (fmt .Sprintf ("CASE WHEN owner_id = ? THEN 0 ELSE owner_id END, %s" , opts . OrderBy ))
606
+ orderBy = db .SearchOrderBy (fmt .Sprintf ("CASE WHEN owner_id = ? THEN 0 ELSE owner_id END, %s" , orderBy ))
605
607
args = append (args , opts .PriorityOwnerID )
606
608
} else if strings .Count (opts .Keyword , "/" ) == 1 {
607
609
// With "owner/repo" search times, prioritise results which match the owner field
608
610
orgName := strings .Split (opts .Keyword , "/" )[0 ]
609
- opts . OrderBy = db .SearchOrderBy (fmt .Sprintf ("CASE WHEN owner_name LIKE ? THEN 0 ELSE 1 END, %s" , opts . OrderBy ))
611
+ orderBy = db .SearchOrderBy (fmt .Sprintf ("CASE WHEN owner_name LIKE ? THEN 0 ELSE 1 END, %s" , orderBy ))
610
612
args = append (args , orgName )
611
613
}
612
614
@@ -623,9 +625,9 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
623
625
}
624
626
}
625
627
626
- sess = sess .Where (cond ).OrderBy (opts . OrderBy .String (), args ... )
628
+ sess = sess .Where (cond ).OrderBy (orderBy .String (), args ... )
627
629
if opts .PageSize > 0 {
628
- sess = sess .Limit (opts .PageSize , (opts . Page - 1 )* opts .PageSize )
630
+ sess = sess .Limit (opts .PageSize , (page - 1 )* opts .PageSize )
629
631
}
630
632
return sess , count , nil
631
633
}
@@ -689,14 +691,14 @@ func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) bu
689
691
690
692
// SearchRepositoryByName takes keyword and part of repository name to search,
691
693
// it returns results in given range and number of total results.
692
- func SearchRepositoryByName (ctx context.Context , opts * SearchRepoOptions ) (RepositoryList , int64 , error ) {
694
+ func SearchRepositoryByName (ctx context.Context , opts SearchRepoOptions ) (RepositoryList , int64 , error ) {
693
695
opts .IncludeDescription = false
694
696
return SearchRepository (ctx , opts )
695
697
}
696
698
697
699
// SearchRepositoryIDs takes keyword and part of repository name to search,
698
700
// it returns results in given range and number of total results.
699
- func SearchRepositoryIDs (ctx context.Context , opts * SearchRepoOptions ) ([]int64 , int64 , error ) {
701
+ func SearchRepositoryIDs (ctx context.Context , opts SearchRepoOptions ) ([]int64 , int64 , error ) {
700
702
opts .IncludeDescription = false
701
703
702
704
cond := SearchRepositoryCondition (opts )
@@ -740,7 +742,7 @@ func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user
740
742
}
741
743
742
744
// GetUserRepositories returns a list of repositories of given user.
743
- func GetUserRepositories (ctx context.Context , opts * SearchRepoOptions ) (RepositoryList , int64 , error ) {
745
+ func GetUserRepositories (ctx context.Context , opts SearchRepoOptions ) (RepositoryList , int64 , error ) {
744
746
if len (opts .OrderBy ) == 0 {
745
747
opts .OrderBy = "updated_unix DESC"
746
748
}
@@ -767,5 +769,5 @@ func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (Reposito
767
769
768
770
sess = sess .Where (cond ).OrderBy (opts .OrderBy .String ())
769
771
repos := make (RepositoryList , 0 , opts .PageSize )
770
- return repos , count , db .SetSessionPagination (sess , opts ).Find (& repos )
772
+ return repos , count , db .SetSessionPagination (sess , & opts ).Find (& repos )
771
773
}
0 commit comments