aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bug
diff options
context:
space:
mode:
Diffstat (limited to 'commands/bug')
-rw-r--r--commands/bug/bug.go38
-rw-r--r--commands/bug/bug_comment_edit.go2
-rw-r--r--commands/bug/bug_new.go2
-rw-r--r--commands/bug/bug_rm.go2
-rw-r--r--commands/bug/bug_select.go2
-rw-r--r--commands/bug/select/select.go11
-rw-r--r--commands/bug/select/select_test.go10
-rw-r--r--commands/bug/testenv/testenv.go6
8 files changed, 36 insertions, 37 deletions
diff --git a/commands/bug/bug.go b/commands/bug/bug.go
index 04bf8980..bab040d8 100644
--- a/commands/bug/bug.go
+++ b/commands/bug/bug.go
@@ -142,14 +142,14 @@ func runBug(env *execenv.Env, opts bugOptions, args []string) error {
return err
}
- allIds, err := env.Backend.QueryBugs(q)
+ allIds, err := env.Backend.Bugs().Query(q)
if err != nil {
return err
}
bugExcerpt := make([]*cache.BugExcerpt, len(allIds))
for i, id := range allIds {
- b, err := env.Backend.ResolveBugExcerpt(id)
+ b, err := env.Backend.Bugs().ResolveExcerpt(id)
if err != nil {
return err
}
@@ -208,8 +208,8 @@ func bugsJsonFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error
jsonBugs := make([]JSONBugExcerpt, len(bugExcerpts))
for i, b := range bugExcerpts {
jsonBug := JSONBugExcerpt{
- Id: b.Id.String(),
- HumanId: b.Id.Human(),
+ Id: b.Id().String(),
+ HumanId: b.Id().Human(),
CreateTime: cmdjson.NewTime(b.CreateTime(), b.CreateLamportTime),
EditTime: cmdjson.NewTime(b.EditTime(), b.EditLamportTime),
Status: b.Status.String(),
@@ -219,7 +219,7 @@ func bugsJsonFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error
Metadata: b.CreateMetadata,
}
- author, err := env.Backend.ResolveIdentityExcerpt(b.AuthorId)
+ author, err := env.Backend.Identities().ResolveExcerpt(b.AuthorId)
if err != nil {
return err
}
@@ -227,7 +227,7 @@ func bugsJsonFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error
jsonBug.Actors = make([]cmdjson.Identity, len(b.Actors))
for i, element := range b.Actors {
- actor, err := env.Backend.ResolveIdentityExcerpt(element)
+ actor, err := env.Backend.Identities().ResolveExcerpt(element)
if err != nil {
return err
}
@@ -236,7 +236,7 @@ func bugsJsonFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error
jsonBug.Participants = make([]cmdjson.Identity, len(b.Participants))
for i, element := range b.Participants {
- participant, err := env.Backend.ResolveIdentityExcerpt(element)
+ participant, err := env.Backend.Identities().ResolveExcerpt(element)
if err != nil {
return err
}
@@ -252,7 +252,7 @@ func bugsJsonFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error
func bugsCompactFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
- author, err := env.Backend.ResolveIdentityExcerpt(b.AuthorId)
+ author, err := env.Backend.Identities().ResolveExcerpt(b.AuthorId)
if err != nil {
return err
}
@@ -266,7 +266,7 @@ func bugsCompactFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
}
env.Out.Printf("%s %s %s %s %s\n",
- colors.Cyan(b.Id.Human()),
+ colors.Cyan(b.Id().Human()),
colors.Yellow(b.Status),
text.LeftPadMaxLine(strings.TrimSpace(b.Title), 40, 0),
text.LeftPadMaxLine(labelsTxt.String(), 5, 0),
@@ -278,7 +278,7 @@ func bugsCompactFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
func bugsIDFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
- env.Out.Println(b.Id.String())
+ env.Out.Println(b.Id().String())
}
return nil
@@ -286,7 +286,7 @@ func bugsIDFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error {
func bugsDefaultFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
- author, err := env.Backend.ResolveIdentityExcerpt(b.AuthorId)
+ author, err := env.Backend.Identities().ResolveExcerpt(b.AuthorId)
if err != nil {
return err
}
@@ -313,7 +313,7 @@ func bugsDefaultFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
}
env.Out.Printf("%s\t%s\t%s\t%s\t%s\n",
- colors.Cyan(b.Id.Human()),
+ colors.Cyan(b.Id().Human()),
colors.Yellow(b.Status),
titleFmt+labelsFmt,
colors.Magenta(authorFmt),
@@ -325,7 +325,7 @@ func bugsDefaultFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
func bugsPlainFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
- env.Out.Printf("%s [%s] %s\n", b.Id.Human(), b.Status, strings.TrimSpace(b.Title))
+ env.Out.Printf("%s [%s] %s\n", b.Id().Human(), b.Status, strings.TrimSpace(b.Title))
}
return nil
}
@@ -353,7 +353,7 @@ func bugsOrgmodeFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
title = b.Title
}
- author, err := env.Backend.ResolveIdentityExcerpt(b.AuthorId)
+ author, err := env.Backend.Identities().ResolveExcerpt(b.AuthorId)
if err != nil {
return err
}
@@ -370,7 +370,7 @@ func bugsOrgmodeFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
env.Out.Printf("* %-6s %s %s %s: %s %s\n",
status,
- b.Id.Human(),
+ b.Id().Human(),
formatTime(b.CreateTime()),
author.DisplayName(),
title,
@@ -381,26 +381,26 @@ func bugsOrgmodeFormatter(env *execenv.Env, bugExcerpts []*cache.BugExcerpt) err
env.Out.Printf("** Actors:\n")
for _, element := range b.Actors {
- actor, err := env.Backend.ResolveIdentityExcerpt(element)
+ actor, err := env.Backend.Identities().ResolveExcerpt(element)
if err != nil {
return err
}
env.Out.Printf(": %s %s\n",
- actor.Id.Human(),
+ actor.Id().Human(),
actor.DisplayName(),
)
}
env.Out.Printf("** Participants:\n")
for _, element := range b.Participants {
- participant, err := env.Backend.ResolveIdentityExcerpt(element)
+ participant, err := env.Backend.Identities().ResolveExcerpt(element)
if err != nil {
return err
}
env.Out.Printf(": %s %s\n",
- participant.Id.Human(),
+ participant.Id().Human(),
participant.DisplayName(),
)
}
diff --git a/commands/bug/bug_comment_edit.go b/commands/bug/bug_comment_edit.go
index 8be7cb80..2a0289f5 100644
--- a/commands/bug/bug_comment_edit.go
+++ b/commands/bug/bug_comment_edit.go
@@ -41,7 +41,7 @@ func newBugCommentEditCommand() *cobra.Command {
}
func runBugCommentEdit(env *execenv.Env, opts bugCommentEditOptions, args []string) error {
- b, commentId, err := env.Backend.ResolveComment(args[0])
+ b, commentId, err := env.Backend.Bugs().ResolveComment(args[0])
if err != nil {
return err
}
diff --git a/commands/bug/bug_new.go b/commands/bug/bug_new.go
index 4f73a09c..fbfb9def 100644
--- a/commands/bug/bug_new.go
+++ b/commands/bug/bug_new.go
@@ -63,7 +63,7 @@ func runBugNew(env *execenv.Env, opts bugNewOptions) error {
}
}
- b, _, err := env.Backend.NewBug(
+ b, _, err := env.Backend.Bugs().New(
text.CleanupOneLine(opts.title),
text.Cleanup(opts.message),
)
diff --git a/commands/bug/bug_rm.go b/commands/bug/bug_rm.go
index 1d2a7524..04881d54 100644
--- a/commands/bug/bug_rm.go
+++ b/commands/bug/bug_rm.go
@@ -34,7 +34,7 @@ func runBugRm(env *execenv.Env, args []string) (err error) {
return errors.New("you must provide a bug prefix to remove")
}
- err = env.Backend.RemoveBug(args[0])
+ err = env.Backend.Bugs().Remove(args[0])
if err != nil {
return
diff --git a/commands/bug/bug_select.go b/commands/bug/bug_select.go
index 0b1cb15c..2a4d1201 100644
--- a/commands/bug/bug_select.go
+++ b/commands/bug/bug_select.go
@@ -46,7 +46,7 @@ func runBugSelect(env *execenv.Env, args []string) error {
prefix := args[0]
- b, err := env.Backend.ResolveBugPrefix(prefix)
+ b, err := env.Backend.Bugs().ResolvePrefix(prefix)
if err != nil {
return err
}
diff --git a/commands/bug/select/select.go b/commands/bug/select/select.go
index 908ad58c..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"
)
@@ -18,7 +17,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
@@ -28,13 +27,13 @@ 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
}
- if err != bug.ErrBugNotExist {
+ if !entity.IsErrNotFound(err) {
return nil, nil, err
}
}
@@ -44,7 +43,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 {
@@ -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..83ca6643 100644
--- a/commands/bug/select/select_test.go
+++ b/commands/bug/select/select_test.go
@@ -13,7 +13,7 @@ import (
func TestSelect(t *testing.T) {
repo := repository.CreateGoGitTestRepo(t, false)
- repoCache, err := cache.NewRepoCache(repo)
+ repoCache, err := cache.NewRepoCacheNoEvents(repo)
require.NoError(t, err)
_, _, err = ResolveBug(repoCache, []string{})
@@ -28,18 +28,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())
diff --git a/commands/bug/testenv/testenv.go b/commands/bug/testenv/testenv.go
index 10f20950..acd1f389 100644
--- a/commands/bug/testenv/testenv.go
+++ b/commands/bug/testenv/testenv.go
@@ -19,7 +19,7 @@ func NewTestEnvAndUser(t *testing.T) (*execenv.Env, entity.Id) {
testEnv := execenv.NewTestEnv(t)
- i, err := testEnv.Backend.NewIdentity(testUserName, testUserEmail)
+ i, err := testEnv.Backend.Identities().New(testUserName, testUserEmail)
require.NoError(t, err)
err = testEnv.Backend.SetUserIdentity(i)
@@ -38,7 +38,7 @@ func NewTestEnvAndBug(t *testing.T) (*execenv.Env, entity.Id) {
testEnv, _ := NewTestEnvAndUser(t)
- b, _, err := testEnv.Backend.NewBug(testBugTitle, testBugMessage)
+ b, _, err := testEnv.Backend.Bugs().New(testBugTitle, testBugMessage)
require.NoError(t, err)
return testEnv, b.Id()
@@ -53,7 +53,7 @@ func NewTestEnvAndBugWithComment(t *testing.T) (*execenv.Env, entity.Id, entity.
env, bugID := NewTestEnvAndBug(t)
- b, err := env.Backend.ResolveBug(bugID)
+ b, err := env.Backend.Bugs().Resolve(bugID)
require.NoError(t, err)
commentId, _, err := b.AddComment(testCommentMessage)