Skip to content

Commit 207fc43

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: (28 commits) Enable a few stylelint rules (go-gitea#30038) Remove remaining jQuery .css code (go-gitea#30015) Respect DEFAULT_ORG_MEMBER_VISIBLE setting when adding creator to org (go-gitea#30013) Remove jQuery `.attr` from the common global functions (go-gitea#30023) Migrate font-size helpers to tailwind (go-gitea#30029) Replace all simple inline styles with tailwind (go-gitea#30032) Migrate font-weight helpers to tailwind (go-gitea#30027) Remove jQuery from the issue "go to" button (go-gitea#30028) Determine fuzziness of bleve indexer by keyword length (go-gitea#29706) Escape paths for find file correctly (go-gitea#30026) Remove jQuery `.attr` from the diff page (go-gitea#30021) Remove jQuery `.attr` from the repository settings (go-gitea#30018) Remove jQuery `.attr` from the image diff again (go-gitea#30022) Introduce `.secondary-nav` and handle `.page-content` spacing universally (go-gitea#29982) Remove jQuery `.attr` from the branch/tag selector (go-gitea#30010) Remove jQuery `.attr` from the commit graph (go-gitea#30006) Remove jQuery from the citation modal (except fomantic) (go-gitea#30008) Remove jQuery `.attr` from the project page (go-gitea#30004) Fix incorrect tailwind migration (go-gitea#30007) Enforce trailing comma in JS on multiline (go-gitea#30002) ...
2 parents 3597d77 + 9c6e6f4 commit 207fc43

File tree

231 files changed

+1007
-1578
lines changed

Some content is hidden

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

231 files changed

+1007
-1578
lines changed

.eslintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ rules:
119119
"@stylistic/js/arrow-spacing": [2, {before: true, after: true}]
120120
"@stylistic/js/block-spacing": [0]
121121
"@stylistic/js/brace-style": [2, 1tbs, {allowSingleLine: true}]
122-
"@stylistic/js/comma-dangle": [2, only-multiline]
122+
"@stylistic/js/comma-dangle": [2, always-multiline]
123123
"@stylistic/js/comma-spacing": [2, {before: false, after: true}]
124124
"@stylistic/js/comma-style": [2, last]
125125
"@stylistic/js/computed-property-spacing": [2, never]

.stylelintrc.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rules:
3030
"@stylistic/block-opening-brace-newline-after": null
3131
"@stylistic/block-opening-brace-newline-before": null
3232
"@stylistic/block-opening-brace-space-after": null
33-
"@stylistic/block-opening-brace-space-before": null
33+
"@stylistic/block-opening-brace-space-before": always
3434
"@stylistic/color-hex-case": lower
3535
"@stylistic/declaration-bang-space-after": never
3636
"@stylistic/declaration-bang-space-before": null
@@ -140,7 +140,7 @@ rules:
140140
function-disallowed-list: null
141141
function-linear-gradient-no-nonstandard-direction: true
142142
function-name-case: lower
143-
function-no-unknown: null
143+
function-no-unknown: true
144144
function-url-no-scheme-relative: null
145145
function-url-quotes: always
146146
function-url-scheme-allowed-list: null
@@ -168,7 +168,7 @@ rules:
168168
no-duplicate-selectors: true
169169
no-empty-source: true
170170
no-invalid-double-slash-comments: true
171-
no-invalid-position-at-import-rule: null
171+
no-invalid-position-at-import-rule: [true, ignoreAtRules: [tailwind]]
172172
no-irregular-whitespace: true
173173
no-unknown-animations: null
174174
no-unknown-custom-properties: null
@@ -181,6 +181,7 @@ rules:
181181
rule-empty-line-before: null
182182
rule-selector-property-disallowed-list: null
183183
scale-unlimited/declaration-strict-value: [[/color$/, font-weight], {ignoreValues: /^(inherit|transparent|unset|initial|currentcolor|none)$/, ignoreFunctions: false, disableFix: true, expandShorthand: true}]
184+
selector-anb-no-unmatchable: true
184185
selector-attribute-name-disallowed-list: null
185186
selector-attribute-operator-allowed-list: null
186187
selector-attribute-operator-disallowed-list: null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
4747
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
4848
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
4949
11. Custom event names are recommended to use `ce-` prefix.
50-
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-df`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
50+
12. Prefer using Tailwind CSS which is available via `tw-` prefix, e.g. `tw-relative`. Gitea's helper CSS classes use `gt-` prefix (`gt-mono`), while Gitea's own private framework-level CSS classes use `g-` prefix (`g-modal-confirm`).
5151
13. Avoid inline scripts & styles as much as possible, it's recommended to put JS code into JS files and use CSS classes. If inline scripts & styles are unavoidable, explain the reason why it can't be avoided.
5252

5353
### Accessibility / ARIA

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ HTML 页面由[Go HTML Template](https://pkg.go.dev/html/template)渲染。
4747
9. 避免在 CSS 中使用不必要的`!important`,如果无法避免,添加注释解释为什么需要它。
4848
10. 避免在一个事件监听器中混合不同的事件,优先为每个事件使用独立的事件监听器。
4949
11. 推荐使用自定义事件名称前缀`ce-`
50-
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-df`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
50+
12. 建议使用 Tailwind CSS,它可以通过 `tw-` 前缀获得,例如 `tw-relative`. Gitea 自身的助手类 CSS 使用 `gt-` 前缀(`gt-mono`),Gitea 自身的私有框架级 CSS 类使用 `g-` 前缀(`g-modal-confirm`)。
5151
13. 尽量避免内联脚本和样式,建议将JS代码放入JS文件中并使用CSS类。如果内联脚本和样式不可避免,请解释无法避免的原因。
5252

5353
### 可访问性 / ARIA

models/asymkey/ssh_key_authorized_keys.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
139139
if err != nil {
140140
return err
141141
}
142+
defer f.Close()
143+
142144
scanner := bufio.NewScanner(f)
143145
for scanner.Scan() {
144146
line := scanner.Text()
@@ -148,15 +150,12 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
148150
}
149151
_, err = t.WriteString(line + "\n")
150152
if err != nil {
151-
f.Close()
152153
return err
153154
}
154155
}
155-
err = scanner.Err()
156-
if err != nil {
157-
return fmt.Errorf("scan: %w", err)
156+
if err = scanner.Err(); err != nil {
157+
return fmt.Errorf("RegeneratePublicKeys scan: %w", err)
158158
}
159-
f.Close()
160159
}
161160
return nil
162161
}

