From d179b8b7ec7815ccac73e00f35f5cfbdc4ddbe2e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 31 Jul 2022 14:38:32 +0200 Subject: bug: fix an issue where Id would be used, then changed due to metadata --- bug/op_create.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'bug/op_create.go') diff --git a/bug/op_create.go b/bug/op_create.go index ed2fd994..ca4f3d8a 100644 --- a/bug/op_create.go +++ b/bug/op_create.go @@ -97,20 +97,16 @@ type CreateTimelineItem struct { // IsAuthored is a sign post method for gqlgen func (c *CreateTimelineItem) IsAuthored() {} -// Convenience function to apply the operation -func Create(author identity.Interface, unixTime int64, title, message string) (*Bug, *CreateOperation, error) { - return CreateWithFiles(author, unixTime, title, message, nil) -} - -func CreateWithFiles(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) (*Bug, *CreateOperation, error) { - newBug := NewBug() - createOp := NewCreateOp(author, unixTime, title, message, files) - - if err := createOp.Validate(); err != nil { - return nil, createOp, err +// Create is a convenience function to create a bug +func Create(author identity.Interface, unixTime int64, title, message string, files []repository.Hash, metadata map[string]string) (*Bug, *CreateOperation, error) { + b := NewBug() + op := NewCreateOp(author, unixTime, title, message, files) + for key, val := range metadata { + op.SetMetadata(key, val) } - - newBug.Append(createOp) - - return newBug, createOp, nil + if err := op.Validate(); err != nil { + return nil, op, err + } + b.Append(op) + return b, op, nil } -- cgit