From bbc84a4f0b29c39ae99a9e09b4cb2b88dda80de9 Mon Sep 17 00:00:00 2001
From: vince <vincetiu8@gmail.com>
Date: Mon, 13 Jul 2020 10:18:33 +0800
Subject: [PATCH] Move resolveComment to the select package

---
 commands/comment_edit.go  | 30 +-----------------------------
 commands/select/select.go | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/commands/comment_edit.go b/commands/comment_edit.go
index 9e72125b..856e13c7 100644
--- a/commands/comment_edit.go
+++ b/commands/comment_edit.go
@@ -1,13 +1,9 @@
 package commands
 
 import (
-	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 
-	"github.com/MichaelMure/git-bug/bug"
-	"github.com/MichaelMure/git-bug/cache"
 	_select "github.com/MichaelMure/git-bug/commands/select"
-	"github.com/MichaelMure/git-bug/entity"
 	"github.com/MichaelMure/git-bug/input"
 )
 
@@ -43,32 +39,8 @@ func newCommentEditCommand() *cobra.Command {
 	return cmd
 }
 
-func ResolveComment(repo *cache.RepoCache, fullId string) (*cache.BugCache, entity.Id, error) {
-	bugId, _ := bug.SplitCommentId(fullId)
-	b, _, err := _select.ResolveBug(repo, []string{bugId})
-	if err != nil {
-		return nil, entity.UnsetId, err
-	}
-
-	matching := make([]entity.Id, 0, 5)
-
-	for _, comment := range b.Snapshot().Comments {
-		if comment.Id().HasPrefix(fullId) {
-			matching = append(matching, comment.Id())
-		}
-	}
-
-	if len(matching) > 1 {
-		return nil, entity.UnsetId, entity.NewErrMultipleMatch("comment", matching)
-	} else if len(matching) == 0 {
-		return nil, entity.UnsetId, errors.New("comment doesn't exist")
-	}
-
-	return b, matching[0], nil
-}
-
 func runCommentEdit(env *Env, opts commentEditOptions, args []string) error {
-	b, c, err := ResolveComment(env.backend, args[0])
+	b, c, err := _select.ResolveComment(env.backend, args[0])
 
 	if err != nil {
 		return err
diff --git a/commands/select/select.go b/commands/select/select.go
index cf861fcc..cb427c05 100644
--- a/commands/select/select.go
+++ b/commands/select/select.go
@@ -69,6 +69,30 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string
 	return nil, nil, ErrNoValidId
 }
 
+func ResolveComment(repo *cache.RepoCache, fullId string) (*cache.BugCache, entity.Id, error) {
+	bugId, _ := bug.SplitCommentId(fullId)
+	b, _, err := ResolveBug(repo, []string{bugId})
+	if err != nil {
+		return nil, entity.UnsetId, err
+	}
+
+	matching := make([]entity.Id, 0, 5)
+
+	for _, comment := range b.Snapshot().Comments {
+		if comment.Id().HasPrefix(fullId) {
+			matching = append(matching, comment.Id())
+		}
+	}
+
+	if len(matching) > 1 {
+		return nil, entity.UnsetId, entity.NewErrMultipleMatch("comment", matching)
+	} else if len(matching) == 0 {
+		return nil, entity.UnsetId, errors.New("comment doesn't exist")
+	}
+
+	return b, matching[0], nil
+}
+
 // Select will select a bug for future use
 func Select(repo *cache.RepoCache, id entity.Id) error {
 	selectPath := selectFilePath(repo)
-- 
GitLab