From 08c0e18ade5241d124fc8a3424b7612174e82cef Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 16 Jun 2019 21:04:36 +0200 Subject: cache: expose the operation when creating a new bug --- bridge/github/import.go | 4 ++-- bridge/launchpad/import.go | 2 +- cache/repo_cache.go | 18 +++++++++--------- commands/add.go | 2 +- termui/termui.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bridge/github/import.go b/bridge/github/import.go index edb97c4f..6cfd022e 100644 --- a/bridge/github/import.go +++ b/bridge/github/import.go @@ -106,7 +106,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline } // create bug - b, err = repo.NewBugRaw( + b, _, err = repo.NewBugRaw( author, issue.CreatedAt.Unix(), issue.Title, @@ -140,7 +140,7 @@ func (gi *githubImporter) ensureIssue(repo *cache.RepoCache, issue issueTimeline // if the bug doesn't exist if b == nil { // we create the bug as soon as we have a legit first edition - b, err = repo.NewBugRaw( + b, _, err = repo.NewBugRaw( author, issue.CreatedAt.Unix(), issue.Title, diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go index 177ff3fc..63101d9c 100644 --- a/bridge/launchpad/import.go +++ b/bridge/launchpad/import.go @@ -74,7 +74,7 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache, since time.Time) e if err == bug.ErrBugNotExist { createdAt, _ := time.Parse(time.RFC3339, lpBug.CreatedAt) - b, err = repo.NewBugRaw( + b, _, err = repo.NewBugRaw( owner, createdAt.Unix(), lpBug.Title, diff --git a/cache/repo_cache.go b/cache/repo_cache.go index b3b2ea1e..a80bc7c9 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -563,16 +563,16 @@ func (c *RepoCache) ValidLabels() []bug.Label { // NewBug create a new bug // The new bug is written in the repository (commit) -func (c *RepoCache) NewBug(title string, message string) (*BugCache, error) { +func (c *RepoCache) NewBug(title string, message string) (*BugCache, *bug.CreateOperation, error) { return c.NewBugWithFiles(title, message, nil) } // NewBugWithFiles create a new bug with attached files for the message // The new bug is written in the repository (commit) -func (c *RepoCache) NewBugWithFiles(title string, message string, files []git.Hash) (*BugCache, error) { +func (c *RepoCache) NewBugWithFiles(title string, message string, files []git.Hash) (*BugCache, *bug.CreateOperation, error) { author, err := c.GetUserIdentity() if err != nil { - return nil, err + return nil, nil, err } return c.NewBugRaw(author, time.Now().Unix(), title, message, files, nil) @@ -581,10 +581,10 @@ func (c *RepoCache) NewBugWithFiles(title string, message string, files []git.Ha // NewBugWithFilesMeta create a new bug with attached files for the message, as // well as metadata for the Create operation. // The new bug is written in the repository (commit) -func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []git.Hash, metadata map[string]string) (*BugCache, error) { +func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title string, message string, files []git.Hash, metadata map[string]string) (*BugCache, *bug.CreateOperation, error) { b, op, err := bug.CreateWithFiles(author.Identity, unixTime, title, message, files) if err != nil { - return nil, err + return nil, nil, err } for key, value := range metadata { @@ -593,11 +593,11 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin err = b.Commit(c.repo) if err != nil { - return nil, err + return nil, nil, err } if _, has := c.bugs[b.Id()]; has { - return nil, fmt.Errorf("bug %s already exist in the cache", b.Id()) + return nil, nil, fmt.Errorf("bug %s already exist in the cache", b.Id()) } cached := NewBugCache(c, b) @@ -606,10 +606,10 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin // force the write of the excerpt err = c.bugUpdated(b.Id()) if err != nil { - return nil, err + return nil, nil, err } - return cached, nil + return cached, op, nil } // Fetch retrieve updates from a remote diff --git a/commands/add.go b/commands/add.go index ea40227c..d199b4c7 100644 --- a/commands/add.go +++ b/commands/add.go @@ -44,7 +44,7 @@ func runAddBug(cmd *cobra.Command, args []string) error { } } - b, err := backend.NewBug(addTitle, addMessage) + b, _, err := backend.NewBug(addTitle, addMessage) if err != nil { return err } diff --git a/termui/termui.go b/termui/termui.go index 54d9df69..46f9dd06 100644 --- a/termui/termui.go +++ b/termui/termui.go @@ -190,7 +190,7 @@ func newBugWithEditor(repo *cache.RepoCache) error { return errTerminateMainloop } else { - b, err = repo.NewBug(title, message) + b, _, err = repo.NewBug(title, message) if err != nil { return err } -- cgit