Exemple #1
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
}
Exemple #2
0
// Initialize will initialize the munger
func (b *BlunderbussMunger) Initialize(config *github.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
}