Exemple #1
0
// EachLoop is called at the start of every munge loop
func (a *Aliases) EachLoop() error {
	if !a.IsEnabled {
		return nil
	}

	// read and check the alias-file.
	fileContents, err := a.aliasReader.read()
	if os.IsNotExist(err) {
		glog.Infof("Missing alias-file (%s), using empty alias structure.", a.AliasFile)
		a.data = &aliasData{
			AliasMap: map[string][]string{},
		}
		a.prevHash = ""
		return nil
	}
	if err != nil {
		return fmt.Errorf("Unable to read alias file: %v", err)
	}

	hash := mungerutil.GetHash(fileContents)
	if a.prevHash != hash {
		var data aliasData
		if err := yaml.Unmarshal(fileContents, &data); err != nil {
			return fmt.Errorf("Failed to decode the alias file: %v", err)
		}
		a.data = &data
		a.prevHash = hash
	}
	return nil
}
Exemple #2
0
// EachLoop is called at the start of every munge loop
func (a *Aliases) EachLoop() error {
	if !a.IsEnabled {
		return nil
	}

	// read and check the alias-file.
	fileContents, err := a.aliasReader.read()
	if err != nil {
		return fmt.Errorf("Unable to read alias file: %v", err)
	}

	hash := mungerutil.GetHash(fileContents)
	if a.prevHash != hash {
		var data aliasData
		if err := yaml.Unmarshal(fileContents, &data); err != nil {
			return fmt.Errorf("Failed to decode the alias file: %v", err)
		}
		a.data = &data
		a.prevHash = hash
	}
	return nil
}
// EachLoop is called at the start of every munge loop
func (c *CheckLabelsMunger) EachLoop() error {
	fileContents, err := c.readFunc()
	if err != nil {
		glog.Errorf("Failed to read the check label config: %v", err)
		return err
	}
	hash := mungerutil.GetHash(fileContents)
	if c.prevHash != hash {
		// Get all labels from file.
		fileLabels := map[string][]*github.Label{}
		if err := yaml.NewYAMLToJSONDecoder(bytes.NewReader(fileContents)).Decode(&fileLabels); err != nil {
			return fmt.Errorf("Failed to decode the check label config: %v", err)
		}

		// Get all labels from repository.
		repoLabels, err := c.labelAccessor.GetLabels()
		if err != nil {
			return err
		}
		c.addMissingLabels(repoLabels, fileLabels["labels"])
		c.prevHash = hash
	}
	return nil
}