models/avatars/avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
const (
2626
// DefaultAvatarClass is the default class of a rendered avatar
27-
DefaultAvatarClass = "ui avatar gt-vm"
27+
DefaultAvatarClass = "ui avatar tw-align-middle"
2828
// DefaultAvatarPixelSize is the default size in pixels of a rendered avatar
2929
DefaultAvatarPixelSize = 28
3030
)

models/organization/org.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ func CreateOrganization(ctx context.Context, org *Organization, owner *user_mode
319319

320320
// Add initial creator to organization and owner team.
321321
if err = db.Insert(ctx, &OrgUser{
322-
UID: owner.ID,
323-
OrgID: org.ID,
322+
UID: owner.ID,
323+
OrgID: org.ID,
324+
IsPublic: setting.Service.DefaultOrgMemberVisible,
324325
}); err != nil {
325326
return fmt.Errorf("insert org-user relation: %w", err)
326327
}

modules/actions/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func ReadLogs(ctx context.Context, inStorage bool, filename string, offset, limi
100100
}
101101

102102
if err := scanner.Err(); err != nil {
103-
return nil, fmt.Errorf("scan: %w", err)
103+
return nil, fmt.Errorf("ReadLogs scan: %w", err)
104104
}
105105

106106
return rows, nil

modules/git/commit.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,8 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
397397
}
398398
}
399399
}
400-
err = scanner.Err()
401-
if err != nil {
402-
return nil, fmt.Errorf("scan: %w", err)
400+
if err = scanner.Err(); err != nil {
401+
return nil, fmt.Errorf("GetSubModules scan: %w", err)
403402
}
404403

405404
return c.submoduleCache, nil

modules/git/repo_stats.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
124124
}
125125
}
126126
}
127-
err = scanner.Err()
128-
if err != nil {
129-
return fmt.Errorf("scan: %w", err)
127+
if err = scanner.Err(); err != nil {
128+
_ = stdoutReader.Close()
129+
return fmt.Errorf("GetCodeActivityStats scan: %w", err)
130130
}
131131
a := make([]*CodeActivityAuthor, 0, len(authors))
132132
for _, v := range authors {

modules/indexer/code/bleve/bleve.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
const (
4040
unicodeNormalizeName = "unicodeNormalize"
4141
maxBatchSize = 16
42+
// fuzzyDenominator determines the levenshtein distance per each character of a keyword
43+
fuzzyDenominator = 4
4244
)
4345

4446
func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error {
@@ -239,15 +241,12 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
239241
keywordQuery query.Query
240242
)
241243

244+
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
245+
phraseQuery.FieldVal = "Content"
246+
phraseQuery.Analyzer = repoIndexerAnalyzer
247+
keywordQuery = phraseQuery
242248
if opts.IsKeywordFuzzy {
243-
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
244-
phraseQuery.FieldVal = "Content"
245-
phraseQuery.Analyzer = repoIndexerAnalyzer
246-
keywordQuery = phraseQuery
247-
} else {
248-
prefixQuery := bleve.NewPrefixQuery(opts.Keyword)
249-
prefixQuery.FieldVal = "Content"
250-
keywordQuery = prefixQuery
249+
phraseQuery.Fuzziness = len(opts.Keyword) / fuzzyDenominator
251250
}
252251

253252
if len(opts.RepoIDs) > 0 {

modules/indexer/internal/bleve/query.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ func NumericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
2020
}
2121

2222
// MatchPhraseQuery generates a match phrase query for the given phrase, field and analyzer
23-
func MatchPhraseQuery(matchPhrase, field, analyzer string) *query.MatchPhraseQuery {
23+
func MatchPhraseQuery(matchPhrase, field, analyzer string, fuzziness int) *query.MatchPhraseQuery {
2424
q := bleve.NewMatchPhraseQuery(matchPhrase)
2525
q.FieldVal = field
2626
q.Analyzer = analyzer
27-
return q
28-
}
29-
30-
// PrefixQuery generates a match prefix query for the given prefix and field
31-
func PrefixQuery(matchPrefix, field string) *query.PrefixQuery {
32-
q := bleve.NewPrefixQuery(matchPrefix)
33-
q.FieldVal = field
27+
q.Fuzziness = fuzziness
3428
return q
3529
}
3630

modules/indexer/issues/bleve/bleve.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error {
3535
})
3636
}
3737

38-
const maxBatchSize = 16
38+
const (
39+
maxBatchSize = 16
40+
// fuzzyDenominator determines the levenshtein distance per each character of a keyword
41+
fuzzyDenominator = 4
42+
)
3943

4044
// IndexerData an update to the issue indexer
4145
type IndexerData internal.IndexerData
@@ -156,19 +160,16 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
156160
var queries []query.Query
157161

158162
if options.Keyword != "" {
163+
fuzziness := 0
159164
if options.IsFuzzyKeyword {
160-
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
161-
inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer),
162-
inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer),
163-
inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer),
164-
}...))
165-
} else {
166-
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
167-
inner_bleve.PrefixQuery(options.Keyword, "title"),
168-
inner_bleve.PrefixQuery(options.Keyword, "content"),
169-
inner_bleve.PrefixQuery(options.Keyword, "comments"),
170-
}...))
165+
fuzziness = len(options.Keyword) / fuzzyDenominator
171166
}
167+
168+
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
169+
inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer, fuzziness),
170+
inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer, fuzziness),
171+
inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer, fuzziness),
172+
}...))
172173
}
173174

