aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bug/bug.go6
-rw-r--r--bug/operations/set_title.go23
-rw-r--r--bug/sorting.go4
-rw-r--r--graphql/graph/gen_graph.go14
-rw-r--r--graphql/schema.graphql1
5 files changed, 41 insertions, 7 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 7fa1dfb2..22cf9ee1 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -280,7 +280,7 @@ func (bug *Bug) IsValid() bool {
}
// The very first Op should be a CreateOp
- firstOp := bug.firstOp()
+ firstOp := bug.FirstOp()
if firstOp == nil || firstOp.OpType() != CreateOp {
return false
}
@@ -561,7 +561,7 @@ func formatHumanId(id string) string {
// Lookup for the very first operation of the bug.
// For a valid Bug, this operation should be a CreateOp
-func (bug *Bug) firstOp() Operation {
+func (bug *Bug) FirstOp() Operation {
for _, pack := range bug.packs {
for _, op := range pack.Operations {
return op
@@ -577,7 +577,7 @@ func (bug *Bug) firstOp() Operation {
// Lookup for the very last operation of the bug.
// For a valid Bug, should never be nil
-func (bug *Bug) lastOp() Operation {
+func (bug *Bug) LastOp() Operation {
if !bug.staging.IsEmpty() {
return bug.staging.Operations[len(bug.staging.Operations)-1]
}
diff --git a/bug/operations/set_title.go b/bug/operations/set_title.go
index fab01d8a..49a270f7 100644
--- a/bug/operations/set_title.go
+++ b/bug/operations/set_title.go
@@ -11,6 +11,7 @@ var _ bug.Operation = SetTitleOperation{}
type SetTitleOperation struct {
bug.OpBase
Title string
+ Was string
}
func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
@@ -19,15 +20,33 @@ func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
return snapshot
}
-func NewSetTitleOp(author bug.Person, title string) SetTitleOperation {
+func NewSetTitleOp(author bug.Person, title string, was string) SetTitleOperation {
return SetTitleOperation{
OpBase: bug.NewOpBase(bug.SetTitleOp, author),
Title: title,
+ Was: was,
}
}
// Convenience function to apply the operation
func SetTitle(b *bug.Bug, author bug.Person, title string) {
- setTitleOp := NewSetTitleOp(author, title)
+ it := bug.NewOperationIterator(b)
+
+ var lastTitleOp bug.Operation
+ for it.Next() {
+ op := it.Value()
+ if op.OpType() == bug.SetTitleOp {
+ lastTitleOp = op
+ }
+ }
+
+ var was string
+ if lastTitleOp != nil {
+ was = lastTitleOp.(SetTitleOperation).Title
+ } else {
+ was = b.FirstOp().(CreateOperation).Title
+ }
+
+ setTitleOp := NewSetTitleOp(author, title, was)
b.Append(setTitleOp)
}
diff --git a/bug/sorting.go b/bug/sorting.go
index 360a969d..d1c370d3 100644
--- a/bug/sorting.go
+++ b/bug/sorting.go
@@ -21,7 +21,7 @@ func (b BugsByCreationTime) Less(i, j int) bool {
// by the first sorting using the logical clock. That means that if users
// synchronize their bugs regularly, the timestamp will rarely be used, and
// should still provide a kinda accurate sorting when needed.
- return b[i].firstOp().Time().Before(b[j].firstOp().Time())
+ return b[i].FirstOp().Time().Before(b[j].FirstOp().Time())
}
func (b BugsByCreationTime) Swap(i, j int) {
@@ -49,7 +49,7 @@ func (b BugsByEditTime) Less(i, j int) bool {
// by the first sorting using the logical clock. That means that if users
// synchronize their bugs regularly, the timestamp will rarely be used, and
// should still provide a kinda accurate sorting when needed.
- return b[i].lastOp().Time().Before(b[j].lastOp().Time())
+ return b[i].LastOp().Time().Before(b[j].LastOp().Time())
}
func (b BugsByEditTime) Swap(i, j int) {
diff --git a/graphql/graph/gen_graph.go b/graphql/graph/gen_graph.go
index 605fa15a..06c65e84 100644
--- a/graphql/graph/gen_graph.go
+++ b/graphql/graph/gen_graph.go
@@ -2413,6 +2413,8 @@ func (ec *executionContext) _SetTitleOperation(ctx context.Context, sel []query.
out.Values[i] = ec._SetTitleOperation_date(ctx, field, obj)
case "title":
out.Values[i] = ec._SetTitleOperation_title(ctx, field, obj)
+ case "was":
+ out.Values[i] = ec._SetTitleOperation_was(ctx, field, obj)
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@@ -2473,6 +2475,17 @@ func (ec *executionContext) _SetTitleOperation_title(ctx context.Context, field
return graphql.MarshalString(res)
}
+func (ec *executionContext) _SetTitleOperation_was(ctx context.Context, field graphql.CollectedField, obj *operations.SetTitleOperation) graphql.Marshaler {
+ rctx := graphql.GetResolverContext(ctx)
+ rctx.Object = "SetTitleOperation"
+ rctx.Args = nil
+ rctx.Field = field
+ rctx.PushField(field.Alias)
+ defer rctx.Pop()
+ res := obj.Was
+ return graphql.MarshalString(res)
+}
+
var __DirectiveImplementors = []string{"__Directive"}
// nolint: gocyclo, errcheck, gas, goconst
@@ -3331,6 +3344,7 @@ type SetTitleOperation implements Operation, Authored {
date: Time!
title: String!
+ was: String!
}
type AddCommentOperation implements Operation, Authored {
diff --git a/graphql/schema.graphql b/graphql/schema.graphql
index e4299629..5910984d 100644
--- a/graphql/schema.graphql
+++ b/graphql/schema.graphql
@@ -92,6 +92,7 @@ type SetTitleOperation implements Operation, Authored {
date: Time!
title: String!
+ was: String!
}
type AddCommentOperation implements Operation, Authored {