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()

modules/indexer/issues/db/db.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
7878
return nil, err
7979
}
8080

81+
// If pagesize == 0, return total count only. It's a special case for search count.
82+
if options.Paginator != nil && options.Paginator.PageSize == 0 {
83+
total, err := issue_model.CountIssues(ctx, opt, cond)
84+
if err != nil {
85+
return nil, err
86+
}
87+
return &internal.SearchResult{
88+
Total: total,
89+
}, nil
90+
}
91+
8192
ids, total, err := issue_model.IssueIDs(ctx, opt, cond)
8293
if err != nil {
8394
return nil, err

modules/indexer/issues/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, err
308308

309309
// CountIssues counts issues by options. It is a shortcut of SearchIssues(ctx, opts) but only returns the total count.
310310
func CountIssues(ctx context.Context, opts *SearchOptions) (int64, error) {
311-
opts = opts.Copy(func(options *SearchOptions) { opts.Paginator = &db_model.ListOptions{PageSize: 0} })
311+
opts = opts.Copy(func(options *SearchOptions) { options.Paginator = &db_model.ListOptions{PageSize: 0} })
312312

313313
_, total, err := SearchIssues(ctx, opts)
314314
return total, err

modules/indexer/issues/internal/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type SearchOptions struct {
106106
UpdatedAfterUnix optional.Option[int64]
107107
UpdatedBeforeUnix optional.Option[int64]
108108

109-
db.Paginator
109+
Paginator *db.ListOptions
110110

111111
SortBy SortBy // sort by field
112112
}

modules/indexer/issues/internal/tests/tests.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ func TestIndexer(t *testing.T, indexer internal.Indexer) {
7777
assert.Equal(t, c.ExpectedIDs, ids)
7878
assert.Equal(t, c.ExpectedTotal, result.Total)
7979
}
80+
81+
// test counting
82+
c.SearchOptions.Paginator = &db.ListOptions{PageSize: 0}
83+
countResult, err := indexer.Search(context.Background(), c.SearchOptions)
84+
require.NoError(t, err)
85+
assert.Empty(t, countResult.Hits)
86+
assert.Equal(t, result.Total, countResult.Total)
8087
})
8188
}
8289
}

modules/indexer/issues/meilisearch/meilisearch.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
218218

219219
skip, limit := indexer_internal.ParsePaginator(options.Paginator, maxTotalHits)
220220

221+
counting := limit == 0
222+
if counting {
223+
// If set limit to 0, it will be 20 by default, and -1 is not allowed.
224+
// See https://www.meilisearch.com/docs/reference/api/search#limit
225+
// So set limit to 1 to make the cost as low as possible, then clear the result before returning.
226+
limit = 1
227+
}
228+
221229
keyword := options.Keyword
222230
if !options.IsFuzzyKeyword {
223231
// to make it non fuzzy ("typo tolerance" in meilisearch terms), we have to quote the keyword(s)
@@ -236,6 +244,10 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
236244
return nil, err
237245
}
238246

