refactor(repo): rename RepoHiddenFolder to HiddenFolder and cleanup
All checks were successful
Build and Release / Create Release (push) Successful in 0s
Build and Release / Unit Tests (push) Successful in 3m2s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 4m58s
Build and Release / Lint (push) Successful in 5m8s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 2m56s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Successful in 3m59s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Successful in 4m29s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 9h5m17s
Build and Release / Build Binary (linux/arm64) (push) Successful in 10m36s
All checks were successful
Build and Release / Create Release (push) Successful in 0s
Build and Release / Unit Tests (push) Successful in 3m2s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 4m58s
Build and Release / Lint (push) Successful in 5m8s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 2m56s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Successful in 3m59s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Successful in 4m29s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 9h5m17s
Build and Release / Build Binary (linux/arm64) (push) Successful in 10m36s
Simplify model name from RepoHiddenFolder to HiddenFolder since the repo context is already clear. Update function signatures to use comma-separated bool parameters and fix test calls to include new hidden folder parameters. Replace strings.Split with strings.SplitSeq for better performance.
This commit is contained in:
@@ -11,9 +11,8 @@ import (
|
||||
"code.gitcaddy.com/server/v3/modules/timeutil"
|
||||
)
|
||||
|
||||
// RepoHiddenFolder represents a folder that is hidden from the code browser
|
||||
// for non-admin users.
|
||||
type RepoHiddenFolder struct {
|
||||
// HiddenFolder represents a folder hidden from the code browser for non-admin users.
|
||||
type HiddenFolder struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
FolderPath string `xorm:"UNIQUE(s) NOT NULL"`
|
||||
@@ -21,12 +20,12 @@ type RepoHiddenFolder struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(RepoHiddenFolder))
|
||||
db.RegisterModel(new(HiddenFolder))
|
||||
}
|
||||
|
||||
// GetHiddenFolders returns all hidden folders for a repository.
|
||||
func GetHiddenFolders(ctx context.Context, repoID int64) ([]*RepoHiddenFolder, error) {
|
||||
folders := make([]*RepoHiddenFolder, 0)
|
||||
func GetHiddenFolders(ctx context.Context, repoID int64) ([]*HiddenFolder, error) {
|
||||
folders := make([]*HiddenFolder, 0)
|
||||
return folders, db.GetEngine(ctx).Where("repo_id = ?", repoID).OrderBy("folder_path").Find(&folders)
|
||||
}
|
||||
|
||||
@@ -45,12 +44,12 @@ func GetHiddenFolderPaths(ctx context.Context, repoID int64) (map[string]bool, e
|
||||
|
||||
// IsHiddenFolder checks if a specific folder path is hidden.
|
||||
func IsHiddenFolder(ctx context.Context, repoID int64, folderPath string) (bool, error) {
|
||||
return db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Exist(&RepoHiddenFolder{})
|
||||
return db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Exist(&HiddenFolder{})
|
||||
}
|
||||
|
||||
// AddHiddenFolder adds a folder to the hidden list.
|
||||
func AddHiddenFolder(ctx context.Context, repoID int64, folderPath string) error {
|
||||
_, err := db.GetEngine(ctx).Insert(&RepoHiddenFolder{
|
||||
_, err := db.GetEngine(ctx).Insert(&HiddenFolder{
|
||||
RepoID: repoID,
|
||||
FolderPath: folderPath,
|
||||
})
|
||||
@@ -59,7 +58,7 @@ func AddHiddenFolder(ctx context.Context, repoID int64, folderPath string) error
|
||||
|
||||
// RemoveHiddenFolder removes a folder from the hidden list.
|
||||
func RemoveHiddenFolder(ctx context.Context, repoID int64, folderPath string) error {
|
||||
_, err := db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Delete(&RepoHiddenFolder{})
|
||||
_, err := db.GetEngine(ctx).Where("repo_id = ? AND folder_path = ?", repoID, folderPath).Delete(&HiddenFolder{})
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -416,7 +416,7 @@ func handleRepoViewSubmodule(ctx *context.Context, commitSubmoduleFile *git.Comm
|
||||
|
||||
// isDotfilePath checks if any segment of the path starts with "."
|
||||
func isDotfilePath(treePath string) bool {
|
||||
for _, segment := range strings.Split(treePath, "/") {
|
||||
for segment := range strings.SplitSeq(treePath, "/") {
|
||||
if strings.HasPrefix(segment, ".") {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ func sortTreeViewNodes(nodes []*TreeViewNode) {
|
||||
})
|
||||
}
|
||||
|
||||
func listTreeNodes(ctx context.Context, repoLink string, renderedIconPool *fileicon.RenderedIconPool, commit *git.Commit, tree *git.Tree, treePath, subPath string, hiddenPaths map[string]bool, isAdmin bool, hideDotfiles bool) ([]*TreeViewNode, error) {
|
||||
func listTreeNodes(ctx context.Context, repoLink string, renderedIconPool *fileicon.RenderedIconPool, commit *git.Commit, tree *git.Tree, treePath, subPath string, hiddenPaths map[string]bool, isAdmin, hideDotfiles bool) ([]*TreeViewNode, error) {
|
||||
entries, err := tree.ListEntries()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -237,7 +237,7 @@ func listTreeNodes(ctx context.Context, repoLink string, renderedIconPool *filei
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func GetTreeViewNodes(ctx context.Context, repoLink string, renderedIconPool *fileicon.RenderedIconPool, commit *git.Commit, treePath, subPath string, hiddenPaths map[string]bool, isAdmin bool, hideDotfiles bool) ([]*TreeViewNode, error) {
|
||||
func GetTreeViewNodes(ctx context.Context, repoLink string, renderedIconPool *fileicon.RenderedIconPool, commit *git.Commit, treePath, subPath string, hiddenPaths map[string]bool, isAdmin, hideDotfiles bool) ([]*TreeViewNode, error) {
|
||||
entry, err := commit.GetTreeEntryByPath(treePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestGetTreeViewNodes(t *testing.T) {
|
||||
mockOpenIconForFolder := func(id string) template.HTML {
|
||||
return template.HTML(`<svg class="svg git-entry-icon octicon-file-directory-open-fill" width="16" height="16" aria-hidden="true"><use href="#` + id + `"></use></svg>`)
|
||||
}
|
||||
treeNodes, err := GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "", "")
|
||||
treeNodes, err := GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "", "", nil, false, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*TreeViewNode{
|
||||
{
|
||||
@@ -87,7 +87,7 @@ func TestGetTreeViewNodes(t *testing.T) {
|
||||
},
|
||||
}, treeNodes)
|
||||
|
||||
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "", "docs/README.md")
|
||||
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "", "docs/README.md", nil, false, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*TreeViewNode{
|
||||
{
|
||||
@@ -107,7 +107,7 @@ func TestGetTreeViewNodes(t *testing.T) {
|
||||
},
|
||||
}, treeNodes)
|
||||
|
||||
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "docs", "README.md")
|
||||
treeNodes, err = GetTreeViewNodes(ctx, curRepoLink, renderedIconPool, ctx.Repo.Commit, "docs", "README.md", nil, false, false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []*TreeViewNode{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user