Skip to content

Commit 7690b3c

Browse files
committed
Merge branch 'main' into fix-editor-images
2 parents 6f62b00 + 5b56d13 commit 7690b3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+436
-362
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- typecheck
2323
- unconvert
2424
- unused
25+
- unparam
2526
- wastedassign
2627

2728
run:

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
# backend
3232
go_1_22
33+
gofumpt
3334
];
3435
};
3536
}

models/db/search.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ const (
1818
SearchOrderByRecentUpdated SearchOrderBy = "updated_unix DESC"
1919
SearchOrderByOldest SearchOrderBy = "created_unix ASC"
2020
SearchOrderByNewest SearchOrderBy = "created_unix DESC"
21-
SearchOrderBySize SearchOrderBy = "size ASC"
22-
SearchOrderBySizeReverse SearchOrderBy = "size DESC"
23-
SearchOrderByGitSize SearchOrderBy = "git_size ASC"
24-
SearchOrderByGitSizeReverse SearchOrderBy = "git_size DESC"
25-
SearchOrderByLFSSize SearchOrderBy = "lfs_size ASC"
26-
SearchOrderByLFSSizeReverse SearchOrderBy = "lfs_size DESC"
2721
SearchOrderByID SearchOrderBy = "id ASC"
2822
SearchOrderByIDReverse SearchOrderBy = "id DESC"
2923
SearchOrderByStars SearchOrderBy = "num_stars ASC"

models/dbfs/dbfile.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ func fileTimestampToTime(timestamp int64) time.Time {
215215
return time.UnixMicro(timestamp)
216216
}
217217

218-
func (f *file) loadMetaByPath() (*dbfsMeta, error) {
218+
func (f *file) loadMetaByPath() error {
219219
var fileMeta dbfsMeta
220220
if ok, err := db.GetEngine(f.ctx).Where("full_path = ?", f.fullPath).Get(&fileMeta); err != nil {
221-
return nil, err
221+
return err
222222
} else if ok {
223223
f.metaID = fileMeta.ID
224224
f.blockSize = fileMeta.BlockSize
225-
return &fileMeta, nil
226225
}
227-
return nil, nil
226+
return nil
228227
}
229228

230229
func (f *file) open(flag int) (err error) {
@@ -288,10 +287,7 @@ func (f *file) createEmpty() error {
288287
if err != nil {
289288
return err
290289
}
291-
if _, err = f.loadMetaByPath(); err != nil {
292-
return err
293-
}
294-
return nil
290+
return f.loadMetaByPath()
295291
}
296292

297293
func (f *file) truncate() error {
@@ -368,8 +364,5 @@ func buildPath(path string) string {
368364
func newDbFile(ctx context.Context, path string) (*file, error) {
369365
path = buildPath(path)
370366
f := &file{ctx: ctx, fullPath: path, blockSize: defaultFileBlockSize}
371-
if _, err := f.loadMetaByPath(); err != nil {
372-
return nil, err
373-
}
374-
return f, nil
367+
return f, f.loadMetaByPath()
375368
}

models/issues/issue_search.go

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,19 @@ func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
9999
}
100100
}
101101

102-
func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
102+
func applyLimit(sess *xorm.Session, opts *IssuesOptions) {
103103
if opts.Paginator == nil || opts.Paginator.IsListAll() {
104-
return sess
104+
return
105105
}
106106

107107
start := 0
108108
if opts.Paginator.Page > 1 {
109109
start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize
110110
}
111111
sess.Limit(opts.Paginator.PageSize, start)
112-
113-
return sess
114112
}
115113

116-
func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
114+
func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) {
117115
if len(opts.LabelIDs) > 0 {
118116
if opts.LabelIDs[0] == 0 {
119117
sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label)")
@@ -136,11 +134,9 @@ func applyLabelsCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session
136134
if len(opts.ExcludedLabelNames) > 0 {
137135
sess.And(builder.NotIn("issue.id", BuildLabelNamesIssueIDsCondition(opts.ExcludedLabelNames)))
138136
}
139-
140-
return sess
141137
}
142138

143-
func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
139+
func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) {
144140
if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == db.NoConditionID {
145141
sess.And("issue.milestone_id = 0")
146142
} else if len(opts.MilestoneIDs) > 0 {
@@ -153,11 +149,9 @@ func applyMilestoneCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sess
153149
From("milestone").
154150
Where(builder.In("name", opts.IncludeMilestones)))
155151
}
156-
157-
return sess
158152
}
159153

160-
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
154+
func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) {
161155
if opts.ProjectID > 0 { // specific project
162156
sess.Join("INNER", "project_issue", "issue.id = project_issue.issue_id").
163157
And("project_issue.project_id=?", opts.ProjectID)
@@ -166,21 +160,19 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
166160
}
167161
// opts.ProjectID == 0 means all projects,
168162
// do not need to apply any condition
169-
return sess
170163
}
171164