247+
if counting {
248+
searchRes.Hits = nil
249+
}
250+
239251
hits, err := convertHits(searchRes)
240252
if err != nil {
241253
return nil, err

routers/web/repo/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames
280280
if commit.User != nil {
281281
avatar = string(avatarUtils.Avatar(commit.User, 18))
282282
} else {
283-
avatar = string(avatarUtils.AvatarByEmail(commit.Author.Email, commit.Author.Name, 18, "gt-mr-3"))
283+
avatar = string(avatarUtils.AvatarByEmail(commit.Author.Email, commit.Author.Name, 18, "tw-mr-2"))
284284
}
285285

286286
br.Avatar = gotemplate.HTML(avatar)

routers/web/repo/issue_content_history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func GetContentHistoryList(ctx *context.Context) {
7070
}
7171

7272
src := html.EscapeString(item.UserAvatarLink)
73-
class := avatars.DefaultAvatarClass + " gt-mr-3"
73+
class := avatars.DefaultAvatarClass + " tw-mr-2"
7474
name := html.EscapeString(username)
7575
avatarHTML := string(templates.AvatarHTML(src, 28, class, username))
7676
timeSinceText := string(timeutil.TimeSinceUnix(item.EditedUnix, ctx.Locale))

routers/web/repo/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,9 @@ func prepareOpenWithEditorApps(ctx *context.Context) {
919919
schema, _, _ := strings.Cut(app.OpenURL, ":")
920920
var iconHTML template.HTML
921921
if schema == "vscode" || schema == "vscodium" || schema == "jetbrains" {
922-
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-%s", schema), 16, "gt-mr-3")
922+
iconHTML = svg.RenderHTML(fmt.Sprintf("gitea-%s", schema), 16, "tw-mr-2")
923923
} else {
924-
iconHTML = svg.RenderHTML("gitea-git", 16, "gt-mr-3") // TODO: it could support user's customized icon in the future
924+
iconHTML = svg.RenderHTML("gitea-git", 16, "tw-mr-2") // TODO: it could support user's customized icon in the future
925925
}
926926
tmplApps = append(tmplApps, map[string]any{
927927
"DisplayName": app.DisplayName,

services/auth/source/oauth2/providers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (p *AuthSourceProvider) DisplayName() string {
5959

6060
func (p *AuthSourceProvider) IconHTML(size int) template.HTML {
6161
if p.iconURL != "" {
62-
img := fmt.Sprintf(`<img class="tw-object-contain gt-mr-3" width="%d" height="%d" src="%s" alt="%s">`,
62+
img := fmt.Sprintf(`<img class="tw-object-contain tw-mr-2" width="%d" height="%d" src="%s" alt="%s">`,
6363
size,
6464
size,
6565
html.EscapeString(p.iconURL), html.EscapeString(p.DisplayName()),

services/auth/source/oauth2/providers_base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func (b *BaseProvider) IconHTML(size int) template.HTML {
3535
case "github":
3636
svgName = "octicon-mark-github"
3737
}
38-
svgHTML := svg.RenderHTML(svgName, size, "gt-mr-3")
38+
svgHTML := svg.RenderHTML(svgName, size, "tw-mr-2")
3939
if svgHTML == "" {
4040
log.Error("No SVG icon for oauth2 provider %q", b.name)
41-
svgHTML = svg.RenderHTML("gitea-openid", size, "gt-mr-3")
41+
svgHTML = svg.RenderHTML("gitea-openid", size, "tw-mr-2")
4242
}
4343
return svgHTML
4444
}

services/auth/source/oauth2/providers_openid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (o *OpenIDProvider) DisplayName() string {
2929

3030
// IconHTML returns icon HTML for this provider
3131
func (o *OpenIDProvider) IconHTML(size int) template.HTML {
32-
return svg.RenderHTML("gitea-openid", size, "gt-mr-3")
32+
return svg.RenderHTML("gitea-openid", size, "tw-mr-2")
3333
}
3434

3535
// CreateGothProvider creates a GothProvider from this Provider

services/issue/issue.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
user_model "code.gitea.io/gitea/models/user"
1818
"code.gitea.io/gitea/modules/container"
1919
"code.gitea.io/gitea/modules/git"
20+
"code.gitea.io/gitea/modules/log"
2021
"code.gitea.io/gitea/modules/storage"
2122
notify_service "code.gitea.io/gitea/services/notify"
2223
)
@@ -85,23 +86,17 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode
8586
}
8687
}
8788

88-
var reviewNotifers []*ReviewRequestNotifier
89-
90-
if err := db.WithTx(ctx, func(ctx context.Context) error {
91-
if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
92-
return err
93-
}
89+
if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil {
90+
return err
91+
}
9492

95-
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
96-
var err error
97-
reviewNotifers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest)
98-
if err != nil {
99-
return err
100-
}
93+
var reviewNotifers []*ReviewRequestNotifier
94+
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
95+
var err error
96+
reviewNotifers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest)
97+
if err != nil {
98+
log.Error("PullRequestCodeOwnersReview: %v", err)
10199
}
102-
return nil
103-
}); err != nil {
104-
return err
105100
}
106101

107102
notify_service.IssueChangeTitle(ctx, doer, issue, oldTitle)

0 commit comments

Comments
 (0)