Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* 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)
  ...
  • Loading branch information
zjjhot committed Mar 24, 2024
2 parents 3597d77 + 9c6e6f4 commit 207fc43
Show file tree
Hide file tree
Showing 231 changed files with 1,007 additions and 1,578 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ rules:
"@stylistic/js/arrow-spacing": [2, {before: true, after: true}]
"@stylistic/js/block-spacing": [0]
"@stylistic/js/brace-style": [2, 1tbs, {allowSingleLine: true}]
"@stylistic/js/comma-dangle": [2, only-multiline]
"@stylistic/js/comma-dangle": [2, always-multiline]
"@stylistic/js/comma-spacing": [2, {before: false, after: true}]
"@stylistic/js/comma-style": [2, last]
"@stylistic/js/computed-property-spacing": [2, never]
Expand Down
7 changes: 4 additions & 3 deletions .stylelintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rules:
"@stylistic/block-opening-brace-newline-after": null
"@stylistic/block-opening-brace-newline-before": null
"@stylistic/block-opening-brace-space-after": null
"@stylistic/block-opening-brace-space-before": null
"@stylistic/block-opening-brace-space-before": always
"@stylistic/color-hex-case": lower
"@stylistic/declaration-bang-space-after": never
"@stylistic/declaration-bang-space-before": null
Expand Down Expand Up @@ -140,7 +140,7 @@ rules:
function-disallowed-list: null
function-linear-gradient-no-nonstandard-direction: true
function-name-case: lower
function-no-unknown: null
function-no-unknown: true
function-url-no-scheme-relative: null
function-url-quotes: always
function-url-scheme-allowed-list: null
Expand Down Expand Up @@ -168,7 +168,7 @@ rules:
no-duplicate-selectors: true
no-empty-source: true
no-invalid-double-slash-comments: true
no-invalid-position-at-import-rule: null
no-invalid-position-at-import-rule: [true, ignoreAtRules: [tailwind]]
no-irregular-whitespace: true
no-unknown-animations: null
no-unknown-custom-properties: null
Expand All @@ -181,6 +181,7 @@ rules:
rule-empty-line-before: null
rule-selector-property-disallowed-list: null
scale-unlimited/declaration-strict-value: [[/color$/, font-weight], {ignoreValues: /^(inherit|transparent|unset|initial|currentcolor|none)$/, ignoreFunctions: false, disableFix: true, expandShorthand: true}]
selector-anb-no-unmatchable: true
selector-attribute-name-disallowed-list: null
selector-attribute-operator-allowed-list: null
selector-attribute-operator-disallowed-list: null
Expand Down
2 changes: 1 addition & 1 deletion docs/content/contributing/guidelines-frontend.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ We recommend [Google HTML/CSS Style Guide](https://google.github.io/styleguide/h
9. Avoid unnecessary `!important` in CSS, add comments to explain why it's necessary if it can't be avoided.
10. Avoid mixing different events in one event listener, prefer to use individual event listeners for every event.
11. Custom event names are recommended to use `ce-` prefix.
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`).
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`).
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.

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

### 可访问性 / ARIA
Expand Down
9 changes: 4 additions & 5 deletions models/asymkey/ssh_key_authorized_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
if err != nil {
return err
}
defer f.Close()

scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
Expand All @@ -148,15 +150,12 @@ func RegeneratePublicKeys(ctx context.Context, t io.StringWriter) error {
}
_, err = t.WriteString(line + "\n")
if err != nil {
f.Close()
return err
}
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
if err = scanner.Err(); err != nil {
return fmt.Errorf("RegeneratePublicKeys scan: %w", err)
}
f.Close()
}
return nil
}
2 changes: 1 addition & 1 deletion models/avatars/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

const (
// DefaultAvatarClass is the default class of a rendered avatar
DefaultAvatarClass = "ui avatar gt-vm"
DefaultAvatarClass = "ui avatar tw-align-middle"
// DefaultAvatarPixelSize is the default size in pixels of a rendered avatar
DefaultAvatarPixelSize = 28
)
Expand Down
5 changes: 3 additions & 2 deletions models/organization/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ func CreateOrganization(ctx context.Context, org *Organization, owner *user_mode

// Add initial creator to organization and owner team.
if err = db.Insert(ctx, &OrgUser{
UID: owner.ID,
OrgID: org.ID,
UID: owner.ID,
OrgID: org.ID,
IsPublic: setting.Service.DefaultOrgMemberVisible,
}); err != nil {
return fmt.Errorf("insert org-user relation: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/actions/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func ReadLogs(ctx context.Context, inStorage bool, filename string, offset, limi
}

if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("scan: %w", err)
return nil, fmt.Errorf("ReadLogs scan: %w", err)
}

return rows, nil
Expand Down
5 changes: 2 additions & 3 deletions modules/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,8 @@ func (c *Commit) GetSubModules() (*ObjectCache, error) {
}
}
}
err = scanner.Err()
if err != nil {
return nil, fmt.Errorf("scan: %w", err)
if err = scanner.Err(); err != nil {
return nil, fmt.Errorf("GetSubModules scan: %w", err)
}

return c.submoduleCache, nil
Expand Down
6 changes: 3 additions & 3 deletions modules/git/repo_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string)
}
}
}
err = scanner.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
if err = scanner.Err(); err != nil {
_ = stdoutReader.Close()
return fmt.Errorf("GetCodeActivityStats scan: %w", err)
}
a := make([]*CodeActivityAuthor, 0, len(authors))
for _, v := range authors {
Expand Down
15 changes: 7 additions & 8 deletions modules/indexer/code/bleve/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
const (
unicodeNormalizeName = "unicodeNormalize"
maxBatchSize = 16
// fuzzyDenominator determines the levenshtein distance per each character of a keyword
fuzzyDenominator = 4
)

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

phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
phraseQuery.FieldVal = "Content"
phraseQuery.Analyzer = repoIndexerAnalyzer
keywordQuery = phraseQuery
if opts.IsKeywordFuzzy {
phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword)
phraseQuery.FieldVal = "Content"
phraseQuery.Analyzer = repoIndexerAnalyzer
keywordQuery = phraseQuery
} else {
prefixQuery := bleve.NewPrefixQuery(opts.Keyword)
prefixQuery.FieldVal = "Content"
keywordQuery = prefixQuery
phraseQuery.Fuzziness = len(opts.Keyword) / fuzzyDenominator
}

