LoadConfig returns the system configuration from the host environment.
()
| 61 | // LoadConfig returns the system configuration from the |
| 62 | // host environment. |
| 63 | func LoadConfig() (*types.Config, error) { |
| 64 | config := new(types.Config) |
| 65 | err := envconfig.Process("", config) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | config.InstanceID, err = getSanitizedMachineName() |
| 71 | if err != nil { |
| 72 | return nil, fmt.Errorf("unable to ensure that instance ID is set in config: %w", err) |
| 73 | } |
| 74 | |
| 75 | err = backfillURLs(config) |
| 76 | if err != nil { |
| 77 | return nil, fmt.Errorf("failed to backfil urls: %w", err) |
| 78 | } |
| 79 | |
| 80 | if config.Git.HookPath == "" { |
| 81 | executablePath, err := os.Executable() |
| 82 | if err != nil { |
| 83 | return nil, fmt.Errorf("failed to get path of current executable: %w", err) |
| 84 | } |
| 85 | |
| 86 | config.Git.HookPath = executablePath |
| 87 | } |
| 88 | |
| 89 | if config.Git.Root == "" { |
| 90 | homedir, err := os.UserHomeDir() |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | |
| 95 | newPath := filepath.Join(homedir, gitnessHomeDir) |
| 96 | config.Git.Root = newPath |
| 97 | |
| 98 | oldPath := filepath.Join(homedir, ".gitrpc") |
| 99 | if _, err := os.Stat(oldPath); err == nil { |
| 100 | if err := os.Rename(oldPath, newPath); err != nil { |
| 101 | config.Git.Root = oldPath |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return config, nil |
| 107 | } |
| 108 | |
| 109 | //nolint:gocognit // refactor if required |
| 110 | func backfillURLs(config *types.Config) error { |
no test coverage detected
searching dependent graphs…