aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/launchpad/import.go
diff options
context:
space:
mode:
authorCyril Roelandt <tipecaml@gmail.com>2018-12-21 20:01:02 +0100
committerCyril Roelandt <tipecaml@gmail.com>2019-02-27 04:40:15 +0100
commit49cc971dbab1466bf390786ea35391f46e1dce7e (patch)
tree196d9b47ce19d435bd88ae687d6a5c0b33e95a4b /bridge/launchpad/import.go
parent5e4a656f85e6145f099c27bfcf42dabe1f317cb2 (diff)
downloadgit-bug-49cc971dbab1466bf390786ea35391f46e1dce7e.tar.gz
Launchpad bridge: fetch comments.
Diffstat (limited to 'bridge/launchpad/import.go')
-rw-r--r--bridge/launchpad/import.go46
1 files changed, 44 insertions, 2 deletions
diff --git a/bridge/launchpad/import.go b/bridge/launchpad/import.go
index 074b4bf3..10d25e6c 100644
--- a/bridge/launchpad/import.go
+++ b/bridge/launchpad/import.go
@@ -44,15 +44,18 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error {
}
for _, lpBug := range lpBugs {
+ var b *cache.BugCache
+ var err error
+
lpBugID := fmt.Sprintf("%d", lpBug.ID)
- _, err := repo.ResolveBugCreateMetadata(keyLaunchpadID, lpBugID)
+ b, err = repo.ResolveBugCreateMetadata(keyLaunchpadID, lpBugID)
if err != nil && err != bug.ErrBugNotExist {
return err
}
if err == bug.ErrBugNotExist {
createdAt, _ := time.Parse(time.RFC3339, lpBug.CreatedAt)
- _, err := repo.NewBugRaw(
+ b, err = repo.NewBugRaw(
li.makePerson(lpBug.Owner),
createdAt.Unix(),
lpBug.Title,
@@ -70,6 +73,45 @@ func (li *launchpadImporter) ImportAll(repo *cache.RepoCache) error {
fmt.Println("TODO: Update bug")
}
+ /* Handle messages */
+ if len(lpBug.Messages) == 0 {
+ return errors.Wrapf(err, "failed to fetch comments for bug #%s", lpBugID)
+ }
+
+ // The Launchpad API returns the bug description as the first
+ // comment, so skip it.
+ for _, lpMessage := range lpBug.Messages[1:] {
+ _, err := b.ResolveTargetWithMetadata(keyLaunchpadID, lpMessage.ID)
+ if err != nil && err != cache.ErrNoMatchingOp {
+ return errors.Wrapf(err, "failed to fetch comments for bug #%s", lpBugID)
+ }
+
+ // If this comment already exists, we are probably
+ // updating an existing bug. We do not want to duplicate
+ // the comments, so let us just skip this one.
+ // TODO: Can Launchpad comments be edited?
+ if err == nil {
+ continue
+ }
+
+ // This is a new comment, we can add it.
+ createdAt, _ := time.Parse(time.RFC3339, lpMessage.CreatedAt)
+ err = b.AddCommentRaw(
+ li.makePerson(lpMessage.Owner),
+ createdAt.Unix(),
+ lpMessage.Content,
+ nil,
+ map[string]string{
+ keyLaunchpadID: lpMessage.ID,
+ })
+ if err != nil {
+ return errors.Wrapf(err, "failed to add comment to bug #%s", lpBugID)
+ }
+ }
+ err = b.CommitAsNeeded()
+ if err != nil {
+ return err
+ }
}
return nil
}