aboutsummaryrefslogtreecommitdiffstats
path: root/bug/operations
diff options
context:
space:
mode:
Diffstat (limited to 'bug/operations')
-rw-r--r--bug/operations/add_comment.go52
-rw-r--r--bug/operations/create.go57
-rw-r--r--bug/operations/create_test.go33
-rw-r--r--bug/operations/label_change.go128
-rw-r--r--bug/operations/operations.go12
-rw-r--r--bug/operations/set_status.go39
-rw-r--r--bug/operations/set_title.go52
7 files changed, 0 insertions, 373 deletions
diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go
deleted file mode 100644
index b4126a8e..00000000
--- a/bug/operations/add_comment.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package operations
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/util"
-)
-
-// AddCommentOperation will add a new comment in the bug
-
-var _ bug.Operation = AddCommentOperation{}
-
-type AddCommentOperation struct {
- bug.OpBase
- Message string
- // TODO: change for a map[string]util.hash to store the filename ?
- files []util.Hash
-}
-
-func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
- comment := bug.Comment{
- Message: op.Message,
- Author: op.Author,
- Files: op.files,
- UnixTime: op.UnixTime,
- }
-
- snapshot.Comments = append(snapshot.Comments, comment)
-
- return snapshot
-}
-
-func (op AddCommentOperation) Files() []util.Hash {
- return op.files
-}
-
-func NewAddCommentOp(author bug.Person, message string, files []util.Hash) AddCommentOperation {
- return AddCommentOperation{
- OpBase: bug.NewOpBase(bug.AddCommentOp, author),
- Message: message,
- files: files,
- }
-}
-
-// Convenience function to apply the operation
-func Comment(b bug.Interface, author bug.Person, message string) {
- CommentWithFiles(b, author, message, nil)
-}
-
-func CommentWithFiles(b bug.Interface, author bug.Person, message string, files []util.Hash) {
- addCommentOp := NewAddCommentOp(author, message, files)
- b.Append(addCommentOp)
-}
diff --git a/bug/operations/create.go b/bug/operations/create.go
deleted file mode 100644
index ecbafb6f..00000000
--- a/bug/operations/create.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package operations
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "github.com/MichaelMure/git-bug/util"
-)
-
-// CreateOperation define the initial creation of a bug
-
-var _ bug.Operation = CreateOperation{}
-
-type CreateOperation struct {
- bug.OpBase
- Title string
- Message string
- files []util.Hash
-}
-
-func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
- snapshot.Title = op.Title
- snapshot.Comments = []bug.Comment{
- {
- Message: op.Message,
- Author: op.Author,
- UnixTime: op.UnixTime,
- },
- }
- snapshot.Author = op.Author
- snapshot.CreatedAt = op.Time()
- return snapshot
-}
-
-func (op CreateOperation) Files() []util.Hash {
- return op.files
-}
-
-func NewCreateOp(author bug.Person, title, message string, files []util.Hash) CreateOperation {
- return CreateOperation{
- OpBase: bug.NewOpBase(bug.CreateOp, author),
- Title: title,
- Message: message,
- files: files,
- }
-}
-
-// Convenience function to apply the operation
-func Create(author bug.Person, title, message string) (*bug.Bug, error) {
- return CreateWithFiles(author, title, message, nil)
-}
-
-func CreateWithFiles(author bug.Person, title, message string, files []util.Hash) (*bug.Bug, error) {
- newBug := bug.NewBug()
- createOp := NewCreateOp(author, title, message, files)
- newBug.Append(createOp)
-
- return newBug, nil
-}
diff --git a/bug/operations/create_test.go b/bug/operations/create_test.go
deleted file mode 100644
index a20472d3..00000000
--- a/bug/operations/create_test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package operations
-
-import (
- "github.com/MichaelMure/git-bug/bug"
- "reflect"
- "testing"
-)
-
-func TestCreate(t *testing.T) {
- snapshot := bug.Snapshot{}
-
- var rene = bug.Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
-
- create := NewCreateOp(rene, "title", "message", nil)
-
- snapshot = create.Apply(snapshot)
-
- expected := bug.Snapshot{
- Title: "title",
- Comments: []bug.Comment{
- {Author: rene, Message: "message", UnixTime: create.UnixTime},
- },
- Author: rene,
- CreatedAt: create.Time(),
- }
-
- if !reflect.DeepEqual(snapshot, expected) {
- t.Fatalf("%v different than %v", snapshot, expected)
- }
-}
diff --git a/bug/operations/label_change.go b/bug/operations/label_change.go
deleted file mode 100644
index 551b8be0..00000000
--- a/bug/operations/label_change.go
+++ /dev/null
@@ -1,128 +0,0 @@
-package operations
-
-import (
- "fmt"
- "io"
- "io/ioutil"
- "sort"
-
- "github.com/MichaelMure/git-bug/bug"
-)
-
-var _ bug.Operation = LabelChangeOperation{}
-
-// LabelChangeOperation define a Bug operation to add or remove labels
-type LabelChangeOperation struct {
- bug.OpBase
- Added []bug.Label
- Removed []bug.Label
-}
-
-// Apply apply the operation
-func (op LabelChangeOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
- // Add in the set
-AddLoop:
- for _, added := range op.Added {
- for _, label := range snapshot.Labels {
- if label == added {
- // Already exist
- continue AddLoop
- }
- }
-
- snapshot.Labels = append(snapshot.Labels, added)
- }
-
- // Remove in the set
- for _, removed := range op.Removed {
- for i, label := range snapshot.Labels {
- if label == removed {
- snapshot.Labels[i] = snapshot.Labels[len(snapshot.Labels)-1]
- snapshot.Labels = snapshot.Labels[:len(snapshot.Labels)-1]
- }
- }
- }
-
- // Sort
- sort.Slice(snapshot.Labels, func(i, j int) bool {
- return string(snapshot.Labels[i]) < string(snapshot.Labels[j])
- })
-
- return snapshot
-}
-
-func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation {
- return LabelChangeOperation{
- OpBase: bug.NewOpBase(bug.LabelChangeOp, author),
- Added: added,
- Removed: removed,
- }
-}
-
-// ChangeLabels is a convenience function to apply the operation
-func ChangeLabels(out io.Writer, b bug.Interface, author bug.Person, add, remove []string) error {
- // TODO: return a channel of result (like MergeAll) instead of formatting the result for the upper layers
- var added, removed []bug.Label
-
- if out == nil {
- out = ioutil.Discard
- }
-
- snap := b.Compile()
-
- for _, str := range add {
- label := bug.Label(str)
-
- // check for duplicate
- if labelExist(added, label) {
- fmt.Fprintf(out, "label \"%s\" is a duplicate\n", str)
- continue
- }
-
- // check that the label doesn't already exist
- if labelExist(snap.Labels, label) {
- fmt.Fprintf(out, "label \"%s\" is already set on this bug\n", str)
- continue
- }
-
- added = append(added, label)
- }
-
- for _, str := range remove {
- label := bug.Label(str)
-
- // check for duplicate
- if labelExist(removed, label) {
- fmt.Fprintf(out, "label \"%s\" is a duplicate\n", str)
- continue
- }
-
- // check that the label actually exist
- if !labelExist(snap.Labels, label) {
- fmt.Fprintf(out, "label \"%s\" doesn't exist on this bug\n", str)
- continue
- }
-
- removed = append(removed, label)
- }
-
- if len(added) == 0 && len(removed) == 0 {
- return fmt.Errorf("no label added or removed")
- }
-
- labelOp := NewLabelChangeOperation(author, added, removed)
-
- b.Append(labelOp)
-
- return nil
-}
-
-func labelExist(labels []bug.Label, label bug.Label) bool {
- for _, l := range labels {
- if l == label {
- return true
- }
- }
-
- return false
-}
diff --git a/bug/operations/operations.go b/bug/operations/operations.go
deleted file mode 100644
index 0bfd3b84..00000000
--- a/bug/operations/operations.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package operations
-
-import "encoding/gob"
-
-// Package initialisation used to register operation's type for (de)serialization
-func init() {
- gob.Register(AddCommentOperation{})
- gob.Register(CreateOperation{})
- gob.Register(SetTitleOperation{})
- gob.Register(SetStatusOperation{})
- gob.Register(LabelChangeOperation{})
-}
diff --git a/bug/operations/set_status.go b/bug/operations/set_status.go
deleted file mode 100644
index bafcf5ee..00000000
--- a/bug/operations/set_status.go
+++ /dev/null
@@ -1,39 +0,0 @@
-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 (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
- snapshot.Status = op.Status
-
- return snapshot
-}
-
-func NewSetStatusOp(author bug.Person, status bug.Status) SetStatusOperation {
- return SetStatusOperation{
- OpBase: bug.NewOpBase(bug.SetStatusOp, author),
- Status: status,
- }
-}
-
-// Convenience function to apply the operation
-func Open(b bug.Interface, author bug.Person) {
- op := NewSetStatusOp(author, bug.OpenStatus)
- b.Append(op)
-}
-
-// Convenience function to apply the operation
-func Close(b bug.Interface, author bug.Person) {
- op := NewSetStatusOp(author, bug.ClosedStatus)
- b.Append(op)
-}
diff --git a/bug/operations/set_title.go b/bug/operations/set_title.go
deleted file mode 100644
index 5bd6260a..00000000
--- a/bug/operations/set_title.go
+++ /dev/null
@@ -1,52 +0,0 @@
-package operations
-
-import (
- "github.com/MichaelMure/git-bug/bug"
-)
-
-// SetTitleOperation will change the title of a bug
-
-var _ bug.Operation = SetTitleOperation{}
-
-type SetTitleOperation struct {
- bug.OpBase
- Title string
- Was string
-}
-
-func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
- snapshot.Title = op.Title
-
- return snapshot
-}
-
-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.Interface, author bug.Person, title string) {
- 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)
-}