Exemple #1
0
// loadConfig loads the on disk configuration or use the default configuration
// if none is found. See CONFIGURATION.md for the logic.
func loadConfig(repo scm.ReadOnlyRepo, path string) (string, *checks.Config) {
	if filepath.IsAbs(path) {
		if config := loadConfigFile(path); config != nil {
			return path, config
		}
	} else {
		// <repo root>/.git/<path>
		if scmDir, err := repo.ScmDir(); err == nil {
			file := filepath.Join(scmDir, path)
			if config := loadConfigFile(file); config != nil {
				return file, config
			}
		}

		// <repo root>/<path>
		file := filepath.Join(repo.Root(), path)
		if config := loadConfigFile(file); config != nil {
			return file, config
		}

		if user, err := user.Current(); err == nil && user.HomeDir != "" {
			if runtime.GOOS == "windows" {
				// ~/<path>
				file = filepath.Join(user.HomeDir, path)
			} else {
				// ~/.config/<path>
				file = filepath.Join(user.HomeDir, ".config", path)
			}
			if config := loadConfigFile(file); config != nil {
				return file, config
			}
		}
	}
	return "<N/A>", checks.New(version)
}