// Checks the configuration on the filesystem for syntax errors or
// non-exsistance.
func (*StepCheckConfigurationFile) Run(state multistep.StateBag) multistep.StepAction {
	log.Println("Checking configuration file...")
	configPath := state.Get("config_path").(string)
	var path string

	// Determine if we are dealing with a custom config path
	if configPath == "" {
		// Default to the home directory
		path = os.Getenv("HOME") + "/.gethubconfig"
	} else {
		// They've specified a custom config path
		log.Println("Environment specified config path", configPath)
		path = configPath + "/.gethubconfig"
	}

	// Is the config file even there?
	_, err := os.Stat(path)

	if err != nil {
		fmt.Println(RED + "It seems as though you haven't set-up gethub. Please run `gethub authorize`" + CLEAR)
		return multistep.ActionHalt
	}

	// Read the file and see if all is well with a basic config
	c, err2 := config.ReadDefault(path)
	checkPath, _ := c.String("gethub", "path")

	if checkPath == "" || err2 != nil {
		fmt.Println(RED + "Something seems to be wrong with your ~/.gethubconfig file. Please run `gethub authorize`" + CLEAR)
		return multistep.ActionHalt
	}

	return multistep.ActionContinue
}
Ejemplo n.º 2
0
func NewConf(path string) (conf, []error) {
	con := conf{}

	// We may have multiple errors here
	errs := make([]error, 0)

	c, err := config.ReadDefault(path)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not read config file: \n%s\n", err)
		os.Exit(1)
	}

	token, err := c.String("settings", "token")
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing token: %s", err))
	}
	con.libToken = token

	con.libUser, err = c.String("settings", "email")
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing user: %s", err))
	}

	con.libSource, err = c.String("settings", "source")
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing source: %s", err))
	}

	con.url, err = c.String("settings", "url")
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing url: %s", err))
	}

	con.rawFlushInterval, err = c.String("settings", "flush_interval")
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing flush_interval: %s", err))
	}

	con.flushInterval, err = time.ParseDuration(con.rawFlushInterval)
	if err != nil {
		errs = append(errs, fmt.Errorf("Failed parsing flush_interval: %s", err))
	}

	log.Printf("Loaded configuration: %v", con)

	// Set errs to nil if there are none
	if len(errs) == 0 {
		errs = nil
	}

	return con, errs
}
Ejemplo n.º 3
0
func (*StepInjectConfiguration) Run(state multistep.StateBag) multistep.StepAction {
	log.Println("Injecting configuration...")

	configPath := state.Get("config_path").(string)

	var path string

	// Determine if we are dealing with a custom config path
	if configPath == "" {
		// Default to the home directory
		path = os.Getenv("HOME") + "/.gethubconfig"
	} else {
		// They've specified a custom config path
		log.Println("Environment specified config path", configPath)
		path = configPath + ".gethubconfig"
	}

	// Read the file
	c, err := config.ReadDefault(path)

	log.Println(err)

	ignoredReposDirty, _ := c.String("ignores", "repo")
	ignoredOwnersDirty, _ := c.String("ignores", "owner")

	owners := []string{}
	repos := []string{}

	// Trim whitespace from the user configuration
	for _, ignoredRepo := range strings.Split(ignoredReposDirty, ",") {
		repos = append(repos, strings.TrimSpace(ignoredRepo))
	}
	for _, ignoredOwner := range strings.Split(ignoredOwnersDirty, ",") {
		owners = append(owners, strings.TrimSpace(ignoredOwner))
	}

	gpath, _ := c.String("gethub", "path")
	state.Put("path", gpath)
	token, _ := c.String("github", "token")
	state.Put("token", token)
	username, _ := c.String("github", "username")
	state.Put("username", username)
	host, _ := c.String("github", "host")
	if host == "" {
		host = githubAPIHost
	}
	state.Put("host", host)

	state.Put("ignored_repos", repos)
	state.Put("ignored_owners", owners)

	return multistep.ActionContinue
}