From ae2f942ef907161af0aba5f3511db72cf9801dca Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 12 Jan 2020 16:38:16 +0100 Subject: more wip --- bridge/core/config.go | 1 + 1 file changed, 1 insertion(+) create mode 100644 bridge/core/config.go (limited to 'bridge/core/config.go') diff --git a/bridge/core/config.go b/bridge/core/config.go new file mode 100644 index 00000000..9a8bc959 --- /dev/null +++ b/bridge/core/config.go @@ -0,0 +1 @@ +package core -- cgit From 74e91144105790cc997c1d79a7f638e1e3a1f3f8 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 24 Jan 2020 00:30:13 +0100 Subject: more more wip --- bridge/core/config.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'bridge/core/config.go') diff --git a/bridge/core/config.go b/bridge/core/config.go index 9a8bc959..adee5f08 100644 --- a/bridge/core/config.go +++ b/bridge/core/config.go @@ -1 +1,43 @@ package core + +import ( + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/identity" +) + +func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error { + // if no user exist with the given login metadata + _, err := repo.ResolveIdentityImmutableMetadata(metaKey, login) + if err != nil && err != identity.ErrIdentityNotExist { + // real error + return err + } + if err == nil { + // found an already valid user, all good + return nil + } + + // if a default user exist, tag it with the login + user, err := repo.GetUserIdentity() + if err != nil && err != identity.ErrIdentityNotExist { + // real error + return err + } + if err == nil { + // found one + user.SetMetadata(metaKey, login) + return user.CommitAsNeeded() + } + + // otherwise create a user with that metadata + i, err := repo.NewIdentityFromGitUserRaw(map[string]string{ + metaKey: login, + }) + + err = repo.SetUserIdentity(i) + if err != nil { + return err + } + + return nil +} -- cgit From a335725cc5f712f3f3089154afa96881284d4853 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 8 Feb 2020 22:04:51 +0100 Subject: bridge: fix wrong error used --- bridge/core/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bridge/core/config.go') diff --git a/bridge/core/config.go b/bridge/core/config.go index adee5f08..8d306ef6 100644 --- a/bridge/core/config.go +++ b/bridge/core/config.go @@ -19,7 +19,7 @@ func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error { // if a default user exist, tag it with the login user, err := repo.GetUserIdentity() - if err != nil && err != identity.ErrIdentityNotExist { + if err != nil && err != identity.ErrNoIdentitySet { // real error return err } -- cgit From 9b1aaa032d36e1ac05504916e359f767d1622d9d Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 8 Feb 2020 22:08:35 +0100 Subject: bridge: fix 2 uncatched errors --- bridge/core/config.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bridge/core/config.go') diff --git a/bridge/core/config.go b/bridge/core/config.go index 8d306ef6..afcda560 100644 --- a/bridge/core/config.go +++ b/bridge/core/config.go @@ -33,6 +33,9 @@ func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error { i, err := repo.NewIdentityFromGitUserRaw(map[string]string{ metaKey: login, }) + if err != nil { + return err + } err = repo.SetUserIdentity(i) if err != nil { -- cgit