aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <michael.mure@consensys.net>2018-11-21 18:56:12 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:35:36 +0100
commitfeab9412dffe5772048aad29893c4cb01d566387 (patch)
treeb7bc9751f2ebdf8d41f5621bbf372eaf7625c4b9 /bug
parent0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff)
downloadgit-bug-feab9412dffe5772048aad29893c4cb01d566387.tar.gz
WIP identity in git
Diffstat (limited to 'bug')
-rw-r--r--bug/bug_actions.go5
-rw-r--r--bug/bug_actions_test.go2
-rw-r--r--bug/comment.go3
-rw-r--r--bug/op_add_comment.go8
-rw-r--r--bug/op_create.go8
-rw-r--r--bug/op_create_test.go6
-rw-r--r--bug/op_edit_comment.go8
-rw-r--r--bug/op_edit_comment_test.go6
-rw-r--r--bug/op_label_change.go8
-rw-r--r--bug/op_noop.go9
-rw-r--r--bug/op_set_metadata.go9
-rw-r--r--bug/op_set_metadata_test.go6
-rw-r--r--bug/op_set_status.go9
-rw-r--r--bug/op_set_title.go8
-rw-r--r--bug/operation.go50
-rw-r--r--bug/operation_iterator_test.go7
-rw-r--r--bug/operation_pack.go31
-rw-r--r--bug/operation_test.go11
-rw-r--r--bug/person.go95
-rw-r--r--bug/snapshot.go3
-rw-r--r--bug/timeline.go5
21 files changed, 132 insertions, 165 deletions
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index 487ba25e..a21db826 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -35,6 +35,11 @@ func Pull(repo repository.ClockedRepo, remote string) error {
if merge.Err != nil {
return merge.Err
}
+ if merge.Status == MergeStatusInvalid {
+ // Not awesome: simply output the merge failure here as this function
+ // is only used in tests for now.
+ fmt.Println(merge)
+ }
}
return nil
diff --git a/bug/bug_actions_test.go b/bug/bug_actions_test.go
index a60e5c68..4327ae58 100644
--- a/bug/bug_actions_test.go
+++ b/bug/bug_actions_test.go
@@ -50,7 +50,7 @@ func cleanupRepo(repo repository.Repo) error {
func setupRepos(t testing.TB) (repoA, repoB, remote *repository.GitRepo) {
repoA = createRepo(false)
repoB = createRepo(false)
- remote = createRepo(true)
+ remote = createRepo(false)
remoteAddr := "file://" + remote.GetPath()
diff --git a/bug/comment.go b/bug/comment.go
index 67936634..84d34299 100644
--- a/bug/comment.go
+++ b/bug/comment.go
@@ -1,13 +1,14 @@
package bug
import (
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
"github.com/dustin/go-humanize"
)
// Comment represent a comment in a Bug
type Comment struct {
- Author Person
+ Author identity.Interface
Message string
Files []git.Hash
diff --git a/bug/op_add_comment.go b/bug/op_add_comment.go
index 2d6fb21a..23a10419 100644
--- a/bug/op_add_comment.go
+++ b/bug/op_add_comment.go
@@ -3,6 +3,8 @@ package bug
import (
"fmt"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -68,7 +70,7 @@ func (op *AddCommentOperation) Validate() error {
// Sign post method for gqlgen
func (op *AddCommentOperation) IsAuthored() {}
-func NewAddCommentOp(author Person, unixTime int64, message string, files []git.Hash) *AddCommentOperation {
+func NewAddCommentOp(author identity.Interface, unixTime int64, message string, files []git.Hash) *AddCommentOperation {
return &AddCommentOperation{
OpBase: newOpBase(AddCommentOp, author, unixTime),
Message: message,
@@ -82,11 +84,11 @@ type AddCommentTimelineItem struct {
}
// Convenience function to apply the operation
-func AddComment(b Interface, author Person, unixTime int64, message string) (*AddCommentOperation, error) {
+func AddComment(b Interface, author identity.Interface, unixTime int64, message string) (*AddCommentOperation, error) {
return AddCommentWithFiles(b, author, unixTime, message, nil)
}
-func AddCommentWithFiles(b Interface, author Person, unixTime int64, message string, files []git.Hash) (*AddCommentOperation, error) {
+func AddCommentWithFiles(b Interface, author identity.Interface, unixTime int64, message string, files []git.Hash) (*AddCommentOperation, error) {
addCommentOp := NewAddCommentOp(author, unixTime, message, files)
if err := addCommentOp.Validate(); err != nil {
return nil, err
diff --git a/bug/op_create.go b/bug/op_create.go
index 3816d8b7..01b2bf03 100644
--- a/bug/op_create.go
+++ b/bug/op_create.go
@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -84,7 +86,7 @@ func (op *CreateOperation) Validate() error {
// Sign post method for gqlgen
func (op *CreateOperation) IsAuthored() {}
-func NewCreateOp(author Person, unixTime int64, title, message string, files []git.Hash) *CreateOperation {
+func NewCreateOp(author identity.Interface, unixTime int64, title, message string, files []git.Hash) *CreateOperation {
return &CreateOperation{
OpBase: newOpBase(CreateOp, author, unixTime),
Title: title,
@@ -99,11 +101,11 @@ type CreateTimelineItem struct {
}
// Convenience function to apply the operation
-func Create(author Person, unixTime int64, title, message string) (*Bug, *CreateOperation, error) {
+func Create(author identity.Interface, unixTime int64, title, message string) (*Bug, *CreateOperation, error) {
return CreateWithFiles(author, unixTime, title, message, nil)
}
-func CreateWithFiles(author Person, unixTime int64, title, message string, files []git.Hash) (*Bug, *CreateOperation, error) {
+func CreateWithFiles(author identity.Interface, unixTime int64, title, message string, files []git.Hash) (*Bug, *CreateOperation, error) {
newBug := NewBug()
createOp := NewCreateOp(author, unixTime, title, message, files)
diff --git a/bug/op_create_test.go b/bug/op_create_test.go
index d74051ec..227dea27 100644
--- a/bug/op_create_test.go
+++ b/bug/op_create_test.go
@@ -4,16 +4,14 @@ import (
"testing"
"time"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/go-test/deep"
)
func TestCreate(t *testing.T) {
snapshot := Snapshot{}
- var rene = Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
+ var rene = identity.NewBare("René Descartes", "rene@descartes.fr")
unix := time.Now().Unix()
diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go
index bc87310a..9e0afc02 100644
--- a/bug/op_edit_comment.go
+++ b/bug/op_edit_comment.go
@@ -3,6 +3,8 @@ package bug
import (
"fmt"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -95,7 +97,7 @@ func (op *EditCommentOperation) Validate() error {
// Sign post method for gqlgen
func (op *EditCommentOperation) IsAuthored() {}
-func NewEditCommentOp(author Person, unixTime int64, target git.Hash, message string, files []git.Hash) *EditCommentOperation {
+func NewEditCommentOp(author identity.Interface, unixTime int64, target git.Hash, message string, files []git.Hash) *EditCommentOperation {
return &EditCommentOperation{
OpBase: newOpBase(EditCommentOp, author, unixTime),
Target: target,
@@ -105,11 +107,11 @@ func NewEditCommentOp(author Person, unixTime int64, target git.Hash, message st
}
// Convenience function to apply the operation
-func EditComment(b Interface, author Person, unixTime int64, target git.Hash, message string) (*EditCommentOperation, error) {
+func EditComment(b Interface, author identity.Interface, unixTime int64, target git.Hash, message string) (*EditCommentOperation, error) {
return EditCommentWithFiles(b, author, unixTime, target, message, nil)
}
-func EditCommentWithFiles(b Interface, author Person, unixTime int64, target git.Hash, message string, files []git.Hash) (*EditCommentOperation, error) {
+func EditCommentWithFiles(b Interface, author identity.Interface, unixTime int64, target git.Hash, message string, files []git.Hash) (*EditCommentOperation, error) {
editCommentOp := NewEditCommentOp(author, unixTime, target, message, files)
if err := editCommentOp.Validate(); err != nil {
return nil, err
diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go
index 71a7dda2..ba9bc9d5 100644
--- a/bug/op_edit_comment_test.go
+++ b/bug/op_edit_comment_test.go
@@ -4,16 +4,14 @@ import (
"testing"
"time"
+ "github.com/MichaelMure/git-bug/identity"
"gotest.tools/assert"
)
func TestEdit(t *testing.T) {
snapshot := Snapshot{}
- var rene = Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
+ var rene = identity.NewBare("René Descartes", "rene@descartes.fr")
unix := time.Now().Unix()
diff --git a/bug/op_label_change.go b/bug/op_label_change.go
index d7aab06b..5d0b6a78 100644
--- a/bug/op_label_change.go
+++ b/bug/op_label_change.go
@@ -4,6 +4,8 @@ import (
"fmt"
"sort"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/pkg/errors"
)
@@ -100,7 +102,7 @@ func (op *LabelChangeOperation) Validate() error {
// Sign post method for gqlgen
func (op *LabelChangeOperation) IsAuthored() {}
-func NewLabelChangeOperation(author Person, unixTime int64, added, removed []Label) *LabelChangeOperation {
+func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, removed []Label) *LabelChangeOperation {
return &LabelChangeOperation{
OpBase: newOpBase(LabelChangeOp, author, unixTime),
Added: added,
@@ -110,7 +112,7 @@ func NewLabelChangeOperation(author Person, unixTime int64, added, removed []Lab
type LabelChangeTimelineItem struct {
hash git.Hash
- Author Person
+ Author identity.Interface
UnixTime Timestamp
Added []Label
Removed []Label
@@ -121,7 +123,7 @@ func (l LabelChangeTimelineItem) Hash() git.Hash {
}
// ChangeLabels is a convenience function to apply the operation
-func ChangeLabels(b Interface, author Person, unixTime int64, add, remove []string) ([]LabelChangeResult, *LabelChangeOperation, error) {
+func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string) ([]LabelChangeResult, *LabelChangeOperation, error) {
var added, removed []Label
var results []LabelChangeResult
diff --git a/bug/op_noop.go b/bug/op_noop.go
index ac898dde..410799b3 100644
--- a/bug/op_noop.go
+++ b/bug/op_noop.go
@@ -1,6 +1,9 @@
package bug
-import "github.com/MichaelMure/git-bug/util/git"
+import (
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/git"
+)
var _ Operation = &NoOpOperation{}
@@ -30,14 +33,14 @@ func (op *NoOpOperation) Validate() error {
// Sign post method for gqlgen
func (op *NoOpOperation) IsAuthored() {}
-func NewNoOpOp(author Person, unixTime int64) *NoOpOperation {
+func NewNoOpOp(author identity.Interface, unixTime int64) *NoOpOperation {
return &NoOpOperation{
OpBase: newOpBase(NoOpOp, author, unixTime),
}
}
// Convenience function to apply the operation
-func NoOp(b Interface, author Person, unixTime int64, metadata map[string]string) (*NoOpOperation, error) {
+func NoOp(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*NoOpOperation, error) {
op := NewNoOpOp(author, unixTime)
for key, value := range metadata {
diff --git a/bug/op_set_metadata.go b/bug/op_set_metadata.go
index aac81f3b..e18f1cb6 100644
--- a/bug/op_set_metadata.go
+++ b/bug/op_set_metadata.go
@@ -1,6 +1,9 @@
package bug
-import "github.com/MichaelMure/git-bug/util/git"
+import (
+ "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/util/git"
+)
var _ Operation = &SetMetadataOperation{}
@@ -56,7 +59,7 @@ func (op *SetMetadataOperation) Validate() error {
// Sign post method for gqlgen
func (op *SetMetadataOperation) IsAuthored() {}
-func NewSetMetadataOp(author Person, unixTime int64, target git.Hash, newMetadata map[string]string) *SetMetadataOperation {
+func NewSetMetadataOp(author identity.Interface, unixTime int64, target git.Hash, newMetadata map[string]string) *SetMetadataOperation {
return &SetMetadataOperation{
OpBase: newOpBase(SetMetadataOp, author, unixTime),
Target: target,
@@ -65,7 +68,7 @@ func NewSetMetadataOp(author Person, unixTime int64, target git.Hash, newMetadat
}
// Convenience function to apply the operation
-func SetMetadata(b Interface, author Person, unixTime int64, target git.Hash, newMetadata map[string]string) (*SetMetadataOperation, error) {
+func SetMetadata(b Interface, author identity.Interface, unixTime int64, target git.Hash, newMetadata map[string]string) (*SetMetadataOperation, error) {
SetMetadataOp := NewSetMetadataOp(author, unixTime, target, newMetadata)
if err := SetMetadataOp.Validate(); err != nil {
return nil, err
diff --git a/bug/op_set_metadata_test.go b/bug/op_set_metadata_test.go
index 068e2bb0..c6f5c3c1 100644
--- a/bug/op_set_metadata_test.go
+++ b/bug/op_set_metadata_test.go
@@ -4,16 +4,14 @@ import (
"testing"
"time"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/stretchr/testify/assert"
)
func TestSetMetadata(t *testing.T) {
snapshot := Snapshot{}
- var rene = Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
+ var rene = identity.NewBare("René Descartes", "rene@descartes.fr")
unix := time.Now().Unix()
diff --git a/bug/op_set_status.go b/bug/op_set_status.go
index 54f476cb..9fc64e52 100644
--- a/bug/op_set_status.go
+++ b/bug/op_set_status.go
@@ -1,6 +1,7 @@
package bug
import (
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
"github.com/pkg/errors"
)
@@ -56,7 +57,7 @@ func (op *SetStatusOperation) Validate() error {
// Sign post method for gqlgen
func (op *SetStatusOperation) IsAuthored() {}
-func NewSetStatusOp(author Person, unixTime int64, status Status) *SetStatusOperation {
+func NewSetStatusOp(author identity.Interface, unixTime int64, status Status) *SetStatusOperation {
return &SetStatusOperation{
OpBase: newOpBase(SetStatusOp, author, unixTime),
Status: status,
@@ -65,7 +66,7 @@ func NewSetStatusOp(author Person, unixTime int64, status Status) *SetStatusOper
type SetStatusTimelineItem struct {
hash git.Hash
- Author Person
+ Author identity.Interface
UnixTime Timestamp
Status Status
}
@@ -75,7 +76,7 @@ func (s SetStatusTimelineItem) Hash() git.Hash {
}
// Convenience function to apply the operation
-func Open(b Interface, author Person, unixTime int64) (*SetStatusOperation, error) {
+func Open(b Interface, author identity.Interface, unixTime int64) (*SetStatusOperation, error) {
op := NewSetStatusOp(author, unixTime, OpenStatus)
if err := op.Validate(); err != nil {
return nil, err
@@ -85,7 +86,7 @@ func Open(b Interface, author Person, unixTime int64) (*SetStatusOperation, erro
}
// Convenience function to apply the operation
-func Close(b Interface, author Person, unixTime int64) (*SetStatusOperation, error) {
+func Close(b Interface, author identity.Interface, unixTime int64) (*SetStatusOperation, error) {
op := NewSetStatusOp(author, unixTime, ClosedStatus)
if err := op.Validate(); err != nil {
return nil, err
diff --git a/bug/op_set_title.go b/bug/op_set_title.go
index b631ca18..3b253c06 100644
--- a/bug/op_set_title.go
+++ b/bug/op_set_title.go
@@ -4,6 +4,8 @@ import (
"fmt"
"strings"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/MichaelMure/git-bug/util/text"
)
@@ -77,7 +79,7 @@ func (op *SetTitleOperation) Validate() error {
// Sign post method for gqlgen
func (op *SetTitleOperation) IsAuthored() {}
-func NewSetTitleOp(author Person, unixTime int64, title string, was string) *SetTitleOperation {
+func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was string) *SetTitleOperation {
return &SetTitleOperation{
OpBase: newOpBase(SetTitleOp, author, unixTime),
Title: title,
@@ -87,7 +89,7 @@ func NewSetTitleOp(author Person, unixTime int64, title string, was string) *Set
type SetTitleTimelineItem struct {
hash git.Hash
- Author Person
+ Author identity.Interface
UnixTime Timestamp
Title string
Was string
@@ -98,7 +100,7 @@ func (s SetTitleTimelineItem) Hash() git.Hash {
}
// Convenience function to apply the operation
-func SetTitle(b Interface, author Person, unixTime int64, title string) (*SetTitleOperation, error) {
+func SetTitle(b Interface, author identity.Interface, unixTime int64, title string) (*SetTitleOperation, error) {
it := NewOperationIterator(b)
var lastTitleOp Operation
diff --git a/bug/operation.go b/bug/operation.go
index 592b5616..8dec5644 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -6,6 +6,8 @@ import (
"fmt"
"time"
+ "github.com/MichaelMure/git-bug/identity"
+
"github.com/MichaelMure/git-bug/util/git"
"github.com/pkg/errors"
)
@@ -74,21 +76,23 @@ func hashOperation(op Operation) (git.Hash, error) {
return base.hash, nil
}
+// TODO: serialization with identity
+
// OpBase implement the common code for all operations
type OpBase struct {
- OperationType OperationType `json:"type"`
- Author Person `json:"author"`
- UnixTime int64 `json:"timestamp"`
- Metadata map[string]string `json:"metadata,omitempty"`
+ OperationType OperationType
+ Author identity.Interface
+ UnixTime int64
+ Metadata map[string]string
// Not serialized. Store the op's hash in memory.
hash git.Hash
- // Not serialized. Store the extra metadata compiled from SetMetadataOperation
- // in memory.
+ // Not serialized. Store the extra metadata in memory,
+ // compiled from SetMetadataOperation.
extraMetadata map[string]string
}
// newOpBase is the constructor for an OpBase
-func newOpBase(opType OperationType, author Person, unixTime int64) OpBase {
+func newOpBase(opType OperationType, author identity.Interface, unixTime int64) OpBase {
return OpBase{
OperationType: opType,
Author: author,
@@ -96,6 +100,34 @@ func newOpBase(opType OperationType, author Person, unixTime int64) OpBase {
}
}
+type opBaseJson struct {
+ OperationType OperationType `json:"type"`
+ UnixTime int64 `json:"timestamp"`
+ Metadata map[string]string `json:"metadata,omitempty"`
+}
+
+func (op *OpBase) MarshalJSON() ([]byte, error) {
+ return json.Marshal(opBaseJson{
+ OperationType: op.OperationType,
+ UnixTime: op.UnixTime,
+ Metadata: op.Metadata,
+ })
+}
+
+func (op *OpBase) UnmarshalJSON(data []byte) error {
+ aux := opBaseJson{}
+
+ if err := json.Unmarshal(data, &aux); err != nil {
+ return err
+ }
+
+ op.OperationType = aux.OperationType
+ op.UnixTime = aux.UnixTime
+ op.Metadata = aux.Metadata
+
+ return nil
+}
+
// Time return the time when the operation was added
func (op *OpBase) Time() time.Time {
return time.Unix(op.UnixTime, 0)
@@ -125,6 +157,10 @@ func opBaseValidate(op Operation, opType OperationType) error {
return fmt.Errorf("time not set")
}
+ if op.base().Author == nil {
+ return fmt.Errorf("author not set")
+ }
+
if err := op.base().Author.Validate(); err != nil {
return errors.Wrap(err, "author")
}
diff --git a/bug/operation_iterator_test.go b/bug/operation_iterator_test.go
index 506cc94f..6b32cfc4 100644
--- a/bug/operation_iterator_test.go
+++ b/bug/operation_iterator_test.go
@@ -1,17 +1,14 @@
package bug
import (
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
"testing"
"time"
)
var (
- rene = Person{
- Name: "René Descartes",
- Email: "rene@descartes.fr",
- }
-
+ rene = identity.NewBare("René Descartes", "rene@descartes.fr")
unix = time.Now().Unix()
createOp = NewCreateOp(rene, unix, "title", "message", nil)
diff --git a/bug/operation_pack.go b/bug/operation_pack.go
index f33d94bf..fc395d90 100644
--- a/bug/operation_pack.go
+++ b/bug/operation_pack.go
@@ -20,7 +20,7 @@ const formatVersion = 1
type OperationPack struct {
Operations []Operation
- // Private field so not serialized by gob
+ // Private field so not serialized
commitHash git.Hash
}
@@ -57,6 +57,7 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
return err
}
+ // delegate to specialized unmarshal function
op, err := opp.unmarshalOp(raw, t.OperationType)
if err != nil {
return err
@@ -73,28 +74,36 @@ func (opp *OperationPack) UnmarshalJSON(data []byte) error {
func (opp *OperationPack) unmarshalOp(raw []byte, _type OperationType) (Operation, error) {
switch _type {
+ case AddCommentOp:
+ op := &AddCommentOperation{}
+ err := json.Unmarshal(raw, &op)
+ return op, err
case CreateOp:
op := &CreateOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case SetTitleOp:
- op := &SetTitleOperation{}
+ case EditCommentOp:
+ op := &EditCommentOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case AddCommentOp:
- op := &AddCommentOperation{}
+ case LabelChangeOp:
+ op := &LabelChangeOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case SetStatusOp:
- op := &SetStatusOperation{}
+ case NoOpOp:
+ op := &NoOpOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case LabelChangeOp:
- op := &LabelChangeOperation{}
+ case SetMetadataOp:
+ op := &SetMetadataOperation{}
err := json.Unmarshal(raw, &op)
return op, err
- case EditCommentOp:
- op := &EditCommentOperation{}
+ case SetStatusOp:
+ op := &SetStatusOperation{}
+ err := json.Unmarshal(raw, &op)
+ return op, err
+ case SetTitleOp:
+ op := &SetTitleOperation{}
err := json.Unmarshal(raw, &op)
return op, err
default:
diff --git a/bug/operation_test.go b/bug/operation_test.go
index 255d6d98..0e2afc6c 100644
--- a/bug/operation_test.go
+++ b/bug/operation_test.go
@@ -3,6 +3,7 @@ package bug
import (
"testing"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/git"
"github.com/stretchr/testify/require"
@@ -25,11 +26,11 @@ func TestValidate(t *testing.T) {
bad := []Operation{
// opbase
- NewSetStatusOp(Person{Name: "", Email: "rene@descartes.fr"}, unix, ClosedStatus),
- NewSetStatusOp(Person{Name: "René Descartes\u001b", Email: "rene@descartes.fr"}, unix, ClosedStatus),
- NewSetStatusOp(Person{Name: "René Descartes", Email: "rene@descartes.fr\u001b"}, unix, ClosedStatus),
- NewSetStatusOp(Person{Name: "René \nDescartes", Email: "rene@descartes.fr"}, unix, ClosedStatus),
- NewSetStatusOp(Person{Name: "René Descartes", Email: "rene@\ndescartes.fr"}, unix, ClosedStatus),
+ NewSetStatusOp(identity.NewBare("", "rene@descartes.fr"), unix, ClosedStatus),
+ NewSetStatusOp(identity.NewBare("René Descartes\u001b", "rene@descartes.fr"), unix, ClosedStatus),
+ NewSetStatusOp(identity.NewBare("René Descartes", "rene@descartes.fr\u001b"), unix, ClosedStatus),
+ NewSetStatusOp(identity.NewBare("René \nDescartes", "rene@descartes.fr"), unix, ClosedStatus),
+ NewSetStatusOp(identity.NewBare("René Descartes", "rene@\ndescartes.fr"), unix, ClosedStatus),
&CreateOperation{OpBase: OpBase{
Author: rene,
UnixTime: 0,
diff --git a/bug/person.go b/bug/person.go
deleted file mode 100644
index 449e2262..00000000
--- a/bug/person.go
+++ /dev/null
@@ -1,95 +0,0 @@
-package bug
-
-import (
- "errors"
- "fmt"
- "strings"
-
- "github.com/MichaelMure/git-bug/repository"
- "github.com/MichaelMure/git-bug/util/text"
-)
-
-type Person struct {
- Name string `json:"name"`
- Email string `json:"email"`
- Login string `json:"login"`
- AvatarUrl string `json:"avatar_url"`
-}
-
-// GetUser will query the repository for user detail and build the corresponding Person
-func GetUser(repo repository.Repo) (Person, error) {
- name, err := repo.GetUserName()
- if err != nil {
- return Person{}, err
- }
- if name == "" {
- return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.name \"John Doe\"`")
- }
-
- email, err := repo.GetUserEmail()
- if err != nil {
- return Person{}, err
- }
- if email == "" {
- return Person{}, errors.New("User name is not configured in git yet. Please use `git config --global user.email johndoe@example.com`")
- }
-
- return Person{Name: name, Email: email}, nil
-}
-
-// Match tell is the Person match the given query string
-func (p Person) Match(query string) bool {
- query = strings.ToLower(query)
-
- return strings.Contains(strings.ToLower(p.Name), query) ||
- strings.Contains(strings.ToLower(p.Login), query)
-}
-
-func (p Person) Validate() error {
- if text.Empty(p.Name) && text.Empty(p.Login) {
- return fmt.Errorf("either name or login should be set")
- }
-
- if strings.Contains(p.Name, "\n") {
- return fmt.Errorf("name should be a single line")
- }
-
- if !text.Safe(p.Name) {
- return fmt.Errorf("name is not fully printable")
- }
-
- if strings.Contains(p.Login, "\n") {
- return fmt.Errorf("login should be a single line")
- }
-
- if !text.Safe(p.Login) {
- return fmt.Errorf("login is not fully printable")
- }
-
- if strings.Contains(p.Email, "\n") {
- return fmt.Errorf("email should be a single line")
- }
-
- if !text.Safe(p.Email) {
- return fmt.Errorf("email is not fully printable")
- }
-
- if p.AvatarUrl != "" && !text.ValidUrl(p.AvatarUrl) {
- return fmt.Errorf("avatarUrl is not a valid URL")
- }
-
- return nil
-}
-
-func (p Person) DisplayName() string {
- switch {
- case p.Name == "" && p.Login != "":
- return p.Login
- case p.Name != "" && p.Login == "":
- return p.Name
- case p.Name != "" && p.Login != "":
- return fmt.Sprintf("%s (%s)", p.Name, p.Login)
- }
-
- panic("invalid person data")
-}
diff --git a/bug/snapshot.go b/bug/snapshot.go
index 72e673d4..46618ebd 100644
--- a/bug/snapshot.go
+++ b/bug/snapshot.go
@@ -4,6 +4,7 @@ import (
"fmt"
"time"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
)
@@ -15,7 +16,7 @@ type Snapshot struct {
Title string
Comments []Comment
Labels []Label
- Author Person
+ Author identity.Interface
CreatedAt time.Time
Timeline []TimelineItem
diff --git a/bug/timeline.go b/bug/timeline.go
index a84c45e4..306ffa9e 100644
--- a/bug/timeline.go
+++ b/bug/timeline.go
@@ -3,6 +3,7 @@ package bug
import (
"strings"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/git"
)
@@ -15,7 +16,7 @@ type TimelineItem interface {
type CommentHistoryStep struct {
// The author of the edition, not necessarily the same as the author of the
// original comment
- Author Person
+ Author identity.Interface
// The new message
Message string
UnixTime Timestamp
@@ -24,7 +25,7 @@ type CommentHistoryStep struct {
// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
type CommentTimelineItem struct {
hash git.Hash
- Author Person
+ Author identity.Interface
Message string
Files []git.Hash
CreatedAt Timestamp