blob: 8d306ef679045079c2786fe9407e49001ce931dc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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.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,
})
err = repo.SetUserIdentity(i)
if err != nil {
return err
}
return nil
}
|