Exemplo n.º 1
0
func LoadConfig() (Config, error) {
	// Try the cache first.
	if configCache != nil {
		return configCache, nil
	}

	// Unmarshal.
	var global GlobalConfig
	if err := config.UnmarshalGlobalConfig(&global); err != nil {
		return nil, err
	}
	if err := global.validate(); err != nil {
		return nil, err
	}

	var local LocalConfig
	if err := config.UnmarshalLocalConfig(&local); err != nil {
		return nil, err
	}
	if local.GitHub.ReviewLabel == "" {
		local.GitHub.ReviewLabel = DefaultReviewIssueLabel
	}

	// Save the new instance into the cache and return.
	configCache = &configProxy{
		apiToken:         global.GitHub.Token,
		reviewIssueLabel: local.GitHub.ReviewLabel,
	}
	return configCache, nil
}
Exemplo n.º 2
0
func LoadConfig() (Config, error) {
	// Try the cache first.
	if configCache != nil {
		return configCache, nil
	}

	// Load the local config.
	var local LocalConfig
	if err := config.UnmarshalLocalConfig(&local); err != nil {
		return nil, err
	}

	labels := &local.PT.Labels
	if labels.PointMeLabel == "" {
		labels.PointMeLabel = DefaultPointMeLabel
	}
	if labels.ImplementedLabel == "" {
		labels.ImplementedLabel = DefaultImplementedLabel
	}
	if labels.NoReviewLabel == "" {
		labels.NoReviewLabel = DefaultNoReviewLabel
	}
	if labels.ReviewedLabel == "" {
		labels.ReviewedLabel = DefaultReviewedLabel
	}
	labels.SkipCheckLabels = append(labels.SkipCheckLabels, DefaultSkipCheckLabels...)

	if err := local.validate(); err != nil {
		return nil, err
	}

	// Load the global config.
	var global GlobalConfig
	if err := config.UnmarshalGlobalConfig(&global); err != nil {
		return nil, err
	}
	if err := global.validate(); err != nil {
		return nil, err
	}

	// Load git config.
	storyFilter, err := git.GetConfigString("salsaflow.pivotaltracker.include-stories")
	if err != nil {
		return nil, err
	}

	var storyFilterRe *regexp.Regexp
	if storyFilter != "" {
		var err error
		storyFilterRe, err = regexp.Compile(storyFilter)
		if err != nil {
			return nil, err
		}
	}

	configCache = &configProxy{&local, &global, storyFilterRe}
	return configCache, nil
}
Exemplo n.º 3
0
func LoadConfig() (Config, error) {
	if cache == nil {
		var lc LocalConfig
		if err := config.UnmarshalLocalConfig(&lc); err != nil {
			return nil, err
		}
		if lc.EnabledTimestamp.IsZero() {
			// The enabled timestamp must be set no matter what.
			printSalsaFlowEnabledTimestampWarning()
			return nil, errors.New("SalsaFlow enabled timestamp not set")
		}
		cache = &lc
	}
	return cache, nil
}
Exemplo n.º 4
0
// LoadConfig returns the config that is useful for modules in general.
//
// Even when an error is returned, Config can be partially filled in
// in case the error being returned is a validation error.
func LoadConfig() (Config, error) {
	// Parse the config files if necessary.
	var err error
	if configCache == nil {
		task := "Load modules-related SalsaFlow config"
		proxy := &configProxy{&LocalConfig{}}
		if err := config.UnmarshalLocalConfig(proxy.local); err != nil {
			return nil, errs.NewError(task, err)
		}
		configCache = proxy
		err = proxy.local.validate()
	}

	// Return the config as saved in the cache.
	return configCache, err
}
Exemplo n.º 5
0
func LoadConfig() (Config, error) {
	// Try the cache first.
	if configCache != nil {
		return configCache, nil
	}

	// Load the local config.
	var local LocalConfig
	if err := config.UnmarshalLocalConfig(&local); err != nil {
		return nil, err
	}

	tags := &local.Sprintly.Tags
	if tags.NoReviewTag == "" {
		tags.NoReviewTag = DefaultNoReviewTag
	}
	if tags.ReviewedTag == "" {
		tags.ReviewedTag = DefaultReviewedTag
	}

	envs := &local.Sprintly.Environments
	if envs.Staging == "" {
		envs.Staging = DefaultStagingEnvironment
	}
	if envs.Production == "" {
		envs.Production = DefaultProductionEnvironment
	}

	if err := local.validate(); err != nil {
		return nil, err
	}

	// Load the global config.
	var global GlobalConfig
	if err := config.UnmarshalGlobalConfig(&global); err != nil {
		return nil, err
	}
	if err := global.validate(); err != nil {
		return nil, err
	}

	configCache = &configProxy{&local, &global}
	return configCache, nil
}