some cleaning

Michael Muré created

Change summary

bug/operations/add_comment.go  | 15 ++++++++-------
bug/operations/create.go       | 17 +++++++++--------
bug/operations/label_change.go | 17 +++++++++--------
bug/operations/set_status.go   | 14 ++++++++------
bug/operations/set_title.go    | 13 +++++++------
5 files changed, 41 insertions(+), 35 deletions(-)

Detailed changes

bug/operations/add_comment.go 🔗

@@ -13,13 +13,6 @@ type AddCommentOperation struct {
 	Message string
 }
 
-func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
-	return AddCommentOperation{
-		OpBase:  bug.NewOpBase(bug.AddCommentOp, author),
-		Message: message,
-	}
-}
-
 func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
 	comment := bug.Comment{
 		Message:  op.Message,
@@ -32,6 +25,14 @@ func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
 	return snapshot
 }
 
+func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
+	return AddCommentOperation{
+		OpBase:  bug.NewOpBase(bug.AddCommentOp, author),
+		Message: message,
+	}
+}
+
+// Convenience function to apply the operation
 func Comment(b *bug.Bug, author bug.Person, message string) {
 	addCommentOp := NewAddCommentOp(author, message)
 	b.Append(addCommentOp)

bug/operations/create.go 🔗

@@ -14,14 +14,6 @@ type CreateOperation struct {
 	Message string
 }
 
-func NewCreateOp(author bug.Person, title, message string) CreateOperation {
-	return CreateOperation{
-		OpBase:  bug.NewOpBase(bug.CreateOp, author),
-		Title:   title,
-		Message: message,
-	}
-}
-
 func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
 	snapshot.Title = op.Title
 	snapshot.Comments = []bug.Comment{
@@ -34,6 +26,15 @@ func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
 	return snapshot
 }
 
+func NewCreateOp(author bug.Person, title, message string) CreateOperation {
+	return CreateOperation{
+		OpBase:  bug.NewOpBase(bug.CreateOp, author),
+		Title:   title,
+		Message: message,
+	}
+}
+
+// Convenience function to apply the operation
 func Create(author bug.Person, title, message string) (*bug.Bug, error) {
 	newBug := bug.NewBug()
 	createOp := NewCreateOp(author, title, message)

bug/operations/label_change.go 🔗

@@ -17,14 +17,6 @@ type LabelChangeOperation struct {
 	Removed []bug.Label
 }
 
-func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation {
-	return LabelChangeOperation{
-		OpBase:  bug.NewOpBase(bug.LabelChangeOp, author),
-		Added:   added,
-		Removed: removed,
-	}
-}
-
 func (op LabelChangeOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
 	// Add in the set
 AddLoop:
@@ -57,6 +49,15 @@ AddLoop:
 	return snapshot
 }
 
+func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation {
+	return LabelChangeOperation{
+		OpBase:  bug.NewOpBase(bug.LabelChangeOp, author),
+		Added:   added,
+		Removed: removed,
+	}
+}
+
+// Convenience function to apply the operation
 func ChangeLabels(out io.Writer, b *bug.Bug, author bug.Person, add, remove []string) error {
 	var added, removed []bug.Label
 

bug/operations/set_status.go 🔗

@@ -13,6 +13,12 @@ type SetStatusOperation struct {
 	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),
@@ -20,17 +26,13 @@ func NewSetStatusOp(author bug.Person, status bug.Status) SetStatusOperation {
 	}
 }
 
-func (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
-	snapshot.Status = op.Status
-
-	return snapshot
-}
-
+// Convenience function to apply the operation
 func Open(b *bug.Bug, author bug.Person) {
 	op := NewSetStatusOp(author, bug.OpenStatus)
 	b.Append(op)
 }
 
+// Convenience function to apply the operation
 func Close(b *bug.Bug, author bug.Person) {
 	op := NewSetStatusOp(author, bug.ClosedStatus)
 	b.Append(op)

bug/operations/set_title.go 🔗

@@ -13,6 +13,12 @@ type SetTitleOperation struct {
 	Title string
 }
 
+func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
+	snapshot.Title = op.Title
+
+	return snapshot
+}
+
 func NewSetTitleOp(author bug.Person, title string) SetTitleOperation {
 	return SetTitleOperation{
 		OpBase: bug.NewOpBase(bug.SetTitleOp, author),
@@ -20,12 +26,7 @@ func NewSetTitleOp(author bug.Person, title string) SetTitleOperation {
 	}
 }
 
-func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
-	snapshot.Title = op.Title
-
-	return snapshot
-}
-
+// Convenience function to apply the operation
 func SetTitle(b *bug.Bug, author bug.Person, title string) {
 	setTitleOp := NewSetTitleOp(author, title)
 	b.Append(setTitleOp)