diff options
Diffstat (limited to 'bug')
-rw-r--r-- | bug/bug.go | 15 | ||||
-rw-r--r-- | bug/operation.go | 9 | ||||
-rw-r--r-- | bug/operations/add_comment.go | 2 | ||||
-rw-r--r-- | bug/operations/create.go | 9 | ||||
-rw-r--r-- | bug/operations/operations.go | 1 | ||||
-rw-r--r-- | bug/operations/set_status.go | 24 | ||||
-rw-r--r-- | bug/operations/set_title.go | 2 | ||||
-rw-r--r-- | bug/snapshot.go | 12 | ||||
-rw-r--r-- | bug/status.go | 20 |
9 files changed, 74 insertions, 20 deletions
@@ -182,17 +182,17 @@ func (bug *Bug) IsValid() bool { } } - // The very first Op should be a CREATE + // The very first Op should be a CreateOp firstOp := bug.firstOp() - if firstOp == nil || firstOp.OpType() != CREATE { + if firstOp == nil || firstOp.OpType() != CreateOp { return false } - // Check that there is no more CREATE op + // Check that there is no more CreateOp op it := NewOperationIterator(bug) createCount := 0 for it.Next() { - if it.Value().OpType() == CREATE { + if it.Value().OpType() == CreateOp { createCount++ } } @@ -351,7 +351,7 @@ func (bug *Bug) HumanId() string { } // Lookup for the very first operation of the bug. -// For a valid Bug, this operation should be a CREATE +// For a valid Bug, this operation should be a CreateOp func (bug *Bug) firstOp() Operation { for _, pack := range bug.packs { for _, op := range pack.Operations { @@ -368,7 +368,10 @@ func (bug *Bug) firstOp() Operation { // Compile a bug in a easily usable snapshot func (bug *Bug) Compile() Snapshot { - snap := Snapshot{} + snap := Snapshot{ + id: bug.id, + Status: OpenStatus, + } it := NewOperationIterator(bug) diff --git a/bug/operation.go b/bug/operation.go index 4414f2ad..c9e7a555 100644 --- a/bug/operation.go +++ b/bug/operation.go @@ -3,10 +3,11 @@ package bug type OperationType int const ( - UNKNOWN OperationType = iota - CREATE - SET_TITLE - ADD_COMMENT + _ OperationType = iota + CreateOp + SetTitleOp + AddCommentOp + SetStatusOp ) type Operation interface { diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go index ce33522c..2927295a 100644 --- a/bug/operations/add_comment.go +++ b/bug/operations/add_comment.go @@ -16,7 +16,7 @@ type AddCommentOperation struct { func NewAddCommentOp(author bug.Person, message string) AddCommentOperation { return AddCommentOperation{ - OpBase: bug.OpBase{OperationType: bug.ADD_COMMENT}, + OpBase: bug.OpBase{OperationType: bug.AddCommentOp}, Message: message, Author: author, Time: time.Now().Unix(), diff --git a/bug/operations/create.go b/bug/operations/create.go index f4ca11ad..ad1d99ac 100644 --- a/bug/operations/create.go +++ b/bug/operations/create.go @@ -2,7 +2,6 @@ package operations import ( "github.com/MichaelMure/git-bug/bug" - "reflect" "time" ) @@ -20,7 +19,7 @@ type CreateOperation struct { func NewCreateOp(author bug.Person, title, message string) CreateOperation { return CreateOperation{ - OpBase: bug.OpBase{OperationType: bug.CREATE}, + OpBase: bug.OpBase{OperationType: bug.CreateOp}, Title: title, Message: message, Author: author, @@ -29,12 +28,6 @@ func NewCreateOp(author bug.Person, title, message string) CreateOperation { } func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { - empty := bug.Snapshot{} - - if !reflect.DeepEqual(snapshot, empty) { - panic("Create operation should never be applied on a non-empty snapshot") - } - snapshot.Title = op.Title snapshot.Comments = []bug.Comment{ { diff --git a/bug/operations/operations.go b/bug/operations/operations.go index f42d6e9a..50692952 100644 --- a/bug/operations/operations.go +++ b/bug/operations/operations.go @@ -7,4 +7,5 @@ func init() { gob.Register(AddCommentOperation{}) gob.Register(CreateOperation{}) gob.Register(SetTitleOperation{}) + gob.Register(SetStatusOperation{}) } diff --git a/bug/operations/set_status.go b/bug/operations/set_status.go new file mode 100644 index 00000000..aa673bb1 --- /dev/null +++ b/bug/operations/set_status.go @@ -0,0 +1,24 @@ +package operations + +import "github.com/MichaelMure/git-bug/bug" + +// SetStatusOperation will change the status of a bug + +var _ bug.Operation = SetStatusOperation{} + +type SetStatusOperation struct { + bug.OpBase + Status bug.Status +} + +func NewSetStatusOp(status bug.Status) SetStatusOperation { + return SetStatusOperation{ + OpBase: bug.OpBase{OperationType: bug.SetStatusOp}, + Status: status, + } +} + +func (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot { + snapshot.Status = op.Status + return snapshot +} diff --git a/bug/operations/set_title.go b/bug/operations/set_title.go index 6d5cb87f..c5e0ab0e 100644 --- a/bug/operations/set_title.go +++ b/bug/operations/set_title.go @@ -11,7 +11,7 @@ type SetTitleOperation struct { func NewSetTitleOp(title string) SetTitleOperation { return SetTitleOperation{ - OpBase: bug.OpBase{OperationType: bug.SET_TITLE}, + OpBase: bug.OpBase{OperationType: bug.SetTitleOp}, Title: title, } } diff --git a/bug/snapshot.go b/bug/snapshot.go index 9b9acf87..53a010bb 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -7,11 +7,23 @@ import ( // Snapshot is a compiled form of the Bug data structure used for storage and merge type Snapshot struct { + id string + Status Status Title string Comments []Comment Labels []Label } +// Return the Bug identifier +func (snap Snapshot) Id() string { + return snap.id +} + +// Return the Bug identifier truncated for human consumption +func (snap Snapshot) HumanId() string { + return fmt.Sprintf("%.8s", snap.id) +} + func (snap Snapshot) Summary() string { return fmt.Sprintf("c:%d l:%d %s", len(snap.Comments)-1, diff --git a/bug/status.go b/bug/status.go new file mode 100644 index 00000000..b1b066ff --- /dev/null +++ b/bug/status.go @@ -0,0 +1,20 @@ +package bug + +type Status int + +const ( + _ Status = iota + OpenStatus + ClosedStatus +) + +func (s Status) String() string { + switch s { + case OpenStatus: + return "open" + case ClosedStatus: + return "closed" + default: + return "unknown status" + } +} |