mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-27 20:03:47 +00:00
2bcf950b78
Adds a search box and a file-extension filter to the pull request diff sidebar, so reviewers can narrow a large diff down to the files they care about. Both filters apply to the file tree and to the diff itself. The extension menu follows GitHub: extensions sorted alphabetically, dotfiles and extension-less files in their own buckets, and the selection kept in the same `file-filters[]` query parameter, so a filtered view is shareable and survives a reload. The menu can list every extension in a diff, so `createTippy` gains an opt-in `limitSizeToViewport` option that caps a popup to the space left in the viewport and scrolls its content. Popups that do not ask for it are unchanged. Closes https://github.com/go-gitea/gitea/issues/27256 Signed-off-by: silverwind <me@silverwind.io> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com> Co-authored-by: Copilot <copilot@github.com> Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
84 lines
2.1 KiB
Go
84 lines
2.1 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"html/template"
|
|
"testing"
|
|
|
|
pull_model "gitea.dev/models/pull"
|
|
"gitea.dev/modules/fileicon"
|
|
"gitea.dev/modules/git"
|
|
"gitea.dev/services/gitdiff"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestTransformDiffTreeForWeb(t *testing.T) {
|
|
renderedIconPool := fileicon.NewRenderedIconPool()
|
|
ret := transformDiffTreeForWeb(renderedIconPool, &gitdiff.DiffTree{Files: []*gitdiff.DiffTreeRecord{
|
|
{
|
|
Status: "changed",
|
|
HeadPath: "dir-a/dir-a-x/file-deep",
|
|
HeadMode: git.EntryModeBlob,
|
|
},
|
|
{
|
|
Status: "added",
|
|
HeadPath: "file1",
|
|
HeadMode: git.EntryModeBlob,
|
|
},
|
|
{
|
|
Status: "renamed",
|
|
BasePath: "file2-old",
|
|
HeadPath: "file2",
|
|
HeadMode: git.EntryModeBlob,
|
|
},
|
|
}}, map[string]pull_model.ViewedState{
|
|
"dir-a/dir-a-x/file-deep": pull_model.Viewed,
|
|
})
|
|
|
|
mockIconForFile := func(id string) template.HTML {
|
|
return template.HTML(`<svg class="svg git-entry-icon octicon-file" width="16" height="16" aria-hidden="true"><use href="#` + id + `"></use></svg>`)
|
|
}
|
|
assert.Equal(t, WebDiffFileTree{
|
|
TreeRoot: WebDiffFileItem{
|
|
Children: []*WebDiffFileItem{
|
|
{
|
|
EntryMode: "tree",
|
|
DisplayName: "dir-a/dir-a-x",
|
|
FullName: "dir-a/dir-a-x",
|
|
Children: []*WebDiffFileItem{
|
|
{
|
|
EntryMode: "",
|
|
DisplayName: "file-deep",
|
|
FullName: "dir-a/dir-a-x/file-deep",
|
|
NameHash: "4acf7eef1c943a09e9f754e93ff190db8583236b",
|
|
DiffStatus: "changed",
|
|
IsViewed: true,
|
|
FileIcon: mockIconForFile(`svg-mfi-file`),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
EntryMode: "",
|
|
DisplayName: "file1",
|
|
FullName: "file1",
|
|
NameHash: "60b27f004e454aca81b0480209cce5081ec52390",
|
|
DiffStatus: "added",
|
|
FileIcon: mockIconForFile(`svg-mfi-file`),
|
|
},
|
|
{
|
|
EntryMode: "",
|
|
DisplayName: "file2",
|
|
FullName: "file2",
|
|
OldFullName: "file2-old",
|
|
NameHash: "cb99b709a1978bd205ab9dfd4c5aaa1fc91c7523",
|
|
DiffStatus: "renamed",
|
|
FileIcon: mockIconForFile(`svg-mfi-file`),
|
|
},
|
|
},
|
|
},
|
|
}, ret)
|
|
}
|