172-
func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
165+
func applyProjectColumnCondition(sess *xorm.Session, opts *IssuesOptions) {
173166
// opts.ProjectColumnID == 0 means all project columns,
174167
// do not need to apply any condition
175168
if opts.ProjectColumnID > 0 {
176169
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectColumnID}))
177170
} else if opts.ProjectColumnID == db.NoConditionID {
178171
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
179172
}
180-
return sess
181173
}
182174

183-
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
175+
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) {
184176
if len(opts.RepoIDs) == 1 {
185177
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
186178
} else if len(opts.RepoIDs) > 1 {
@@ -195,10 +187,9 @@ func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session
195187
if opts.RepoCond != nil {
196188
sess.And(opts.RepoCond)
197189
}
198-
return sess
199190
}
200191

201-
func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
192+
func applyConditions(sess *xorm.Session, opts *IssuesOptions) {
202193
if len(opts.IssueIDs) > 0 {
203194
sess.In("issue.id", opts.IssueIDs)
204195
}
@@ -261,8 +252,6 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
261252
if opts.User != nil {
262253
sess.And(issuePullAccessibleRepoCond("issue.repo_id", opts.User.ID, opts.Org, opts.Team, opts.IsPull.Value()))
263254
}
264-
265-
return sess
266255
}
267256

268257
// teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access
@@ -339,22 +328,22 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
339328
return cond
340329
}
341330

342-
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) *xorm.Session {
343-
return sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
331+
func applyAssigneeCondition(sess *xorm.Session, assigneeID int64) {
332+
sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
344333
And("issue_assignees.assignee_id = ?", assigneeID)
345334
}
346335

347-
func applyPosterCondition(sess *xorm.Session, posterID int64) *xorm.Session {
348-
return sess.And("issue.poster_id=?", posterID)
336+
func applyPosterCondition(sess *xorm.Session, posterID int64) {
337+
sess.And("issue.poster_id=?", posterID)
349338
}
350339

351-
func applyMentionedCondition(sess *xorm.Session, mentionedID int64) *xorm.Session {
352-
return sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
340+
func applyMentionedCondition(sess *xorm.Session, mentionedID int64) {
341+
sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
353342
And("issue_user.is_mentioned = ?", true).
354343
And("issue_user.uid = ?", mentionedID)
355344
}
356345

357-
func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) *xorm.Session {
346+
func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) {
358347
existInTeamQuery := builder.Select("team_user.team_id").
359348
From("team_user").
360349
Where(builder.Eq{"team_user.uid": reviewRequestedID})
@@ -375,11 +364,11 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64)
375364
),
376365
builder.In("review.id", maxReview),
377366
))
378-
return sess.Where("issue.poster_id <> ?", reviewRequestedID).
367+
sess.Where("issue.poster_id <> ?", reviewRequestedID).
379368
And(builder.In("issue.id", subQuery))
380369
}
381370

382-
func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session {
371+
func applyReviewedCondition(sess *xorm.Session, reviewedID int64) {
383372
// Query for pull requests where you are a reviewer or commenter, excluding
384373
// any pull requests already returned by the review requested filter.
385374
notPoster := builder.Neq{"issue.poster_id": reviewedID}
@@ -406,11 +395,11 @@ func applyReviewedCondition(sess *xorm.Session, reviewedID int64) *xorm.Session
406395
builder.In("type", CommentTypeComment, CommentTypeCode, CommentTypeReview),
407396
)),
408397
)
409-
return sess.And(notPoster, builder.Or(reviewed, commented))
398+
sess.And(notPoster, builder.Or(reviewed, commented))
410399
}
411400

