Skip to content

Commit

Permalink
feat: add support for a default repository path
Browse files Browse the repository at this point in the history
  • Loading branch information
markfeinstein authored and dlvhdr committed Feb 7, 2024
1 parent f76c49e commit d9ef14a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ui/common/repopath.go
Expand Up @@ -2,6 +2,7 @@ package common

import (
"fmt"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -42,11 +43,15 @@ func GetRepoLocalPath(repoName string, cfgPaths map[string]string) (string, bool
// match config:repoPath values of {owner}/* as map key
wildcardPath, wildcardFound := cfgPaths[fmt.Sprintf("%s/*", owner)]

if !wildcardFound {
return "", false
if wildcardFound {
// adjust wildcard match to wildcard path - ~/somepath/* to ~/somepath/{repo}
return fmt.Sprintf("%s/%s", strings.TrimSuffix(wildcardPath, "/*"), repo), true
}

// adjust wildcard match to wildcard path - ~/somepath/* to ~/somepath/{repo}
return fmt.Sprintf("%s/%s", strings.TrimSuffix(wildcardPath, "/*"), repo), true
if defaultPath, found := cfgPaths["default_path"]; found {
p := strings.TrimSuffix(defaultPath, "/*")
return filepath.Join(p, repo), true
}

return "", false
}
12 changes: 12 additions & 0 deletions ui/common/repopath_test.go
Expand Up @@ -13,6 +13,12 @@ var configPaths = map[string]string{
"user_2/*": "/path/to/user_2/*",
}

var configPathsWithDefultPath = map[string]string{
"user/repo": "/path/to/user/repo",
"user_2/*": "/path/to/user_2/*",
"default_path": "/path/to/user/dev",
}

func TestGetRepoLocalPath(t *testing.T) {
testCases := map[string]struct {
repo string
Expand Down Expand Up @@ -44,6 +50,12 @@ func TestGetRepoLocalPath(t *testing.T) {
found: false,
configPaths: configPaths,
},
"default path": {
repo: "user3/repo",
want: "/path/to/user/dev/repo",
found: true,
configPaths: configPathsWithDefultPath,
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit d9ef14a

Please sign in to comment.