Ejemplo n.º 1
0
// InitializeMungers will call munger.Initialize() for the requested mungers.
func InitializeMungers(config *github.Config, features *features.Features) error {
	for _, munger := range mungers {
		if err := munger.Initialize(config, features); err != nil {
			return err
		}
		glog.Infof(mungerutil.PrettyString(munger))
		glog.Infof("Initialized munger: %s", munger.Name())
	}
	return nil
}
Ejemplo n.º 2
0
func main() {
	config := &mungeConfig{}
	root := &cobra.Command{
		Use:   filepath.Base(os.Args[0]),
		Short: "A program to add labels, check tests, and generally mess with outstanding PRs",
		RunE: func(_ *cobra.Command, _ []string) error {
			glog.Info(mungerutil.PrettyString(config))
			if err := config.PreExecute(); err != nil {
				return err
			}
			if len(config.IssueReportsList) > 0 {
				return reports.RunReports(&config.Config, config.IssueReportsList...)
			}
			if len(config.PRMungersList) == 0 {
				glog.Fatalf("must include at least one --pr-mungers")
			}
			if err := mungers.RegisterMungers(config.PRMungersList); err != nil {
				glog.Fatalf("unable to find requested mungers: %v", err)
			}
			requestedFeatures := mungers.RequestedFeatures()
			if err := config.Features.Initialize(&config.Config, requestedFeatures); err != nil {
				return err
			}
			if err := mungers.InitializeMungers(&config.Config, &config.Features); err != nil {
				glog.Fatalf("unable to initialize mungers: %v", err)
			}
			return doMungers(config)
		},
	}
	root.SetGlobalNormalizationFunc(utilflag.WordSepNormalizeFunc)
	config.AddRootFlags(root)
	addMungeFlags(config, root)
	config.Features.AddFlags(root)

	allMungers := mungers.GetAllMungers()
	for _, m := range allMungers {
		m.AddFlags(root, &config.Config)
	}

	allReports := reports.GetAllReports()
	for _, r := range allReports {
		r.AddFlags(root, &config.Config)
	}

	if err := root.Execute(); err != nil {
		glog.Fatalf("%v\n", err)
	}
}