// Creates a project ref local config that can be used for testing, with the string identifier given
// and the local config from a path
func CreateTestLocalConfig(testSettings *evergreen.Settings, projectName, projectPath string) error {

	if projectPath == "" {
		config, err := evergreen.FindConfig(testSettings.ConfigDir)
		if err != nil {
			return err
		}
		projectPath = filepath.Join(config, "project", fmt.Sprintf("%v.yml", projectName))
	}

	projectRef, err := model.FindOneProjectRef(projectName)
	if err != nil {
		return err
	}

	if projectRef == nil {
		projectRef = &model.ProjectRef{}
	}

	data, err := ioutil.ReadFile(projectPath)
	if err != nil {
		return err
	}

	err = yaml.Unmarshal(data, projectRef)
	if err != nil {
		return err
	}

	projectRef.LocalConfig = string(data)

	return projectRef.Upsert()
}
Example #2
0
// This function is responsible for reading the notifications file
func ParseNotifications(configName string) (*MCINotification, error) {
	evergreen.Logger.Logf(slogger.INFO, "Parsing notifications...")
	configRoot, err := evergreen.FindConfig(configName)
	if err != nil {
		return nil, err
	}

	notificationsFile := filepath.Join(configRoot, evergreen.NotificationsFile)
	data, err := ioutil.ReadFile(notificationsFile)
	if err != nil {
		return nil, err
	}

	// unmarshal file contents into MCINotification struct
	mciNotification := &MCINotification{}

	err = yaml.Unmarshal(data, mciNotification)
	if err != nil {
		return nil, fmt.Errorf("Parse error unmarshalling notifications %v: %v", notificationsFile, err)
	}
	return mciNotification, nil
}