aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge/github/import.go11
-rw-r--r--bug/op_label_change.go27
-rw-r--r--cache/bug_cache.go27
3 files changed, 60 insertions, 5 deletions
diff --git a/bridge/github/import.go b/bridge/github/import.go
index 4960117a..5f99b5ea 100644
--- a/bridge/github/import.go
+++ b/bridge/github/import.go
@@ -40,7 +40,7 @@ func (gi *githubImporter) ImportAll(repo *cache.RepoCache, since time.Time) erro
for gi.iterator.NextIssue() {
issue := gi.iterator.IssueValue()
- fmt.Printf("importing issue: %v\n", gi.iterator.count)
+ fmt.Printf("importing issue: %v %v\n", gi.iterator.count, issue.Title)
// get issue edits
issueEdits := []userContentEdit{}
for gi.iterator.NextIssueEdit() {
@@ -71,12 +71,12 @@ func (gi *githubImporter) ImportAll(repo *cache.RepoCache, since time.Time) erro
err := gi.ensureTimelineComment(repo, b, item.IssueComment, commentEdits)
if err != nil {
- return fmt.Errorf("timeline event creation: %v", err)
+ return fmt.Errorf("timeline comment creation: %v", err)
}
} else {
if err := gi.ensureTimelineItem(repo, b, item); err != nil {
- return fmt.Errorf("timeline comment creation: %v", err)
+ return fmt.Errorf("timeline event creation: %v", err)
}
}
}
@@ -189,7 +189,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
if err != nil {
return err
}
- _, _, err = b.ChangeLabelsRaw(
+ _, err = b.ForceChangeLabelsRaw(
author,
item.LabeledEvent.CreatedAt.Unix(),
[]string{
@@ -198,6 +198,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
nil,
map[string]string{keyGithubId: id},
)
+
return err
case "UnlabeledEvent":
@@ -211,7 +212,7 @@ func (gi *githubImporter) ensureTimelineItem(repo *cache.RepoCache, b *cache.Bug
return err
}
- _, _, err = b.ChangeLabelsRaw(
+ _, err = b.ForceChangeLabelsRaw(
author,
item.UnlabeledEvent.CreatedAt.Unix(),
nil,
diff --git a/bug/op_label_change.go b/bug/op_label_change.go
index a2108941..0e7929b7 100644
--- a/bug/op_label_change.go
+++ b/bug/op_label_change.go
@@ -234,6 +234,33 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r
return results, labelOp, nil
}
+// ForceChangeLabels is a convenience function to apply the operation
+// The difference with ChangeLabels is that no checks of deduplications are done. You are entirely
+// responsible of what you are doing. In the general case, you want to use ChangeLabels instead.
+// The intended use of this function is to allow importers to create legal but unexpected label changes,
+// like removing a label with no information of when it was added before.
+func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string) (*LabelChangeOperation, error) {
+ added := make([]Label, len(add))
+ for i, str := range add {
+ added[i] = Label(str)
+ }
+
+ removed := make([]Label, len(remove))
+ for i, str := range remove {
+ removed[i] = Label(str)
+ }
+
+ labelOp := NewLabelChangeOperation(author, unixTime, added, removed)
+
+ if err := labelOp.Validate(); err != nil {
+ return nil, err
+ }
+
+ b.Append(labelOp)
+
+ return labelOp, nil
+}
+
func labelExist(labels []Label, label Label) bool {
for _, l := range labels {
if l == label {
diff --git a/cache/bug_cache.go b/cache/bug_cache.go
index 5fc76658..aad6dab8 100644
--- a/cache/bug_cache.go
+++ b/cache/bug_cache.go
@@ -139,6 +139,33 @@ func (c *BugCache) ChangeLabelsRaw(author *IdentityCache, unixTime int64, added
return changes, op, nil
}
+func (c *BugCache) ForceChangeLabels(added []string, removed []string) (*bug.LabelChangeOperation, error) {
+ author, err := c.repoCache.GetUserIdentity()
+ if err != nil {
+ return nil, err
+ }
+
+ return c.ForceChangeLabelsRaw(author, time.Now().Unix(), added, removed, nil)
+}
+
+func (c *BugCache) ForceChangeLabelsRaw(author *IdentityCache, unixTime int64, added []string, removed []string, metadata map[string]string) (*bug.LabelChangeOperation, error) {
+ op, err := bug.ForceChangeLabels(c.bug, author.Identity, unixTime, added, removed)
+ if err != nil {
+ return nil, err
+ }
+
+ for key, value := range metadata {
+ op.SetMetadata(key, value)
+ }
+
+ err = c.notifyUpdated()
+ if err != nil {
+ return nil, err
+ }
+
+ return op, nil
+}
+
func (c *BugCache) Open() (*bug.SetStatusOperation, error) {
author, err := c.repoCache.GetUserIdentity()
if err != nil {