From 0ac39a7ab5db077fcf0df827e32bf6e625e980da Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 19 Nov 2022 11:33:12 +0100 Subject: WIP --- commands/bug/select/select.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'commands/bug/select') diff --git a/commands/bug/select/select.go b/commands/bug/select/select.go index 908ad58c..42d65bc2 100644 --- a/commands/bug/select/select.go +++ b/commands/bug/select/select.go @@ -18,7 +18,7 @@ const selectFile = "select" var ErrNoValidId = errors.New("you must provide a bug id or use the \"select\" command first") // ResolveBug first try to resolve a bug using the first argument of the command -// line. If it fails, it fallback to the select mechanism. +// line. If it fails, it falls back to the select mechanism. // // Returns: // - the bug if any @@ -34,7 +34,7 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string return b, args[1:], nil } - if err != bug.ErrBugNotExist { + if !entity.IsErrNotFound(err) { return nil, nil, err } } @@ -44,7 +44,7 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string b, err := selected(repo) // selected bug is invalid - if err == bug.ErrBugNotExist { + if entity.IsErrNotFound(err) { // we clear the selected bug err = Clear(repo) if err != nil { -- cgit From 9b98fc06489353053564b431ac0c0d73a5c55a56 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 21 Dec 2022 21:54:36 +0100 Subject: cache: tie up the refactor up to compiling --- commands/bug/select/select.go | 5 ++--- commands/bug/select/select_test.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'commands/bug/select') diff --git a/commands/bug/select/select.go b/commands/bug/select/select.go index 42d65bc2..7096dde4 100644 --- a/commands/bug/select/select.go +++ b/commands/bug/select/select.go @@ -9,7 +9,6 @@ import ( "github.com/pkg/errors" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/entities/bug" "github.com/MichaelMure/git-bug/entity" ) @@ -28,7 +27,7 @@ var ErrNoValidId = errors.New("you must provide a bug id or use the \"select\" c func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string, error) { // At first, try to use the first argument as a bug prefix if len(args) > 0 { - b, err := repo.ResolveBugPrefix(args[0]) + b, err := repo.Bugs().ResolvePrefix(args[0]) if err == nil { return b, args[1:], nil @@ -115,7 +114,7 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { return nil, fmt.Errorf("select file in invalid, removing it") } - b, err := repo.ResolveBug(id) + b, err := repo.Bugs().Resolve(id) if err != nil { return nil, err } diff --git a/commands/bug/select/select_test.go b/commands/bug/select/select_test.go index 702700f4..5533ac2b 100644 --- a/commands/bug/select/select_test.go +++ b/commands/bug/select/select_test.go @@ -13,8 +13,11 @@ import ( func TestSelect(t *testing.T) { repo := repository.CreateGoGitTestRepo(t, false) - repoCache, err := cache.NewRepoCache(repo) + repoCache, events, err := cache.NewRepoCache(repo) require.NoError(t, err) + for event := range events { + require.NoError(t, event.Err) + } _, _, err = ResolveBug(repoCache, []string{}) require.Equal(t, ErrNoValidId, err) @@ -28,18 +31,18 @@ func TestSelect(t *testing.T) { // generate a bunch of bugs - rene, err := repoCache.NewIdentity("René Descartes", "rene@descartes.fr") + rene, err := repoCache.Identities().New("René Descartes", "rene@descartes.fr") require.NoError(t, err) for i := 0; i < 10; i++ { - _, _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) + _, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) } // and two more for testing - b1, _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) + b1, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) - b2, _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) + b2, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) err = Select(repoCache, b1.Id()) -- cgit From 95911100823b5c809225d664de74ad2d64e91972 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 22 Dec 2022 23:19:31 +0100 Subject: cache: fix some bugs after refactor --- commands/bug/select/select_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'commands/bug/select') diff --git a/commands/bug/select/select_test.go b/commands/bug/select/select_test.go index 5533ac2b..83ca6643 100644 --- a/commands/bug/select/select_test.go +++ b/commands/bug/select/select_test.go @@ -13,11 +13,8 @@ import ( func TestSelect(t *testing.T) { repo := repository.CreateGoGitTestRepo(t, false) - repoCache, events, err := cache.NewRepoCache(repo) + repoCache, err := cache.NewRepoCacheNoEvents(repo) require.NoError(t, err) - for event := range events { - require.NoError(t, event.Err) - } _, _, err = ResolveBug(repoCache, []string{}) require.Equal(t, ErrNoValidId, err) -- cgit