@@ -1105,14 +1105,18 @@ func CountUserRepositories(userID int64, private bool) int64 {
1105
1105
}
1106
1106
1107
1107
// Repositories returns all repositories
1108
- func Repositories (page , pageSize int ) (_ []* Repository , err error ) {
1109
- repos := make ([]* Repository , 0 , pageSize )
1110
- return repos , x .Limit (pageSize , (page - 1 )* pageSize ).Asc ("id" ).Find (& repos )
1108
+ func Repositories (opts * SearchRepoOptions ) (_ []* Repository , err error ) {
1109
+ if len (opts .OrderBy ) == 0 {
1110
+ opts .OrderBy = "id ASC"
1111
+ }
1112
+
1113
+ repos := make ([]* Repository , 0 , opts .PageSize )
1114
+ return repos , x .Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize ).OrderBy (opts .OrderBy ).Find (& repos )
1111
1115
}
1112
1116
1113
1117
// RepositoriesWithUsers returns number of repos in given page.
1114
- func RepositoriesWithUsers (page , pageSize int ) (_ []* Repository , err error ) {
1115
- repos , err := Repositories (page , pageSize )
1118
+ func RepositoriesWithUsers (opts * SearchRepoOptions ) (_ []* Repository , err error ) {
1119
+ repos , err := Repositories (opts )
1116
1120
if err != nil {
1117
1121
return nil , fmt .Errorf ("Repositories: %v" , err )
1118
1122
}
@@ -1565,12 +1569,31 @@ func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
1565
1569
}
1566
1570
1567
1571
// GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
1568
- func GetRecentUpdatedRepositories (page , pageSize int ) (repos []* Repository , err error ) {
1569
- return repos , x .
1570
- Limit (pageSize , (page - 1 )* pageSize ).
1571
- Where ("is_private=?" , false ).
1572
- Limit (pageSize ).
1573
- Desc ("updated_unix" ).
1572
+ func GetRecentUpdatedRepositories (opts * SearchRepoOptions ) (repos []* Repository , err error ) {
1573
+ if len (opts .OrderBy ) == 0 {
1574
+ opts .OrderBy = "updated_unix DESC"
1575
+ }
1576
+
1577
+ sess := x .Where ("is_private=?" , false ).
1578
+ Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize ).
1579
+ Limit (opts .PageSize )
1580
+
1581
+ if opts .Searcher != nil {
1582
+ sess .Or ("owner_id = ?" , opts .Searcher .ID )
1583
+
1584
+ err := opts .Searcher .GetOrganizations (true )
1585
+
1586
+ if err != nil {
1587
+ return nil , fmt .Errorf ("Organization: %v" , err )
1588
+ }
1589
+
1590
+ for _ , org := range opts .Searcher .Orgs {
1591
+ sess .Or ("owner_id = ?" , org .ID )
1592
+ }
1593
+ }
1594
+
1595
+ return repos , sess .
1596
+ OrderBy (opts .OrderBy ).
1574
1597
Find (& repos )
1575
1598
}
1576
1599
@@ -1587,6 +1610,7 @@ func GetRepositoryCount(u *User) (int64, error) {
1587
1610
type SearchRepoOptions struct {
1588
1611
Keyword string
1589
1612
OwnerID int64
1613
+ Searcher * User //ID of the person who's seeking
1590
1614
OrderBy string
1591
1615
Private bool // Include private repositories in results
1592
1616
Page int
@@ -1616,17 +1640,36 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int
1616
1640
sess .And ("is_private=?" , false )
1617
1641
}
1618
1642
1643
+ if opts .Searcher != nil {
1644
+
1645
+ sess .Or ("owner_id = ?" , opts .Searcher .ID )
1646
+
1647
+ err := opts .Searcher .GetOrganizations (true )
1648
+
1649
+ if err != nil {
1650
+ return nil , 0 , fmt .Errorf ("Organization: %v" , err )
1651
+ }
1652
+
1653
+ for _ , org := range opts .Searcher .Orgs {
1654
+ sess .Or ("owner_id = ?" , org .ID )
1655
+ }
1656
+ }
1657
+
1658
+ if len (opts .OrderBy ) == 0 {
1659
+ opts .OrderBy = "name ASC"
1660
+ }
1661
+
1619
1662
var countSess xorm.Session
1620
1663
countSess = * sess
1621
1664
count , err := countSess .Count (new (Repository ))
1622
1665
if err != nil {
1623
1666
return nil , 0 , fmt .Errorf ("Count: %v" , err )
1624
1667
}
1625
1668
1626
- if len ( opts . OrderBy ) > 0 {
1627
- sess . OrderBy (opts .OrderBy )
1628
- }
1629
- return repos , count , sess . Limit ( opts . PageSize , ( opts . Page - 1 ) * opts . PageSize ). Find (& repos )
1669
+ return repos , count , sess .
1670
+ Limit ( opts . PageSize , (opts .Page - 1 ) * opts . PageSize ).
1671
+ OrderBy ( opts . OrderBy ).
1672
+ Find (& repos )
1630
1673
}
1631
1674
1632
1675
// DeleteRepositoryArchives deletes all repositories' archives.
0 commit comments