diff options
author | Michael Muré <batolettre@gmail.com> | 2019-08-12 16:12:14 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-08-12 16:12:14 +0200 |
commit | 99b5c58d43137bd9f6503788a55484327b0c531f (patch) | |
tree | 08ecc0f923b5f1fb4e8a7627aeabccb335d92ad1 /identity | |
parent | 67a3752e176790e82a48706236f889cab4f8913d (diff) | |
download | git-bug-99b5c58d43137bd9f6503788a55484327b0c531f.tar.gz |
finish the refactoring for the dedicated identifier type
Diffstat (limited to 'identity')
-rw-r--r-- | identity/bare.go | 3 | ||||
-rw-r--r-- | identity/common.go | 11 | ||||
-rw-r--r-- | identity/identity_actions.go | 9 |
3 files changed, 12 insertions, 11 deletions
diff --git a/identity/bare.go b/identity/bare.go index 93cea91f..a243f074 100644 --- a/identity/bare.go +++ b/identity/bare.go @@ -50,13 +50,12 @@ type bareIdentityJSON struct { } func (i *Bare) MarshalJSON() ([]byte, error) { - data, err := json.Marshal(bareIdentityJSON{ + return json.Marshal(bareIdentityJSON{ Name: i.name, Email: i.email, Login: i.login, AvatarUrl: i.avatarUrl, }) - return data, err } func (i *Bare) UnmarshalJSON(data []byte) error { diff --git a/identity/common.go b/identity/common.go index 68a6d57c..007e10d6 100644 --- a/identity/common.go +++ b/identity/common.go @@ -4,17 +4,14 @@ import ( "encoding/json" "errors" "fmt" - "strings" + + "github.com/MichaelMure/git-bug/entity" ) var ErrIdentityNotExist = errors.New("identity doesn't exist") -type ErrMultipleMatch struct { - Matching []string -} - -func (e ErrMultipleMatch) Error() string { - return fmt.Sprintf("Multiple matching identities found:\n%s", strings.Join(e.Matching, "\n")) +func NewErrMultipleMatch(matching []entity.Id) *entity.ErrMultipleMatch { + return entity.NewErrMultipleMatch("identity", matching) } // Custom unmarshaling function to allow package user to delegate diff --git a/identity/identity_actions.go b/identity/identity_actions.go index 40aab8e2..aa6a2a91 100644 --- a/identity/identity_actions.go +++ b/identity/identity_actions.go @@ -59,8 +59,13 @@ func MergeAll(repo repository.ClockedRepo, remote string) <-chan entity.MergeRes } for _, remoteRef := range remoteRefs { - refSplitted := strings.Split(remoteRef, "/") - id := refSplitted[len(refSplitted)-1] + refSplit := strings.Split(remoteRef, "/") + id := entity.Id(refSplit[len(refSplit)-1]) + + if err := id.Validate(); err != nil { + out <- entity.NewMergeInvalidStatus(id, errors.Wrap(err, "invalid ref").Error()) + continue + } remoteIdentity, err := read(repo, remoteRef) |