From d9ef14a2f42d423de32b989b3cf79f9bd9eb4444 Mon Sep 17 00:00:00 2001 From: Mark Feinstein Date: Sun, 28 Jan 2024 06:12:23 -0800 Subject: [PATCH] feat: add support for a default repository path --- ui/common/repopath.go | 13 +++++++++---- ui/common/repopath_test.go | 12 ++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ui/common/repopath.go b/ui/common/repopath.go index db03af6a..7f1649b2 100644 --- a/ui/common/repopath.go +++ b/ui/common/repopath.go @@ -2,6 +2,7 @@ package common import ( "fmt" + "path/filepath" "strings" ) @@ -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 } diff --git a/ui/common/repopath_test.go b/ui/common/repopath_test.go index 06224e68..6997af2a 100644 --- a/ui/common/repopath_test.go +++ b/ui/common/repopath_test.go @@ -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 @@ -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 {