diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-09 01:31:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-09 01:31:00 +0100 |
commit | 9e1a987b4d94dc5c2115423ede5954d4faf1d342 (patch) | |
tree | e30bb28d55444a7d1e66c8fa8b8ba7d413805473 /bridge/core/config.go | |
parent | 97bc5ccd229b7b438262a84e3c42783b4d4a82af (diff) | |
parent | 9b1aaa032d36e1ac05504916e359f767d1622d9d (diff) | |
download | git-bug-9e1a987b4d94dc5c2115423ede5954d4faf1d342.tar.gz |
Merge pull request #294 from MichaelMure/cred-metadata
Cred metadata
Diffstat (limited to 'bridge/core/config.go')
-rw-r--r-- | bridge/core/config.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bridge/core/config.go b/bridge/core/config.go new file mode 100644 index 00000000..afcda560 --- /dev/null +++ b/bridge/core/config.go @@ -0,0 +1,46 @@ +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.ErrNoIdentitySet { + // 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, + }) + if err != nil { + return err + } + + err = repo.SetUserIdentity(i) + if err != nil { + return err + } + + return nil +} |