412-
func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session {
413-
return sess.And(
401+
func applySubscribedCondition(sess *xorm.Session, subscriberID int64) {
402+
sess.And(
414403
builder.
415404
NotIn("issue.id",
416405
builder.Select("issue_id").

models/issues/pull_list.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type PullRequestsOptions struct {
2828
MilestoneID int64
2929
}
3030

31-
func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) (*xorm.Session, error) {
31+
func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullRequestsOptions) *xorm.Session {
3232
sess := db.GetEngine(ctx).Where("pull_request.base_repo_id=?", baseRepoID)
3333

3434
sess.Join("INNER", "issue", "pull_request.issue_id = issue.id")
@@ -46,7 +46,7 @@ func listPullRequestStatement(ctx context.Context, baseRepoID int64, opts *PullR
4646
sess.And("issue.milestone_id=?", opts.MilestoneID)
4747
}
4848

49-
return sess, nil
49+
return sess
5050
}
5151

5252
// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
@@ -130,23 +130,15 @@ func PullRequests(ctx context.Context, baseRepoID int64, opts *PullRequestsOptio
130130
opts.Page = 1
131131
}
132132

133-
countSession, err := listPullRequestStatement(ctx, baseRepoID, opts)
134-
if err != nil {
135-
log.Error("listPullRequestStatement: %v", err)
136-
return nil, 0, err
137-
}
133+
countSession := listPullRequestStatement(ctx, baseRepoID, opts)
138134
maxResults, err := countSession.Count(new(PullRequest))
139135
if err != nil {
140136
log.Error("Count PRs: %v", err)
141137
return nil, maxResults, err
142138
}
143139

144-
findSession, err := listPullRequestStatement(ctx, baseRepoID, opts)
140+
findSession := listPullRequestStatement(ctx, baseRepoID, opts)
145141
applySorts(findSession, opts.SortType, 0)
146-
if err != nil {
147-
log.Error("listPullRequestStatement: %v", err)
148-
return nil, maxResults, err
149-
}
150142
findSession = db.SetSessionPagination(findSession, opts)
151143
prs := make([]*PullRequest, 0, opts.PageSize)
152144
return prs, maxResults, findSession.Find(&prs)
@@ -200,8 +192,10 @@ func (prs PullRequestList) LoadIssues(ctx context.Context) (IssueList, error) {
200192
return nil, nil
201193
}
202194

203-
// Load issues.
204-
issueIDs := prs.GetIssueIDs()
195+
// Load issues which are not loaded
196+
issueIDs := container.FilterSlice(prs, func(pr *PullRequest) (int64, bool) {
197+
return pr.IssueID, pr.Issue == nil && pr.IssueID > 0
198+
})
205199
issues := make(map[int64]*Issue, len(issueIDs))
206200
if err := db.GetEngine(ctx).
207201
In("id", issueIDs).
@@ -237,10 +231,7 @@ func (prs PullRequestList) LoadIssues(ctx context.Context) (IssueList, error) {
237231
// GetIssueIDs returns all issue ids
238232
func (prs PullRequestList) GetIssueIDs() []int64 {
239233
return container.FilterSlice(prs, func(pr *PullRequest) (int64, bool) {
240-
if pr.Issue == nil {
241-
return pr.IssueID, pr.IssueID > 0
242-
}
243-
return 0, false
234+
return pr.IssueID, pr.IssueID > 0
244235
})
245236
}
246237

models/repo/repo_list.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -207,31 +207,6 @@ type SearchRepoOptions struct {
207207
OnlyShowRelevant bool
208208
}
209209

210-
// SearchOrderBy is used to sort the result
211-
type SearchOrderBy string
212-
213-
func (s SearchOrderBy) String() string {
214-
return string(s)
215-
}
216-
217-
// Strings for sorting result
218-
const (
219-
SearchOrderByAlphabetically SearchOrderBy = "name ASC"
220-
SearchOrderByAlphabeticallyReverse SearchOrderBy = "name DESC"
221-
SearchOrderByLeastUpdated SearchOrderBy = "updated_unix ASC"
222-
SearchOrderByRecentUpdated SearchOrderBy = "updated_unix DESC"
223-
SearchOrderByOldest SearchOrderBy = "created_unix ASC"
224-
SearchOrderByNewest SearchOrderBy = "created_unix DESC"
225-
SearchOrderBySize SearchOrderBy = "size ASC"
226-
SearchOrderBySizeReverse SearchOrderBy = "size DESC"
227-
SearchOrderByID SearchOrderBy = "id ASC"
228-
SearchOrderByIDReverse SearchOrderBy = "id DESC"
229-
SearchOrderByStars SearchOrderBy = "num_stars ASC"
230-
SearchOrderByStarsReverse SearchOrderBy = "num_stars DESC"
231-
SearchOrderByForks SearchOrderBy = "num_forks ASC"
232-
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
233-
)
234-
235210
// UserOwnedRepoCond returns user ownered repositories
236211
func UserOwnedRepoCond(userID int64) builder.Cond {
237212
return builder.Eq{

0 commit comments

Comments
 (0)