Beispiel #1
0
// Initialize will initialize the munger
func (b *BlockPath) Initialize(config *github.Config, features *features.Features) error {
	if len(b.Path) == 0 {
		glog.Fatalf("--block-path-config is required with the block-path munger")
	}
	file, err := os.Open(b.Path)
	if err != nil {
		glog.Fatalf("Failed to load block-path config: %v", err)
	}
	defer file.Close()

	c := &configBlockPath{}
	if err := yaml.NewYAMLToJSONDecoder(file).Decode(c); err != nil {
		glog.Fatalf("Failed to decode the block-path config: %v", err)
	}

	b.blockRegexp = []regexp.Regexp{}
	for _, str := range c.BlockRegexp {
		reg, err := regexp.Compile(str)
		if err != nil {
			return err
		}
		b.blockRegexp = append(b.blockRegexp, *reg)
	}

	b.doNotBlockRegexp = []regexp.Regexp{}
	for _, str := range c.DoNotBlockRegexp {
		reg, err := regexp.Compile(str)
		if err != nil {
			return err
		}
		b.doNotBlockRegexp = append(b.doNotBlockRegexp, *reg)
	}
	return nil
}
Beispiel #2
0
func (o *RepoInfo) walkFunc(path string, info os.FileInfo, err error) error {
	if err != nil {
		glog.Errorf("%v", err)
		return nil
	}
	filename := filepath.Base(path)
	if info.Mode().IsDir() {
		switch filename {
		case ".git":
			return filepath.SkipDir
		case "_output":
			return filepath.SkipDir
		}
	}
	if !info.Mode().IsRegular() {
		return nil
	}
	if filename != ownerFilename {
		return nil
	}

	file, err := os.Open(path)
	if err != nil {
		glog.Errorf("%v", err)
		return nil
	}
	defer file.Close()

	c := &assignmentConfig{}
	if err := yaml.NewYAMLToJSONDecoder(file).Decode(c); err != nil {
		glog.Errorf("%v", err)
		return nil
	}

	path, err = filepath.Rel(o.kubernetesDir, path)
	if err != nil {
		glog.Errorf("Unable to find relative path between %q and %q: %v", o.kubernetesDir, path, err)
		return err
	}
	path = filepath.Dir(path)
	if len(c.Assignees) > 0 {
		o.assignees[path] = sets.NewString(c.Assignees...)
	}
	//if len(c.Owners) > 0 {
	//o.owners[path] = sets.NewString(c.Owners...)
	//}
	return nil
}
Beispiel #3
0
func (b *BlunderbussMunger) loadConfig() {
	if len(*blunderbussConfig) == 0 {
		glog.Fatalf("--blunderbuss-config is required with the blunderbuss munger")
	}
	file, err := os.Open(*blunderbussConfig)
	if err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	defer file.Close()

	b.config = &BlunderbussConfig{}
	if err := yaml.NewYAMLToJSONDecoder(file).Decode(b.config); err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	glog.V(4).Infof("Loaded config from %s", *blunderbussConfig)
}
Beispiel #4
0
func (b *BlunderbussMunger) doNormalizeBlunderbuss() error {
	file, err := os.Open(b.blunderbussConfigFile)
	if err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	defer file.Close()

	b.config = &BlunderbussConfig{}
	if err := yaml.NewYAMLToJSONDecoder(file).Decode(b.config); err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	glog.V(4).Infof("Loaded config from %s", b.blunderbussConfigFile)

	out := new(bytes.Buffer)

	var paths []string
	for k := range b.config.PrefixMap {
		paths = append(paths, k)
	}
	sort.Strings(paths)

	for i, p := range paths {
		if i != 0 {
			out.WriteString("\n")
		} else {
			out.WriteString("prefixMap:\n")
		}
		out.WriteString(fmt.Sprintf("  %s:\n", p))
		var names []string
		for _, n := range b.config.PrefixMap[p] {
			names = append(names, n)
		}
		sort.Strings(names)
		for _, n := range names {
			out.WriteString(fmt.Sprintf("    - %s\n", n))
		}
	}

	f, err := os.Create(b.blunderbussConfigFile)
	if err != nil {
		glog.Fatalf("unable to open file for write: %v", err)
	}
	defer f.Close()

	f.Write(out.Bytes())
	return nil
}
Beispiel #5
0
// Initialize will initialize the munger
func (b *BlunderbussMunger) Initialize(config *github_util.Config) error {
	if len(b.blunderbussConfigFile) == 0 {
		glog.Fatalf("--blunderbuss-config is required with the blunderbuss munger")
	}
	file, err := os.Open(b.blunderbussConfigFile)
	if err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	defer file.Close()

	b.config = &BlunderbussConfig{}
	if err := yaml.NewYAMLToJSONDecoder(file).Decode(b.config); err != nil {
		glog.Fatalf("Failed to load blunderbuss config: %v", err)
	}
	glog.V(4).Infof("Loaded config from %s", b.blunderbussConfigFile)
	return nil
}
Beispiel #6
0
// 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
}
Beispiel #7
0
func (o *RepoInfo) walkFunc(path string, info os.FileInfo, err error) error {
	if err != nil {
		glog.Errorf("%v", err)
		return nil
	}
	filename := filepath.Base(path)
	if info.Mode().IsDir() {
		switch filename {
		case ".git":
			return filepath.SkipDir
		case "_output":
			return filepath.SkipDir
		}
	}
	if !info.Mode().IsRegular() {
		return nil
	}

	c := &assignmentConfig{}

	// '.md' files may contain assignees at the top of the file in a yaml header
	// Flag guarded because this is only enabled in some repos
	if o.EnableMdYaml && filename != ownerFilename && strings.HasSuffix(filename, "md") {
		// Parse the yaml header from the file if it exists and marshal into the config
		if err := decodeAssignmentConfig(path, c); err != nil {
			glog.Errorf("%v", err)
			return err
		}

		// Set assignees for this file using the relative path if they were found
		path, err = filepath.Rel(o.projectDir, path)
		if err != nil {
			glog.Errorf("Unable to find relative path between %q and %q: %v", o.projectDir, path, err)
			return err
		}
		if len(c.Assignees) > 0 {
			o.assignees[path] = sets.NewString(c.Assignees...)
		}
		return nil
	}

	if filename != ownerFilename {
		return nil
	}

	file, err := os.Open(path)
	if err != nil {
		glog.Errorf("%v", err)
		return nil
	}
	defer file.Close()

	if err := yaml.NewYAMLToJSONDecoder(file).Decode(c); err != nil {
		glog.Errorf("%v", err)
		return nil
	}

	path, err = filepath.Rel(o.projectDir, path)
	if err != nil {
		glog.Errorf("Unable to find relative path between %q and %q: %v", o.projectDir, path, err)
		return err
	}
	path = filepath.Dir(path)
	// Make the root explicitly / so its easy to distinguish. Nothing else is `/` anchored
	if path == "." {
		path = "/"
	}
	if len(c.Assignees) > 0 {
		o.assignees[path] = sets.NewString(c.Assignees...)
	}
	//if len(c.Owners) > 0 {
	//o.owners[path] = sets.NewString(c.Owners...)
	//}
	return nil
}