Skip to content

Commit eed565f

Browse files
committed
Merge remote-tracking branch 'origin/main' into cmpzero
* origin/main: Remove fomantic table module (go-gitea#30047) Fix menu buttons in issues and release (go-gitea#30056) Fix git grep search limit, add test (go-gitea#30071) Fix button hover border (go-gitea#30048) Fix Add/Remove WIP on pull request title failure (go-gitea#29999) Fix misuse of `TxContext` (go-gitea#30061) Remove jQuery `.attr` from the reaction selector (go-gitea#30052) Remove jQuery `.attr` from the ComboMarkdownEditor (go-gitea#30051) Remove jQuery `.attr` from the label edit exclusive checkbox (go-gitea#30053) Remove jQuery `.attr` from the repository topic bar (go-gitea#30050) Use db.ListOptions directly instead of Paginator interface to make it easier to use and fix performance of /pulls and /issues (go-gitea#29990) Migrate `gt-hidden` to `tw-hidden` (go-gitea#30046) Forbid jQuery `is` and fix issues (go-gitea#30016) Remove fomantic segment module (go-gitea#30042) Migrate margin and padding helpers to tailwind (go-gitea#30043)
2 parents 72f394e + f73d891 commit eed565f

File tree

246 files changed

+1579
-3215
lines changed

Some content is hidden

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

246 files changed

+1579
-3215
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ rules:
303303
jquery/no-in-array: [2]
304304
jquery/no-is-array: [2]
305305
jquery/no-is-function: [2]
306-
jquery/no-is: [0]
306+
jquery/no-is: [2]
307307
jquery/no-load: [2]
308308
jquery/no-map: [2]
309309
jquery/no-merge: [2]
@@ -440,7 +440,7 @@ rules:
440440
no-jquery/no-is-numeric: [2]
441441
no-jquery/no-is-plain-object: [2]
442442
no-jquery/no-is-window: [2]
443-
no-jquery/no-is: [0]
443+
no-jquery/no-is: [2]
444444
no-jquery/no-jquery-constructor: [0]
445445
no-jquery/no-live: [2]
446446
no-jquery/no-load-shorthand: [2]

docs/content/contributing/guidelines-frontend.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ However, there are still some special cases, so the current guideline is:
118118
### Show/Hide Elements
119119

120120
* Vue components are recommended to use `v-if` and `v-show` to show/hide elements.
121-
* Go template code should use Gitea's `.gt-hidden` and `showElem()/hideElem()/toggleElem()`, see more details in `.gt-hidden`'s comment.
121+
* Go template code should use `.tw-hidden` and `showElem()/hideElem()/toggleElem()`, see more details in `.tw-hidden`'s comment.
122122

123123
### Styles and Attributes in Go HTML Template
124124

docs/content/contributing/guidelines-frontend.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Gitea 使用一些补丁使 Fomantic UI 更具可访问性(参见 `aria.md`)
117117
### 显示/隐藏元素
118118

119119
* 推荐在Vue组件中使用`v-if``v-show`来显示/隐藏元素。
120-
* Go 模板代码应使用 Gitea 的 `.gt-hidden``showElem()/hideElem()/toggleElem()` 来显示/隐藏元素,请参阅`.gt-hidden`的注释以获取更多详细信息。
120+
* Go 模板代码应使用 `.tw-hidden``showElem()/hideElem()/toggleElem()` 来显示/隐藏元素,请参阅`.tw-hidden`的注释以获取更多详细信息。
121121

122122
### Go HTML 模板中的样式和属性
123123

models/db/context.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ func (c *halfCommitter) Close() error {
120120

121121
// TxContext represents a transaction Context,
122122
// it will reuse the existing transaction in the parent context or create a new one.
123+
// Some tips to use:
124+
//
125+
// 1 It's always recommended to use `WithTx` in new code instead of `TxContext`, since `WithTx` will handle the transaction automatically.
126+
// 2. To maintain the old code which uses `TxContext`:
127+
// a. Always call `Close()` before returning regardless of whether `Commit()` has been called.
128+
// b. Always call `Commit()` before returning if there are no errors, even if the code did not change any data.
129+
// c. Remember the `Committer` will be a halfCommitter when a transaction is being reused.
130+
// So calling `Commit()` will do nothing, but calling `Close()` without calling `Commit()` will rollback the transaction.
131+
// And all operations submitted by the caller stack will be rollbacked as well, not only the operations in the current function.
132+
// d. It doesn't mean rollback is forbidden, but always do it only when there is an error, and you do want to rollback.
123133
func TxContext(parentCtx context.Context) (*Context, Committer, error) {
124134
if sess, ok := inTransaction(parentCtx); ok {
125135
return newContext(parentCtx, sess, true), &halfCommitter{committer: sess}, nil

models/issues/issue_search.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
// IssuesOptions represents options of an issue.
2323
type IssuesOptions struct { //nolint
24-
db.Paginator
24+
Paginator *db.ListOptions
2525
RepoIDs []int64 // overwrites RepoCond if the length is not 0
2626
AllPublic bool // include also all public repositories
2727
RepoCond builder.Cond
@@ -104,23 +104,11 @@ func applyLimit(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
104104
return sess
105105
}
106106

107-
// Warning: Do not use GetSkipTake() for *db.ListOptions
108-
// Its implementation could reset the page size with setting.API.MaxResponseItems
109-
if listOptions, ok := opts.Paginator.(*db.ListOptions); ok {
110-
if listOptions.Page >= 0 && listOptions.PageSize > 0 {
111-
var start int
112-
if listOptions.Page == 0 {
113-
start = 0
114-
} else {
115-
start = (listOptions.Page - 1) * listOptions.PageSize
116-
}
117-
sess.Limit(listOptions.PageSize, start)
118-
}
119-
return sess
107+
start := 0
108+
if opts.Paginator.Page > 1 {
109+
start = (opts.Paginator.Page - 1) * opts.Paginator.PageSize
120110
}
121-
122-
start, limit := opts.Paginator.GetSkipTake()
123-
sess.Limit(limit, start)
111+
sess.Limit(opts.Paginator.PageSize, start)
124112

125113
return sess
126114
}

models/issues/issue_stats.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ func CountIssuesByRepo(ctx context.Context, opts *IssuesOptions) (map[int64]int6
6868
}
6969

7070
// CountIssues number return of issues by given conditions.
71-
func CountIssues(ctx context.Context, opts *IssuesOptions) (int64, error) {
71+
func CountIssues(ctx context.Context, opts *IssuesOptions, otherConds ...builder.Cond) (int64, error) {
7272
sess := db.GetEngine(ctx).
7373
Select("COUNT(issue.id) AS count").
7474
Table("issue").
7575
Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
7676
applyConditions(sess, opts)
7777

78+
for _, cond := range otherConds {
79+
sess.And(cond)
80+
}
81+
7882
return sess.Count()
7983
}
8084

models/issues/review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
620620

621621
// skip it when reviewer hase been request to review
622622
if review != nil && review.Type == ReviewTypeRequest {
623-
return nil, nil
623+
return nil, committer.Commit() // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction.
624624
}
625625

626626
// if the reviewer is an official reviewer,

modules/git/grep.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type GrepResult struct {
2424

2525
type GrepOptions struct {
2626
RefName string
27+
MaxResultLimit int
2728
ContextLineNumber int
2829
IsFuzzy bool
2930
}
@@ -59,6 +60,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
5960
cmd.AddOptionValues("-e", strings.TrimLeft(search, "-"))
6061
}
6162
cmd.AddDynamicArguments(util.IfZero(opts.RefName, "HEAD"))
63+
opts.MaxResultLimit = util.IfZero(opts.MaxResultLimit, 50)
6264
stderr := bytes.Buffer{}
6365
err = cmd.Run(&RunOpts{
6466
Dir: repo.Path,
@@ -82,7 +84,7 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
8284
continue
8385
}
8486
if line == "" {
85-
if len(results) >= 50 {
87+
if len(results) >= opts.MaxResultLimit {
8688
cancel()
8789
break
8890
}
@@ -101,6 +103,10 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
101103
return scanner.Err()
102104
},
103105
})
106+
// git grep exits by cancel (killed), usually it is caused by the limit of results
107+
if IsErrorExitCode(err, -1) && stderr.Len() == 0 {
108+
return results, nil
109+
}
104110
// git grep exits with 1 if no results are found
105111
if IsErrorExitCode(err, 1) && stderr.Len() == 0 {
106112
return nil, nil

modules/git/grep_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ func TestGrepSearch(t *testing.T) {
3131
},
3232
}, res)
3333

34+
res, err = GrepSearch(context.Background(), repo, "void", GrepOptions{MaxResultLimit: 1})
35+
assert.NoError(t, err)
36+
assert.Equal(t, []*GrepResult{
37+
{
38+
Filename: "java-hello/main.java",
39+
LineNumbers: []int{3},
40+
LineCodes: []string{" public static void main(String[] args)"},
41+
},
42+
}, res)
43+
3444
res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
3545
assert.NoError(t, err)
3646
assert.Len(t, res, 0)

modules/indexer/internal/paginator.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// ParsePaginator parses a db.Paginator into a skip and limit
13-
func ParsePaginator(paginator db.Paginator, max ...int) (int, int) {
13+
func ParsePaginator(paginator *db.ListOptions, max ...int) (int, int) {
1414
// Use a very large number to indicate no limit
1515
unlimited := math.MaxInt32
1616
if len(max) > 0 {
@@ -19,22 +19,15 @@ func ParsePaginator(paginator db.Paginator, max ...int) (int, int) {
1919
}
2020

2121
if paginator == nil || paginator.IsListAll() {
22+
// It shouldn't happen. In actual usage scenarios, there should not be requests to search all.
23+
// But if it does happen, respect it and return "unlimited".
24+
// And it's also useful for testing.
2225
return 0, unlimited
2326
}
2427

25-
// Warning: Do not use GetSkipTake() for *db.ListOptions
26-
// Its implementation could reset the page size with setting.API.MaxResponseItems
27-
if listOptions, ok := paginator.(*db.ListOptions); ok {
28-
if listOptions.Page >= 0 && listOptions.PageSize > 0 {
29-
var start int
30-
if listOptions.Page == 0 {
31-
start = 0
32-
} else {
33-
start = (listOptions.Page - 1) * listOptions.PageSize
34-
}
35-
return start, listOptions.PageSize
36-
}
37-
return 0, unlimited
28+
if paginator.PageSize == 0 {
29+
// Do not return any results when searching, it's used to get the total count only.
30+
return 0, 0
3831
}
3932

4033
return paginator.GetSkipTake()

0 commit comments

Comments
 (0)