diff options
Diffstat (limited to 'entities')
26 files changed, 86 insertions, 159 deletions
diff --git a/entities/bug/bug_actions.go b/entities/bug/bug_actions.go index 651d24dc0..1d1bda78f 100644 --- a/entities/bug/bug_actions.go +++ b/entities/bug/bug_actions.go @@ -1,7 +1,6 @@ package bug import ( - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" @@ -22,14 +21,14 @@ func Push(repo repository.Repo, remote string) (string, error) { // This function will return an error if a merge fail // Note: an author is necessary for the case where a merge commit is created, as this commit will // have an author and may be signed if a signing key is available. -func Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) error { +func Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor entity.Identity) error { return dag.Pull(def, wrapper, repo, resolvers, remote, mergeAuthor) } // MergeAll will merge all the available remote bug // Note: an author is necessary for the case where a merge commit is created, as this commit will // have an author and may be signed if a signing key is available. -func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult { +func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor entity.Identity) <-chan entity.MergeResult { return dag.MergeAll(def, wrapper, repo, resolvers, remote, mergeAuthor) } diff --git a/entities/bug/comment.go b/entities/bug/comment.go index 7835c5a8a..15fb6a5d0 100644 --- a/entities/bug/comment.go +++ b/entities/bug/comment.go @@ -3,7 +3,6 @@ package bug import ( "github.com/dustin/go-humanize" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" @@ -18,7 +17,7 @@ type Comment struct { // targetId is the Id of the Operation that originally created that Comment targetId entity.Id - Author identity.Interface + Author entity.Identity Message string Files []repository.Hash diff --git a/entities/bug/op_add_comment.go b/entities/bug/op_add_comment.go index 17cc5dd05..833aa894e 100644 --- a/entities/bug/op_add_comment.go +++ b/entities/bug/op_add_comment.go @@ -3,7 +3,6 @@ package bug import ( "fmt" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" @@ -72,7 +71,7 @@ func (op *AddCommentOperation) Validate() error { return nil } -func NewAddCommentOp(author identity.Interface, unixTime int64, message string, files []repository.Hash) *AddCommentOperation { +func NewAddCommentOp(author entity.Identity, unixTime int64, message string, files []repository.Hash) *AddCommentOperation { return &AddCommentOperation{ OpBase: dag.NewOpBase(AddCommentOp, author, unixTime), Message: message, @@ -89,7 +88,7 @@ type AddCommentTimelineItem struct { func (a *AddCommentTimelineItem) IsAuthored() {} // AddComment is a convenience function to add a comment to a bug -func AddComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *AddCommentOperation, error) { +func AddComment(b Interface, author entity.Identity, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *AddCommentOperation, error) { op := NewAddCommentOp(author, unixTime, message, files) for key, val := range metadata { op.SetMetadata(key, val) diff --git a/entities/bug/op_add_comment_test.go b/entities/bug/op_add_comment_test.go index fee9e785c..7727c45b9 100644 --- a/entities/bug/op_add_comment_test.go +++ b/entities/bug/op_add_comment_test.go @@ -3,17 +3,16 @@ package bug import ( "testing" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" ) func TestAddCommentSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddCommentOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*AddCommentOperation, entity.Resolvers) { return NewAddCommentOp(author, unixTime, "message", nil), nil }) - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*AddCommentOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*AddCommentOperation, entity.Resolvers) { return NewAddCommentOp(author, unixTime, "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_create.go b/entities/bug/op_create.go index 63eb438d0..33504e3d0 100644 --- a/entities/bug/op_create.go +++ b/entities/bug/op_create.go @@ -3,7 +3,6 @@ package bug import ( "fmt" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" @@ -89,7 +88,7 @@ func (op *CreateOperation) Validate() error { return nil } -func NewCreateOp(author identity.Interface, unixTime int64, title, message string, files []repository.Hash) *CreateOperation { +func NewCreateOp(author entity.Identity, unixTime int64, title, message string, files []repository.Hash) *CreateOperation { return &CreateOperation{ OpBase: dag.NewOpBase(CreateOp, author, unixTime), Title: title, @@ -107,7 +106,7 @@ type CreateTimelineItem struct { func (c *CreateTimelineItem) IsAuthored() {} // 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) { +func Create(author entity.Identity, 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 { diff --git a/entities/bug/op_create_test.go b/entities/bug/op_create_test.go index d8bde46f1..f340876fa 100644 --- a/entities/bug/op_create_test.go +++ b/entities/bug/op_create_test.go @@ -40,10 +40,10 @@ func TestCreate(t *testing.T) { } func TestCreateSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*CreateOperation, entity.Resolvers) { return NewCreateOp(author, unixTime, "title", "message", nil), nil }) - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*CreateOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*CreateOperation, entity.Resolvers) { return NewCreateOp(author, unixTime, "title", "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_edit_comment.go b/entities/bug/op_edit_comment.go index 788d16d92..d2f47db94 100644 --- a/entities/bug/op_edit_comment.go +++ b/entities/bug/op_edit_comment.go @@ -5,7 +5,6 @@ import ( "github.com/pkg/errors" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/repository" @@ -107,7 +106,7 @@ func (op *EditCommentOperation) Validate() error { return nil } -func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash) *EditCommentOperation { +func NewEditCommentOp(author entity.Identity, unixTime int64, target entity.Id, message string, files []repository.Hash) *EditCommentOperation { return &EditCommentOperation{ OpBase: dag.NewOpBase(EditCommentOp, author, unixTime), Target: target, @@ -117,7 +116,7 @@ func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.I } // EditComment is a convenience function to apply the operation -func EditComment(b Interface, author identity.Interface, unixTime int64, target entity.Id, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error) { +func EditComment(b Interface, author entity.Identity, unixTime int64, target entity.Id, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error) { op := NewEditCommentOp(author, unixTime, target, message, files) for key, val := range metadata { op.SetMetadata(key, val) @@ -130,7 +129,7 @@ func EditComment(b Interface, author identity.Interface, unixTime int64, target } // EditCreateComment is a convenience function to edit the body of a bug (the first comment) -func EditCreateComment(b Interface, author identity.Interface, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error) { +func EditCreateComment(b Interface, author entity.Identity, unixTime int64, message string, files []repository.Hash, metadata map[string]string) (entity.CombinedId, *EditCommentOperation, error) { createOp := b.FirstOp().(*CreateOperation) return EditComment(b, author, unixTime, createOp.Id(), message, files, metadata) } diff --git a/entities/bug/op_edit_comment_test.go b/entities/bug/op_edit_comment_test.go index 2ca1345e2..76a68f305 100644 --- a/entities/bug/op_edit_comment_test.go +++ b/entities/bug/op_edit_comment_test.go @@ -76,10 +76,10 @@ func TestEdit(t *testing.T) { } func TestEditCommentSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*EditCommentOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*EditCommentOperation, entity.Resolvers) { return NewEditCommentOp(author, unixTime, "target", "message", nil), nil }) - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*EditCommentOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*EditCommentOperation, entity.Resolvers) { return NewEditCommentOp(author, unixTime, "target", "message", []repository.Hash{"hash1", "hash2"}), nil }) } diff --git a/entities/bug/op_label_change.go b/entities/bug/op_label_change.go index 0d13fe9e0..816effc84 100644 --- a/entities/bug/op_label_change.go +++ b/entities/bug/op_label_change.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/util/timestamp" @@ -96,7 +95,7 @@ func (op *LabelChangeOperation) Validate() error { return nil } -func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, removed []Label) *LabelChangeOperation { +func NewLabelChangeOperation(author entity.Identity, unixTime int64, added, removed []Label) *LabelChangeOperation { return &LabelChangeOperation{ OpBase: dag.NewOpBase(LabelChangeOp, author, unixTime), Added: added, @@ -106,7 +105,7 @@ func NewLabelChangeOperation(author identity.Interface, unixTime int64, added, r type LabelChangeTimelineItem struct { combinedId entity.CombinedId - Author identity.Interface + Author entity.Identity UnixTime timestamp.Timestamp Added []Label Removed []Label @@ -120,7 +119,7 @@ func (l LabelChangeTimelineItem) CombinedId() entity.CombinedId { func (l *LabelChangeTimelineItem) IsAuthored() {} // ChangeLabels is a convenience function to change labels on a bug -func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) ([]LabelChangeResult, *LabelChangeOperation, error) { +func ChangeLabels(b Interface, author entity.Identity, unixTime int64, add, remove []string, metadata map[string]string) ([]LabelChangeResult, *LabelChangeOperation, error) { var added, removed []Label var results []LabelChangeResult @@ -186,7 +185,7 @@ func ChangeLabels(b Interface, author identity.Interface, unixTime int64, add, r // responsible for what you are doing. In the general case, you want to use ChangeLabels instead. // The intended use of this function is to allow importers to create legal but unexpected label changes, // like removing a label with no information of when it was added before. -func ForceChangeLabels(b Interface, author identity.Interface, unixTime int64, add, remove []string, metadata map[string]string) (*LabelChangeOperation, error) { +func ForceChangeLabels(b Interface, author entity.Identity, unixTime int64, add, remove []string, metadata map[string]string) (*LabelChangeOperation, error) { added := make([]Label, len(add)) for i, str := range add { added[i] = Label(str) diff --git a/entities/bug/op_label_change_test.go b/entities/bug/op_label_change_test.go index e6dc88035..c27e906d6 100644 --- a/entities/bug/op_label_change_test.go +++ b/entities/bug/op_label_change_test.go @@ -3,19 +3,18 @@ package bug import ( "testing" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestLabelChangeSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { return NewLabelChangeOperation(author, unixTime, []Label{"added"}, []Label{"removed"}), nil }) - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { return NewLabelChangeOperation(author, unixTime, []Label{"added"}, nil), nil }) - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*LabelChangeOperation, entity.Resolvers) { return NewLabelChangeOperation(author, unixTime, nil, []Label{"removed"}), nil }) } diff --git a/entities/bug/op_set_metadata.go b/entities/bug/op_set_metadata.go index b4aab78c7..9d4f01f6d 100644 --- a/entities/bug/op_set_metadata.go +++ b/entities/bug/op_set_metadata.go @@ -1,17 +1,16 @@ package bug import ( - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) -func NewSetMetadataOp(author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *dag.SetMetadataOperation[*Snapshot] { +func NewSetMetadataOp(author entity.Identity, unixTime int64, target entity.Id, newMetadata map[string]string) *dag.SetMetadataOperation[*Snapshot] { return dag.NewSetMetadataOp[*Snapshot](SetMetadataOp, author, unixTime, target, newMetadata) } // SetMetadata is a convenience function to add metadata on another operation -func SetMetadata(b Interface, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*Snapshot], error) { +func SetMetadata(b Interface, author entity.Identity, unixTime int64, target entity.Id, newMetadata map[string]string) (*dag.SetMetadataOperation[*Snapshot], error) { op := NewSetMetadataOp(author, unixTime, target, newMetadata) if err := op.Validate(); err != nil { return nil, err diff --git a/entities/bug/op_set_status.go b/entities/bug/op_set_status.go index 68199129d..0fdce8a6f 100644 --- a/entities/bug/op_set_status.go +++ b/entities/bug/op_set_status.go @@ -4,7 +4,6 @@ import ( "github.com/pkg/errors" "github.com/MichaelMure/git-bug/entities/common" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/util/timestamp" @@ -50,7 +49,7 @@ func (op *SetStatusOperation) Validate() error { return nil } -func NewSetStatusOp(author identity.Interface, unixTime int64, status common.Status) *SetStatusOperation { +func NewSetStatusOp(author entity.Identity, unixTime int64, status common.Status) *SetStatusOperation { return &SetStatusOperation{ OpBase: dag.NewOpBase(SetStatusOp, author, unixTime), Status: status, @@ -59,7 +58,7 @@ func NewSetStatusOp(author identity.Interface, unixTime int64, status common.Sta type SetStatusTimelineItem struct { combinedId entity.CombinedId - Author identity.Interface + Author entity.Identity UnixTime timestamp.Timestamp Status common.Status } @@ -72,7 +71,7 @@ func (s SetStatusTimelineItem) CombinedId() entity.CombinedId { func (s *SetStatusTimelineItem) IsAuthored() {} // Open is a convenience function to change a bugs state to Open -func Open(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) { +func Open(b Interface, author entity.Identity, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) { op := NewSetStatusOp(author, unixTime, common.OpenStatus) for key, value := range metadata { op.SetMetadata(key, value) @@ -85,7 +84,7 @@ func Open(b Interface, author identity.Interface, unixTime int64, metadata map[s } // Close is a convenience function to change a bugs state to Close -func Close(b Interface, author identity.Interface, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) { +func Close(b Interface, author entity.Identity, unixTime int64, metadata map[string]string) (*SetStatusOperation, error) { op := NewSetStatusOp(author, unixTime, common.ClosedStatus) for key, value := range metadata { op.SetMetadata(key, value) diff --git a/entities/bug/op_set_status_test.go b/entities/bug/op_set_status_test.go index 0f6d358a1..0670c7ceb 100644 --- a/entities/bug/op_set_status_test.go +++ b/entities/bug/op_set_status_test.go @@ -4,13 +4,12 @@ import ( "testing" "github.com/MichaelMure/git-bug/entities/common" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestSetStatusSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*SetStatusOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*SetStatusOperation, entity.Resolvers) { return NewSetStatusOp(author, unixTime, common.ClosedStatus), nil }) } diff --git a/entities/bug/op_set_title.go b/entities/bug/op_set_title.go index 6e445aa64..60da2eaec 100644 --- a/entities/bug/op_set_title.go +++ b/entities/bug/op_set_title.go @@ -3,7 +3,6 @@ package bug import ( "fmt" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" "github.com/MichaelMure/git-bug/util/timestamp" @@ -60,7 +59,7 @@ func (op *SetTitleOperation) Validate() error { return nil } -func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was string) *SetTitleOperation { +func NewSetTitleOp(author entity.Identity, unixTime int64, title string, was string) *SetTitleOperation { return &SetTitleOperation{ OpBase: dag.NewOpBase(SetTitleOp, author, unixTime), Title: title, @@ -70,7 +69,7 @@ func NewSetTitleOp(author identity.Interface, unixTime int64, title string, was type SetTitleTimelineItem struct { combinedId entity.CombinedId - Author identity.Interface + Author entity.Identity UnixTime timestamp.Timestamp Title string Was string @@ -84,7 +83,7 @@ func (s SetTitleTimelineItem) CombinedId() entity.CombinedId { func (s *SetTitleTimelineItem) IsAuthored() {} // SetTitle is a convenience function to change a bugs title -func SetTitle(b Interface, author identity.Interface, unixTime int64, title string, metadata map[string]string) (*SetTitleOperation, error) { +func SetTitle(b Interface, author entity.Identity, unixTime int64, title string, metadata map[string]string) (*SetTitleOperation, error) { var lastTitleOp *SetTitleOperation for _, op := range b.Operations() { switch op := op.(type) { diff --git a/entities/bug/op_set_title_test.go b/entities/bug/op_set_title_test.go index 82425ab49..4d59f4fbd 100644 --- a/entities/bug/op_set_title_test.go +++ b/entities/bug/op_set_title_test.go @@ -3,13 +3,12 @@ package bug import ( "testing" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/entity/dag" ) func TestSetTitleSerialize(t *testing.T) { - dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author identity.Interface, unixTime int64) (*SetTitleOperation, entity.Resolvers) { + dag.SerializeRoundTripTest(t, operationUnmarshaler, func(author entity.Identity, unixTime int64) (*SetTitleOperation, entity.Resolvers) { return NewSetTitleOp(author, unixTime, "title", "was"), nil }) } diff --git a/entities/bug/snapshot.go b/entities/bug/snapshot.go index 9dbc78625..b458771bc 100644 --- a/entities/bug/snapshot.go +++ b/entities/bug/snapshot.go @@ -5,7 +5,6 @@ import ( "time" "github.com/MichaelMure/git-bug/entities/common" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" ) @@ -19,9 +18,9 @@ type Snapshot struct { Title string Comments []Comment Labels []Label - Author identity.Interface - Actors []identity.Interface - Participants []identity.Interface + Author entity.Identity + Actors []entity.Identity + Participants []entity.Identity CreateTime time.Time Timeline []TimelineItem @@ -94,7 +93,7 @@ func (snap *Snapshot) SearchCommentByOpId(id entity.Id) (*Comment, error) { } // append the operation author to the actors list -func (snap *Snapshot) addActor(actor identity.Interface) { +func (snap *Snapshot) addActor(actor entity.Identity) { for _, a := range snap.Actors { if actor.Id() == a.Id() { return @@ -105,7 +104,7 @@ func (snap *Snapshot) addActor(actor identity.Interface) { } // append the operation author to the participants list -func (snap *Snapshot) addParticipant(participant identity.Interface) { +func (snap *Snapshot) addParticipant(participant entity.Identity) { for _, p := range snap.Participants { if participant.Id() == p.Id() { return diff --git a/entities/bug/timeline.go b/entities/bug/timeline.go index 84ece2621..3c425777a 100644 --- a/entities/bug/timeline.go +++ b/entities/bug/timeline.go @@ -3,7 +3,6 @@ package bug import ( "strings" - "github.com/MichaelMure/git-bug/entities/identity" "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/timestamp" @@ -18,7 +17,7 @@ type TimelineItem interface { type CommentHistoryStep struct { // The author of the edition, not necessarily the same as the author of the // original comment - Author identity.Interface + Author entity.Identity // The new message Message string UnixTime timestamp.Timestamp @@ -27,7 +26,7 @@ type CommentHistoryStep struct { // CommentTimelineItem is a TimelineItem that holds a Comment and its edition history type CommentTimelineItem struct { combinedId entity.CombinedId - Author identity.Interface + Author entity.Identity Message string Files []repository.Hash CreatedAt timestamp.Timestamp diff --git a/entities/identity/common.go b/entities/identity/common.go index 88e30e338..749def636 100644 --- a/entities/identity/common.go +++ b/entities/identity/common.go @@ -3,6 +3,8 @@ package identity import ( "encoding/json" "fmt" + + bootstrap "github.com/MichaelMure/git-bug/entity/boostrap" ) // Custom unmarshaling function to allow package user to delegate @@ -10,7 +12,7 @@ import ( // and a Bare. // // If the given message has a "id" field, it's considered being a proper Identity. -func UnmarshalJSON(raw json.RawMessage) (Interface, error) { +func UnmarshalJSON(raw json.RawMessage) (bootstrap.Identity, error) { aux := &IdentityStub{} // First try to decode and load as a normal Identity diff --git a/entities/identity/identity.go b/entities/identity/identity.go index 9effd1466..f71d0e4a8 100644 --- a/entities/identity/identity.go +++ b/entities/identity/identity.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/entity" bootstrap "github.com/MichaelMure/git-bug/entity/boostrap" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/lamport" @@ -28,7 +29,7 @@ var ErrNoIdentitySet = errors.New("No identity is set.\n" + "\"git bug user new\" or adopted with \"git bug user adopt\"") var ErrMultipleIdentitiesSet = errors.New("multiple user identities set") -var _ Interface = &Identity{} +var _ entity.Identity = &Identity{} var _ bootstrap.Entity = &Identity{} type Identity struct { @@ -40,7 +41,7 @@ func NewIdentity(repo repository.RepoClock, name string, email string) (*Identit return NewIdentityFull(repo, name, email, "", "", nil) } -func NewIdentityFull(repo repository.RepoClock, name string, email string, login string, avatarUrl string, keys []*Key) (*Identity, error) { +func NewIdentityFull(repo repository.RepoClock, name string, email string, login string, avatarUrl string, keys []bootstrap.Key) (*Identity, error) { v, err := newVersion(repo, name, email, login, avatarUrl, keys) if err != nil { return nil, err @@ -216,13 +217,13 @@ type Mutator struct { Login string Email string AvatarUrl string - Keys []*Key + Keys []bootstrap.Key } // Mutate allow to create a new version of the Identity in one go func (i *Identity) Mutate(repo repository.RepoClock, f func(orig *Mutator)) error { - copyKeys := func(keys []*Key) []*Key { - result := make([]*Key, len(keys)) + copyKeys := func(keys []bootstrap.Key) []bootstrap.Key { + result := make([]bootstrap.Key, len(keys)) for i, key := range keys { result[i] = key.Clone() } @@ -466,15 +467,15 @@ func (i *Identity) AvatarUrl() string { } // Keys return the last version of the valid keys -func (i *Identity) Keys() []*Key { +func (i *Identity) Keys() []bootstrap.Key { return i.lastVersion().keys } // SigningKey return the key that should be used to sign new messages. If no key is available, return nil. -func (i *Identity) SigningKey(repo repository.RepoKeyring) (*Key, error) { +func (i *Identity) SigningKey(repo repository.RepoKeyring) (bootstrap.Key, error) { keys := i.Keys() for _, key := range keys { - err := key.ensurePrivateKey(repo) + err := key.EnsurePrivateKey(repo) if err == errNoPrivateKey { continue } @@ -487,8 +488,8 @@ func (i *Identity) SigningKey(repo repository.RepoKeyring) (*Key, error) { } // ValidKeysAtTime return the set of keys valid at a given lamport time -func (i *Identity) ValidKeysAtTime(clockName string, time lamport.Time) []*Key { - var result []*Key +func (i *Identity) ValidKeysAtTime(clockName string, time lamport.Time) []bootstrap.Key { + var result []bootstrap.Key var lastTime lamport.Time for _, v := range i.versions { diff --git a/entities/identity/identity_stub.go b/entities/identity/identity_stub.go index 67a9db531..94208da10 100644 --- a/entities/identity/identity_stub.go +++ b/entities/identity/identity_stub.go @@ -9,7 +9,7 @@ import ( "github.com/MichaelMure/git-bug/util/timestamp" ) -var _ Interface = &IdentityStub{} +var _ bootstrap.Identity = &IdentityStub{} // IdentityStub is an almost empty Identity, holding only the id. // When a normal Identity is serialized into JSON, only the id is serialized. @@ -68,15 +68,15 @@ func (IdentityStub) AvatarUrl() string { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (IdentityStub) Keys() []*Key { +func (IdentityStub) Keys() []bootstrap.Key { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (i *IdentityStub) SigningKey(repo repository.RepoKeyring) (*Key, error) { +func (i *IdentityStub) SigningKey(repo repository.RepoKeyring) (bootstrap.Key, error) { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (IdentityStub) ValidKeysAtTime(_ string, _ lamport.Time) []*Key { +func (IdentityStub) ValidKeysAtTime(_ string, _ lamport.Time) []bootstrap.Key { panic("identities needs to be properly loaded with identity.ReadLocal()") } diff --git a/entities/identity/identity_test.go b/entities/identity/identity_test.go index e4ecfbe91..3da0c83e7 100644 --- a/entities/identity/identity_test.go +++ b/entities/identity/identity_test.go @@ -37,18 +37,18 @@ func TestIdentityCommitLoad(t *testing.T) { // multiple versions - identity, err = NewIdentityFull(repo, "René Descartes", "rene.descartes@example.com", "", "", []*Key{generatePublicKey()}) + identity, err = NewIdentityFull(repo, "René Descartes", "rene.descartes@example.com", "", "", []bootstrap.Key{generatePublicKey()}) require.NoError(t, err) idBeforeCommit = identity.Id() err = identity.Mutate(repo, func(orig *Mutator) { - orig.Keys = []*Key{generatePublicKey()} + orig.Keys = []bootstrap.Key{generatePublicKey()} }) require.NoError(t, err) err = identity.Mutate(repo, func(orig *Mutator) { - orig.Keys = []*Key{generatePublicKey()} + orig.Keys = []bootstrap.Key{generatePublicKey()} }) require.NoError(t, err) @@ -71,13 +71,13 @@ func TestIdentityCommitLoad(t *testing.T) { err = identity.Mutate(repo, func(orig *Mutator) { orig.Email = "rene@descartes.com" - orig.Keys = []*Key{generatePublicKey()} + orig.Keys = []bootstrap.Key{generatePublicKey()} }) require.NoError(t, err) err = identity.Mutate(repo, func(orig *Mutator) { orig.Email = "rene@descartes.com" - orig.Keys = []*Key{generatePublicKey(), generatePublicKey()} + orig.Keys = []bootstrap.Key{generatePublicKey(), generatePublicKey()} }) require.NoError(t, err) @@ -134,35 +134,35 @@ func TestIdentity_ValidKeysAtTime(t *testing.T) { versions: []*version{ { times: map[string]lamport.Time{"foo": 100}, - keys: []*Key{pubKeyA}, + keys: []bootstrap.Key{pubKeyA}, }, { times: map[string]lamport.Time{"foo": 200}, - keys: []*Key{pubKeyB}, + keys: []bootstrap.Key{pubKeyB}, }, { times: map[string]lamport.Time{"foo": 201}, - keys: []*Key{pubKeyC}, + keys: []bootstrap.Key{pubKeyC}, }, { times: map[string]lamport.Time{"foo": 201}, - keys: []*Key{pubKeyD}, + keys: []bootstrap.Key{pubKeyD}, }, { times: map[string]lamport.Time{"foo": 300}, - keys: []*Key{pubKeyE}, + keys: []bootstrap.Key{pubKeyE}, }, }, } require.Nil(t, identity.ValidKeysAtTime("foo", 10)) - require.Equal(t, identity.ValidKeysAtTime("foo", 100), []*Key{pubKeyA}) - require.Equal(t, identity.ValidKeysAtTime("foo", 140), []*Key{pubKeyA}) - require.Equal(t, identity.ValidKeysAtTime("foo", 200), []*Key{pubKeyB}) - require.Equal(t, identity.ValidKeysAtTime("foo", 201), []*Key{pubKeyD}) - require.Equal(t, identity.ValidKeysAtTime("foo", 202), []*Key{pubKeyD}) - require.Equal(t, identity.ValidKeysAtTime("foo", 300), []*Key{pubKeyE}) - require.Equal(t, identity.ValidKeysAtTime("foo", 3000), []*Key{pubKeyE}) + require.Equal(t, identity.ValidKeysAtTime("foo", 100), []bootstrap.Key{pubKeyA}) + require.Equal(t, identity.ValidKeysAtTime("foo", 140), []bootstrap.Key{pubKeyA}) + require.Equal(t, identity.ValidKeysAtTime("foo", 200), []bootstrap.Key{pubKeyB}) + require.Equal(t, identity.ValidKeysAtTime("foo", 201), []bootstrap.Key{pubKeyD}) + require.Equal(t, identity.ValidKeysAtTime("foo", 202), []bootstrap.Key{pubKeyD}) + require.Equal(t, identity.ValidKeysAtTime("foo", 300), []bootstrap.Key{pubKeyE}) + require.Equal(t, identity.ValidKeysAtTime("foo", 3000), []bootstrap.Key{pubKeyE}) } // Test the immutable or mutable metadata search @@ -235,7 +235,7 @@ func TestJSON(t *testing.T) { require.NoError(t, err) // deserialize, got a IdentityStub with the same id - var i Interface + var i bootstrap.Identity i, err = UnmarshalJSON(data) require.NoError(t, err) require.Equal(t, identity.Id(), i.Id()) diff --git a/entities/identity/interface.go b/entities/identity/interface.go deleted file mode 100644 index 88234341b..000000000 --- a/entities/identity/interface.go +++ /dev/null @@ -1,62 +0,0 @@ -package identity - -import ( - bootstrap "github.com/MichaelMure/git-bug/entity/boostrap" - "github.com/MichaelMure/git-bug/repository" - "github.com/MichaelMure/git-bug/util/lamport" - "github.com/MichaelMure/git-bug/util/timestamp" -) - -type Interface interface { - bootstrap.Entity - - // Name return the last version of the name - // Can be empty. - Name() string - - // DisplayName return a non-empty string to display, representing the - // identity, based on the non-empty values. - DisplayName() string - - // Email return the last version of the email - // Can be empty. - Email() string - - // Login return the last version of the login - // Can be empty. - // Warning: this login can be defined when importing from a bridge but should *not* be - // used to identify an identity as multiple bridge with different login can map to the same - // identity. Use the metadata system for that usage instead. - Login() string - - // AvatarUrl return the last version of the Avatar URL - // Can be empty. - AvatarUrl() string - - // Keys return the last version of the valid keys - // Can be empty. - Keys() []*Key - - // SigningKey return the key that should be used to sign new messages. If no key is available, return nil. - SigningKey(repo repository.RepoKeyring) (*Key, error) - - // ValidKeysAtTime return the set of keys valid at a given lamport time for a given clock of another entity - // Can be empty. - ValidKeysAtTime(clockName string, time lamport.Time) []*Key - - // LastModification return the timestamp at which the last version of the identity became valid. - LastModification() timestamp.Timestamp - - // LastModificationLamports return the lamport times at which the last version of the identity became valid. - LastModificationLamports() map[string]lamport.Time - - // IsProtected return true if the chain of git commits started to be signed. - // If that's the case, only signed commit with a valid key for this identity can be added. - IsProtected() bool - - // Validate check if the Identity data is valid - Validate() error - - // NeedCommit indicate that the in-memory state changed and need to be committed in the repository - NeedCommit() bool -} diff --git a/entities/identity/key.go b/entities/identity/key.go index 87271dd56..b9bcc8c3a 100644 --- a/entities/identity/key.go +++ b/entities/identity/key.go @@ -13,6 +13,7 @@ import ( "github.com/ProtonMail/go-crypto/openpgp/packet" "github.com/pkg/errors" + bootstrap "github.com/MichaelMure/git-bug/entity/boostrap" "github.com/MichaelMure/git-bug/repository" ) @@ -75,7 +76,7 @@ func (k *Key) Validate() error { return nil } -func (k *Key) Clone() *Key { +func (k *Key) Clone() bootstrap.Key { clone := &Key{} pub := *k.public @@ -185,9 +186,9 @@ func (k *Key) loadPrivate(repo repository.RepoKeyring) error { return nil } -// ensurePrivateKey attempt to load the corresponding private key if it is not loaded already. +// EnsurePrivateKey attempt to load the corresponding private key if it is not loaded already. // If no private key is found, returns errNoPrivateKey -func (k *Key) ensurePrivateKey(repo repository.RepoKeyring) error { +func (k *Key) EnsurePrivateKey(repo repository.RepoKeyring) error { if k.private != nil { return nil } diff --git a/entities/identity/key_test.go b/entities/identity/key_test.go index 6e320dc20..88301a1e9 100644 --- a/entities/identity/key_test.go +++ b/entities/identity/key_test.go @@ -43,7 +43,7 @@ func TestStoreLoad(t *testing.T) { err = json.Unmarshal(dataJSON, &read) require.NoError(t, err) - err = read.ensurePrivateKey(repo) + err = read.EnsurePrivateKey(repo) require.NoError(t, err) require.Equal(t, k.public, read.public) diff --git a/entities/identity/version.go b/entities/identity/version.go index 2e30ead73..3f0a22d92 100644 --- a/entities/identity/version.go +++ b/entities/identity/version.go @@ -33,7 +33,7 @@ type version struct { // The set of keys valid at that time, from this version onward, until they get removed // in a new version. This allows to have multiple key for the same identity (e.g. one per // device) as well as revoke key. - keys []*Key + keys []bootstrap.Key // mandatory random bytes to ensure a better randomness of the data of the first // version of an identity, used to later generate the ID @@ -51,7 +51,7 @@ type version struct { commitHash repository.Hash } -func newVersion(repo repository.RepoClock, name string, email string, login string, avatarURL string, keys []*Key) (*version, error) { +func newVersion(repo repository.RepoClock, name string, email string, login string, avatarURL string, keys []bootstrap.Key) (*version, error) { clocks, err := repo.AllClocks() if err != nil { return nil, err @@ -123,7 +123,7 @@ func (v *version) Clone() *version { clone.times[name] = t } - clone.keys = make([]*Key, len(v.keys)) + clone.keys = make([]bootstrap.Key, len(v.keys)) for i, key := range v.keys { clone.keys[i] = key.Clone() } diff --git a/entities/identity/version_test.go b/entities/identity/version_test.go index 2ad43f3d4..3b45ba21f 100644 --- a/entities/identity/version_test.go +++ b/entities/identity/version_test.go @@ -32,7 +32,7 @@ func makeIdentityTestRepo(t *testing.T) repository.ClockedRepo { func TestVersionJSON(t *testing.T) { repo := makeIdentityTestRepo(t) - keys := []*Key{ + keys := []bootstrap.Key{ generatePublicKey(), generatePublicKey(), } |