174175
if len(options.RepoIDs) > 0 || options.AllPublic {

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

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -515,10 +515,8 @@ var cases = []*testIndexerCase{
515515
{
516516
Name: "SortByCreatedDesc",
517517
SearchOptions: &internal.SearchOptions{
518-
Paginator: &db.ListOptions{
519-
ListAll: true,
520-
},
521-
SortBy: internal.SortByCreatedDesc,
518+
Paginator: &db.ListOptionsAll,
519+
SortBy: internal.SortByCreatedDesc,
522520
},
523521
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
524522
assert.Equal(t, len(data), len(result.Hits))
@@ -533,10 +531,8 @@ var cases = []*testIndexerCase{
533531
{
534532
Name: "SortByUpdatedDesc",
535533
SearchOptions: &internal.SearchOptions{
536-
Paginator: &db.ListOptions{
537-
ListAll: true,
538-
},
539-
SortBy: internal.SortByUpdatedDesc,
534+
Paginator: &db.ListOptionsAll,
535+
SortBy: internal.SortByUpdatedDesc,
540536
},
541537
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
542538
assert.Equal(t, len(data), len(result.Hits))
@@ -551,10 +547,8 @@ var cases = []*testIndexerCase{
551547
{
552548
Name: "SortByCommentsDesc",
553549
SearchOptions: &internal.SearchOptions{
554-
Paginator: &db.ListOptions{
555-
ListAll: true,
556-
},
557-
SortBy: internal.SortByCommentsDesc,
550+
Paginator: &db.ListOptionsAll,
551+
SortBy: internal.SortByCommentsDesc,
558552
},
559553
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
560554
assert.Equal(t, len(data), len(result.Hits))
@@ -569,10 +563,8 @@ var cases = []*testIndexerCase{
569563
{
570564
Name: "SortByDeadlineDesc",
571565
SearchOptions: &internal.SearchOptions{
572-
Paginator: &db.ListOptions{
573-
ListAll: true,
574-
},
575-
SortBy: internal.SortByDeadlineDesc,
566+
Paginator: &db.ListOptionsAll,
567+
SortBy: internal.SortByDeadlineDesc,
576568
},
577569
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
578570
assert.Equal(t, len(data), len(result.Hits))
@@ -587,10 +579,8 @@ var cases = []*testIndexerCase{
587579
{
588580
Name: "SortByCreatedAsc",
589581
SearchOptions: &internal.SearchOptions{
590-
Paginator: &db.ListOptions{
591-
ListAll: true,
592-
},
593-
SortBy: internal.SortByCreatedAsc,
582+
Paginator: &db.ListOptionsAll,
583+
SortBy: internal.SortByCreatedAsc,
594584
},
595585
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
596586
assert.Equal(t, len(data), len(result.Hits))
@@ -605,10 +595,8 @@ var cases = []*testIndexerCase{
605595
{
606596
Name: "SortByUpdatedAsc",
607597
SearchOptions: &internal.SearchOptions{
608-
Paginator: &db.ListOptions{
609-
ListAll: true,
610-
},
611-
SortBy: internal.SortByUpdatedAsc,
598+
Paginator: &db.ListOptionsAll,
599+
SortBy: internal.SortByUpdatedAsc,
612600
},
613601
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
614602
assert.Equal(t, len(data), len(result.Hits))
@@ -623,10 +611,8 @@ var cases = []*testIndexerCase{
623611
{
624612
Name: "SortByCommentsAsc",
625613
SearchOptions: &internal.SearchOptions{
626-
Paginator: &db.ListOptions{
627-
ListAll: true,
628-
},
629-
SortBy: internal.SortByCommentsAsc,
614+
Paginator: &db.ListOptionsAll,
615+
SortBy: internal.SortByCommentsAsc,
630616
},
631617
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
632618
assert.Equal(t, len(data), len(result.Hits))
@@ -641,10 +627,8 @@ var cases = []*testIndexerCase{
641627
{
642628
Name: "SortByDeadlineAsc",
643629
SearchOptions: &internal.SearchOptions{
644-
Paginator: &db.ListOptions{
645-
ListAll: true,
646-
},
647-
SortBy: internal.SortByDeadlineAsc,
630+
Paginator: &db.ListOptionsAll,
631+
SortBy: internal.SortByDeadlineAsc,
648632
},
649633
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
650634
assert.Equal(t, len(data), len(result.Hits))

modules/indexer/issues/util.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
6161
)
6262
{
6363
reviews, err := issue_model.FindReviews(ctx, issue_model.FindReviewOptions{
64-
ListOptions: db.ListOptions{
65-
ListAll: true,
66-
},
64+
ListOptions: db.ListOptionsAll,
6765
IssueID: issueID,
6866
OfficialOnly: false,
6967
})

modules/markup/csv/csv.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
124124
return err
125125
}
126126
}
127-
err = scan.Err()
128-
if err != nil {
129-
return fmt.Errorf("scan: %w", err)
127+
if err = scan.Err(); err != nil {
128+
return fmt.Errorf("fallbackRender scan: %w", err)
130129
}
131130

132131
_, err = tmpBlock.WriteString("</pre>")

0 commit comments

Comments
 (0)