Skip to content

Commit 642dd61

Browse files
Gustedforgejo-backport-action
authored and
forgejo-backport-action
committed
fix: Add recentupdated as recognized sort option
- Add `recentupdated` to the `OrderByMap`. - Add integration testing for organization and user repository sorting. - Resolves go-gitea#5612 - Regression from 12e23ee where the `recentupdated` case was not added to the map, but was handled seperately as a fallback. The regression came into affect when 5a0bc35 also relied on this map but didn't handle the `recentupdated` case. (cherry picked from commit df38c41)
1 parent c7e5285 commit 642dd61

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

models/fixtures/repository.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
size: 0
9292
is_fsck_enabled: true
9393
close_issues_via_commit_in_any_branch: false
94+
created_unix: 1700000001
95+
updated_unix: 1700000001
9496

9597
-
9698
id: 4
@@ -152,6 +154,8 @@
152154
size: 0
153155
is_fsck_enabled: true
154156
close_issues_via_commit_in_any_branch: false
157+
created_unix: 1700000002
158+
updated_unix: 1700000002
155159

156160
-
157161
id: 6
@@ -182,6 +186,8 @@
182186
size: 0
183187
is_fsck_enabled: true
184188
close_issues_via_commit_in_any_branch: false
189+
created_unix: 1710000001
190+
updated_unix: 1710000001
185191

186192
-
187193
id: 7
@@ -212,6 +218,8 @@
212218
size: 0
213219
is_fsck_enabled: true
214220
close_issues_via_commit_in_any_branch: false
221+
created_unix: 1710000003
222+
updated_unix: 1710000003
215223

216224
-
217225
id: 8
@@ -242,6 +250,8 @@
242250
size: 0
243251
is_fsck_enabled: true
244252
close_issues_via_commit_in_any_branch: false
253+
created_unix: 1710000002
254+
updated_unix: 1710000002
245255

246256
-
247257
id: 9
@@ -968,6 +978,8 @@
968978
size: 0
969979
is_fsck_enabled: true
970980
close_issues_via_commit_in_any_branch: false
981+
created_unix: 1700000003
982+
updated_unix: 1700000003
971983

972984
-
973985
id: 33
@@ -1811,4 +1823,4 @@
18111823
template_id: 0
18121824
size: 0
18131825
is_fsck_enabled: true
1814-
close_issues_via_commit_in_any_branch: false
1826+
close_issues_via_commit_in_any_branch: false

models/organization/org_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ func TestAccessibleReposEnv_RepoIDs(t *testing.T) {
299299
require.NoError(t, err)
300300
assert.Equal(t, expectedRepoIDs, repoIDs)
301301
}
302-
testSuccess(2, []int64{3, 5, 32})
303-
testSuccess(4, []int64{3, 32})
302+
testSuccess(2, []int64{32, 5, 3})
303+
testSuccess(4, []int64{32, 3})
304304
}
305305

306306
func TestAccessibleReposEnv_Repos(t *testing.T) {
@@ -318,8 +318,8 @@ func TestAccessibleReposEnv_Repos(t *testing.T) {
318318
}
319319
assert.Equal(t, expectedRepos, repos)
320320
}
321-
testSuccess(2, []int64{3, 5, 32})
322-
testSuccess(4, []int64{3, 32})
321+
testSuccess(2, []int64{32, 5, 3})
322+
testSuccess(4, []int64{32, 3})
323323
}
324324

325325
func TestAccessibleReposEnv_MirrorRepos(t *testing.T) {

models/repo/search.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var OrderByMap = map[string]map[string]db.SearchOrderBy{
3636
var OrderByFlatMap = map[string]db.SearchOrderBy{
3737
"newest": OrderByMap["desc"]["created"],
3838
"oldest": OrderByMap["asc"]["created"],
39+
"recentupdate": OrderByMap["desc"]["updated"],
3940
"leastupdate": OrderByMap["asc"]["updated"],
4041
"reversealphabetically": OrderByMap["desc"]["alpha"],
4142
"alphabetically": OrderByMap["asc"]["alpha"],

tests/integration/last_updated_time_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ func TestRepoLastUpdatedTime(t *testing.T) {
1616
user := "user2"
1717
session := loginUser(t, user)
1818

19-
req := NewRequest(t, "GET", path.Join("explore", "repos"))
19+
req := NewRequest(t, "GET", "/explore/repos?q=repo1")
2020
resp := session.MakeRequest(t, req, http.StatusOK)
2121
doc := NewHTMLParser(t, resp.Body)
2222
node := doc.doc.Find(".flex-item-body").First()
23-
2423
{
2524
buf := ""
2625
findTextNonNested(t, node, &buf)

tests/integration/org_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestOrgRepos(t *testing.T) {
2828
users = []string{"user1", "user2"}
2929
cases = map[string][]string{
3030
"alphabetically": {"repo21", "repo3", "repo5"},
31+
"recentupdate": {"repo21", "repo5", "repo3"},
3132
"reversealphabetically": {"repo5", "repo3", "repo21"},
3233
}
3334
)

tests/integration/user_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,27 @@ func TestUserTOTPEnrolled(t *testing.T) {
819819
assert.True(t, called)
820820
})
821821
}
822+
823+
func TestUserRepos(t *testing.T) {
824+
defer tests.PrepareTestEnv(t)()
825+
826+
cases := map[string][]string{
827+
"alphabetically": {"repo6", "repo7", "repo8"},
828+
"recentupdate": {"repo7", "repo8", "repo6"},
829+
"reversealphabetically": {"repo8", "repo7", "repo6"},
830+
}
831+
832+
session := loginUser(t, "user10")
833+
for sortBy, repos := range cases {
834+
req := NewRequest(t, "GET", "/user10?sort="+sortBy)
835+
resp := session.MakeRequest(t, req, http.StatusOK)
836+
837+
htmlDoc := NewHTMLParser(t, resp.Body)
838+
839+
sel := htmlDoc.doc.Find("a.name")
840+
assert.Len(t, repos, len(sel.Nodes))
841+
for i := 0; i < len(repos); i++ {
842+
assert.EqualValues(t, repos[i], strings.TrimSpace(sel.Eq(i).Text()))
843+
}
844+
}
845+
}

0 commit comments

Comments
 (0)