if len(opts.RepoIDs) > 0 {
Expand Down
10 changes: 2 additions & 8 deletions modules/indexer/internal/bleve/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ func NumericEqualityQuery(value int64, field string) *query.NumericRangeQuery {
}

// MatchPhraseQuery generates a match phrase query for the given phrase, field and analyzer
func MatchPhraseQuery(matchPhrase, field, analyzer string) *query.MatchPhraseQuery {
func MatchPhraseQuery(matchPhrase, field, analyzer string, fuzziness int) *query.MatchPhraseQuery {
q := bleve.NewMatchPhraseQuery(matchPhrase)
q.FieldVal = field
q.Analyzer = analyzer
return q
}

// PrefixQuery generates a match prefix query for the given prefix and field
func PrefixQuery(matchPrefix, field string) *query.PrefixQuery {
q := bleve.NewPrefixQuery(matchPrefix)
q.FieldVal = field
q.Fuzziness = fuzziness
return q
}

Expand Down
25 changes: 13 additions & 12 deletions modules/indexer/issues/bleve/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error {
})
}

const maxBatchSize = 16
const (
maxBatchSize = 16
// fuzzyDenominator determines the levenshtein distance per each character of a keyword
fuzzyDenominator = 4
)

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

if options.Keyword != "" {
fuzziness := 0
if options.IsFuzzyKeyword {
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer),
inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer),
inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer),
}...))
} else {
queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
inner_bleve.PrefixQuery(options.Keyword, "title"),
inner_bleve.PrefixQuery(options.Keyword, "content"),
inner_bleve.PrefixQuery(options.Keyword, "comments"),
}...))
fuzziness = len(options.Keyword) / fuzzyDenominator
}

queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{
inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer, fuzziness),
inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer, fuzziness),
inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer, fuzziness),
}...))
}

if len(options.RepoIDs) > 0 || options.AllPublic {
Expand Down
48 changes: 16 additions & 32 deletions modules/indexer/issues/internal/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByCreatedDesc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByCreatedDesc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByCreatedDesc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -533,10 +531,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByUpdatedDesc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByUpdatedDesc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByUpdatedDesc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -551,10 +547,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByCommentsDesc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByCommentsDesc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByCommentsDesc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -569,10 +563,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByDeadlineDesc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByDeadlineDesc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByDeadlineDesc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -587,10 +579,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByCreatedAsc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByCreatedAsc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByCreatedAsc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -605,10 +595,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByUpdatedAsc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByUpdatedAsc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByUpdatedAsc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -623,10 +611,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByCommentsAsc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByCommentsAsc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByCommentsAsc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand All @@ -641,10 +627,8 @@ var cases = []*testIndexerCase{
{
Name: "SortByDeadlineAsc",
SearchOptions: &internal.SearchOptions{
Paginator: &db.ListOptions{
ListAll: true,
},
SortBy: internal.SortByDeadlineAsc,
Paginator: &db.ListOptionsAll,
SortBy: internal.SortByDeadlineAsc,
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
assert.Equal(t, len(data), len(result.Hits))
Expand Down
4 changes: 1 addition & 3 deletions modules/indexer/issues/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
)
{
reviews, err := issue_model.FindReviews(ctx, issue_model.FindReviewOptions{
ListOptions: db.ListOptions{
ListAll: true,
},
ListOptions: db.ListOptionsAll,
IssueID: issueID,
OfficialOnly: false,
})
Expand Down
5 changes: 2 additions & 3 deletions modules/markup/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
return err
}
}
err = scan.Err()
if err != nil {
return fmt.Errorf("scan: %w", err)
if err = scan.Err(); err != nil {
return fmt.Errorf("fallbackRender scan: %w", err)
}

_, err = tmpBlock.WriteString("</pre>")
Expand Down
Loading

0 comments on commit 207fc43

Please sign in to comment.