Skip to content

Commit 252b54e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Show correct SSL Mode on "install page" (go-gitea#25818) Fix incorrect oldest sort in project list (go-gitea#25806) Fix the error message when the token is incorrect (go-gitea#25701) Exclude default branch from pushed branch hint (go-gitea#25795) For API attachments, use API URL (go-gitea#25639)
2 parents 28f689d + d1e066f commit 252b54e

32 files changed

+453
-128
lines changed

models/fixtures/project.yml

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
creator_id: 2
88
board_type: 1
99
type: 2
10+
created_unix: 1688973030
11+
updated_unix: 1688973030
1012

1113
-
1214
id: 2
@@ -17,6 +19,8 @@
1719
creator_id: 3
1820
board_type: 1
1921
type: 2
22+
created_unix: 1688973010
23+
updated_unix: 1688973010
2024

2125
-
2226
id: 3
@@ -27,6 +31,8 @@
2731
creator_id: 5
2832
board_type: 1
2933
type: 2
34+
created_unix: 1688973020
35+
updated_unix: 1688973020
3036

3137
-
3238
id: 4
@@ -37,3 +43,5 @@
3743
creator_id: 2
3844
board_type: 1
3945
type: 2
46+
created_unix: 1688973000
47+
updated_unix: 1688973000

models/git/branch.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str
382382
}
383383

384384
// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created
385-
func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (BranchList, error) {
385+
// except the indicate branch
386+
func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, excludeBranchName string) (BranchList, error) {
386387
branches := make(BranchList, 0, 2)
387388
subQuery := builder.Select("head_branch").From("pull_request").
388389
InnerJoin("issue", "issue.id = pull_request.issue_id").
@@ -392,6 +393,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (B
392393
})
393394
err := db.GetEngine(ctx).
394395
Where("pusher_id=? AND is_deleted=?", userID, false).
396+
And("name <> ?", excludeBranchName).
395397
And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()).
396398
NotIn("name", subQuery).
397399
OrderBy("branch.updated_unix DESC").

models/project/project.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ type SearchOptions struct {
196196
RepoID int64
197197
Page int
198198
IsClosed util.OptionalBool
199-
SortType string
199+
OrderBy db.SearchOrderBy
200200
Type Type
201201
}
202202

@@ -226,26 +226,28 @@ func CountProjects(ctx context.Context, opts SearchOptions) (int64, error) {
226226
return db.GetEngine(ctx).Where(opts.toConds()).Count(new(Project))
227227
}
228228

229+
func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
230+
switch sortType {
231+
case "oldest":
232+
return db.SearchOrderByOldest
233+
case "recentupdate":
234+
return db.SearchOrderByRecentUpdated
235+
case "leastupdate":
236+
return db.SearchOrderByLeastUpdated
237+
default:
238+
return db.SearchOrderByNewest
239+
}
240+
}
241+
229242
// FindProjects returns a list of all projects that have been created in the repository
230243
func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, error) {
231-
e := db.GetEngine(ctx).Where(opts.toConds())
244+
e := db.GetEngine(ctx).Where(opts.toConds()).OrderBy(opts.OrderBy.String())
232245
projects := make([]*Project, 0, setting.UI.IssuePagingNum)
233246

234247
if opts.Page > 0 {
235248
e = e.Limit(setting.UI.IssuePagingNum, (opts.Page-1)*setting.UI.IssuePagingNum)
236249
}
237250

238-
switch opts.SortType {
239-
case "oldest":
240-
e.Desc("created_unix")
241-
case "recentupdate":
242-
e.Desc("updated_unix")
243-
case "leastupdate":
244-
e.Asc("updated_unix")
245-
default:
246-
e.Asc("created_unix")
247-
}
248-
249251
count, err := e.FindAndCount(&projects)
250252
return projects, count, err
251253
}

models/project/project_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,42 @@ func TestProject(t *testing.T) {
8282

8383
assert.True(t, projectFromDB.IsClosed)
8484
}
85+
86+
func TestProjectsSort(t *testing.T) {
87+
assert.NoError(t, unittest.PrepareTestDatabase())
88+
89+
tests := []struct {
90+
sortType string
91+
wants []int64
92+
}{
93+
{
94+
sortType: "default",
95+
wants: []int64{1, 3, 2, 4},
96+
},
97+
{
98+
sortType: "oldest",
99+
wants: []int64{4, 2, 3, 1},
100+
},
101+
{
102+
sortType: "recentupdate",
103+
wants: []int64{1, 3, 2, 4},
104+
},
105+
{
106+
sortType: "leastupdate",
107+
wants: []int64{4, 2, 3, 1},
108+
},
109+
}
110+
111+
for _, tt := range tests {
112+
projects, count, err := FindProjects(db.DefaultContext, SearchOptions{
113+
OrderBy: GetSearchOrderByBySortType(tt.sortType),
114+
})
115+
assert.NoError(t, err)
116+
assert.EqualValues(t, int64(4), count)
117+
if assert.Len(t, projects, 4) {
118+
for i := range projects {
119+
assert.EqualValues(t, tt.wants[i], projects[i].ID)
120+
}
121+
}
122+
}
123+
}

models/repo/attachment.go

-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ func (a *Attachment) DownloadURL() string {
6565
return setting.AppURL + "attachments/" + url.PathEscape(a.UUID)
6666
}
6767

68-
// _____ __ __ .__ __
69-
// / _ \_/ |__/ |______ ____ | |__ _____ ____ _____/ |_
70-
// / /_\ \ __\ __\__ \ _/ ___\| | \ / \_/ __ \ / \ __\
71-
// / | \ | | | / __ \\ \___| Y \ Y Y \ ___/| | \ |
72-
// \____|__ /__| |__| (____ /\___ >___| /__|_| /\___ >___| /__|
73-
// \/ \/ \/ \/ \/ \/ \/
74-
7568
// ErrAttachmentNotExist represents a "AttachmentNotExist" kind of error.
7669
type ErrAttachmentNotExist struct {
7770
ID int64

0 commit comments

Comments
 (0)