aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-02 23:37:49 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-02 23:37:49 +0200
commitd8f89726fec3822d7d1dd42c52f478f37003b534 (patch)
tree567e97ee605ef3a286e42e11535fa6516321e743 /bug
parented8f7eca9a8e0d1c448a7cc6240e2b7e357cf354 (diff)
downloadgit-bug-d8f89726fec3822d7d1dd42c52f478f37003b534.tar.gz
implement media hosting in git for comments + API for the webui
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go25
-rw-r--r--bug/comment.go2
-rw-r--r--bug/label.go2
-rw-r--r--bug/operation.go6
-rw-r--r--bug/operations/add_comment.go16
-rw-r--r--bug/operations/create.go15
-rw-r--r--bug/operations/label_change.go5
-rw-r--r--bug/operations/set_status.go5
-rw-r--r--bug/operations/set_title.go5
9 files changed, 71 insertions, 10 deletions
diff --git a/bug/bug.go b/bug/bug.go
index d3cc41dd..61f58c78 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -259,7 +259,7 @@ func (bug *Bug) Append(op Operation) {
// Write the staging area in Git and move the operations to the packs
func (bug *Bug) Commit(repo repository.Repo) error {
if bug.staging.IsEmpty() {
- return fmt.Errorf("can't commit an empty bug")
+ return fmt.Errorf("can't commit a bug with no pending operation")
}
// Write the Ops as a Git blob containing the serialized array
@@ -272,14 +272,31 @@ func (bug *Bug) Commit(repo repository.Repo) error {
bug.rootPack = hash
}
- // Write a Git tree referencing this blob
- hash, err = repo.StoreTree([]repository.TreeEntry{
+ // Make a Git tree referencing this blob and all needed files
+ tree := []repository.TreeEntry{
// the last pack of ops
{ObjectType: repository.Blob, Hash: hash, Name: opsEntryName},
// always the first pack of ops (might be the same)
{ObjectType: repository.Blob, Hash: bug.rootPack, Name: rootEntryName},
- })
+ }
+
+ counter := 0
+ added := make(map[util.Hash]interface{})
+ for _, ops := range bug.staging.Operations {
+ for _, file := range ops.Files() {
+ if _, has := added[file]; !has {
+ tree = append(tree, repository.TreeEntry{
+ ObjectType: repository.Blob,
+ Hash: file,
+ Name: fmt.Sprintf("file%d", counter),
+ })
+ counter++
+ added[file] = struct{}{}
+ }
+ }
+ }
+ hash, err = repo.StoreTree(tree)
if err != nil {
return err
}
diff --git a/bug/comment.go b/bug/comment.go
index c0c07076..0b4fd6ad 100644
--- a/bug/comment.go
+++ b/bug/comment.go
@@ -1,6 +1,7 @@
package bug
import (
+ "github.com/MichaelMure/git-bug/util"
"github.com/dustin/go-humanize"
"time"
)
@@ -8,6 +9,7 @@ import (
type Comment struct {
Author Person
Message string
+ Files []util.Hash
// Creation time of the comment.
// Should be used only for human display, never for ordering as we can't rely on it in a distributed system.
diff --git a/bug/label.go b/bug/label.go
index ccfa15f4..b19a980f 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -11,7 +11,7 @@ func (l Label) String() string {
return string(l)
}
-// UnmarshalGQL implements the graphql.Marshaler interface
+// UnmarshalGQL implements the graphql.Unmarshaler interface
func (l *Label) UnmarshalGQL(v interface{}) error {
_, ok := v.(string)
if !ok {
diff --git a/bug/operation.go b/bug/operation.go
index 74be2fac..736c88dd 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -1,6 +1,9 @@
package bug
-import "time"
+import (
+ "github.com/MichaelMure/git-bug/util"
+ "time"
+)
type OperationType int
@@ -17,6 +20,7 @@ type Operation interface {
OpType() OperationType
Time() time.Time
Apply(snapshot Snapshot) Snapshot
+ Files() []util.Hash
// TODO: data validation (ex: a title is a single line)
// Validate() bool
diff --git a/bug/operations/add_comment.go b/bug/operations/add_comment.go
index f35c572b..f2e76b73 100644
--- a/bug/operations/add_comment.go
+++ b/bug/operations/add_comment.go
@@ -2,6 +2,7 @@ package operations
import (
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/util"
)
// AddCommentOperation will add a new comment in the bug
@@ -11,12 +12,14 @@ var _ bug.Operation = AddCommentOperation{}
type AddCommentOperation struct {
bug.OpBase
Message string
+ 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,
}
@@ -25,15 +28,24 @@ func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
return snapshot
}
-func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
+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.Bug, author bug.Person, message string) {
- addCommentOp := NewAddCommentOp(author, message)
+ CommentWithFiles(b, author, message, nil)
+}
+
+func CommentWithFiles(b *bug.Bug, 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
index 0ee7e857..ecbafb6f 100644
--- a/bug/operations/create.go
+++ b/bug/operations/create.go
@@ -2,6 +2,7 @@ package operations
import (
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/util"
)
// CreateOperation define the initial creation of a bug
@@ -12,6 +13,7 @@ type CreateOperation struct {
bug.OpBase
Title string
Message string
+ files []util.Hash
}
func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
@@ -28,18 +30,27 @@ func (op CreateOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
return snapshot
}
-func NewCreateOp(author bug.Person, title, message string) CreateOperation {
+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)
+ createOp := NewCreateOp(author, title, message, files)
newBug.Append(createOp)
return newBug, nil
diff --git a/bug/operations/label_change.go b/bug/operations/label_change.go
index a711faef..f289fedc 100644
--- a/bug/operations/label_change.go
+++ b/bug/operations/label_change.go
@@ -3,6 +3,7 @@ package operations
import (
"fmt"
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/util"
"io"
"io/ioutil"
"sort"
@@ -50,6 +51,10 @@ AddLoop:
return snapshot
}
+func (op LabelChangeOperation) Files() []util.Hash {
+ return nil
+}
+
func NewLabelChangeOperation(author bug.Person, added, removed []bug.Label) LabelChangeOperation {
return LabelChangeOperation{
OpBase: bug.NewOpBase(bug.LabelChangeOp, author),
diff --git a/bug/operations/set_status.go b/bug/operations/set_status.go
index ed6c328c..87ca14bf 100644
--- a/bug/operations/set_status.go
+++ b/bug/operations/set_status.go
@@ -2,6 +2,7 @@ package operations
import (
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/util"
)
// SetStatusOperation will change the status of a bug
@@ -19,6 +20,10 @@ func (op SetStatusOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
return snapshot
}
+func (op SetStatusOperation) Files() []util.Hash {
+ return nil
+}
+
func NewSetStatusOp(author bug.Person, status bug.Status) SetStatusOperation {
return SetStatusOperation{
OpBase: bug.NewOpBase(bug.SetStatusOp, author),
diff --git a/bug/operations/set_title.go b/bug/operations/set_title.go
index fab01d8a..d6186f41 100644
--- a/bug/operations/set_title.go
+++ b/bug/operations/set_title.go
@@ -2,6 +2,7 @@ package operations
import (
"github.com/MichaelMure/git-bug/bug"
+ "github.com/MichaelMure/git-bug/util"
)
// SetTitleOperation will change the title of a bug
@@ -19,6 +20,10 @@ func (op SetTitleOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
return snapshot
}
+func (op SetTitleOperation) Files() []util.Hash {
+ return nil
+}
+
func NewSetTitleOp(author bug.Person, title string) SetTitleOperation {
return SetTitleOperation{
OpBase: bug.NewOpBase(bug.SetTitleOp, author),