(repo *cache.RepoCache, metaKey string, login string)
| 9 | ) |
| 10 | |
| 11 | func FinishConfig(repo *cache.RepoCache, metaKey string, login string) error { |
| 12 | // if no user exist with the given login metadata |
| 13 | _, err := repo.Identities().ResolveIdentityImmutableMetadata(metaKey, login) |
| 14 | if err != nil && !entity.IsErrNotFound(err) { |
| 15 | // real error |
| 16 | return err |
| 17 | } |
| 18 | if err == nil { |
| 19 | // found an already valid user, all good |
| 20 | return nil |
| 21 | } |
| 22 | |
| 23 | // if a default user exist, tag it with the login |
| 24 | user, err := repo.GetUserIdentity() |
| 25 | if err != nil && err != identity.ErrNoIdentitySet { |
| 26 | // real error |
| 27 | return err |
| 28 | } |
| 29 | if err == nil { |
| 30 | fmt.Printf("Current identity %v tagged with login %v\n", user.Id().Human(), login) |
| 31 | // found one |
| 32 | user.SetMetadata(metaKey, login) |
| 33 | return user.CommitAsNeeded() |
| 34 | } |
| 35 | |
| 36 | // otherwise create a user with that metadata |
| 37 | i, err := repo.Identities().NewFromGitUserRaw(map[string]string{ |
| 38 | metaKey: login, |
| 39 | }) |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | |
| 44 | err = repo.SetUserIdentity(i) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | |
| 49 | fmt.Printf("Identity %v created, set as current\n", i.Id().Human()) |
| 50 | |
| 51 | return nil |
| 52 | } |
no test coverage detected