Exemplo n.º 1
0
func post(config cfg, c *client.Client, args []string) error {
	diffArgs := append([]string{"diff"}, args...)
	cmd := exec.Command("git", diffArgs...)
	output, err := cmd.Output()
	if err != nil {
		return err
	}
	diffText := string(output)
	logArgs := append([]string{"log"}, args...)
	cmd = exec.Command("git", logArgs...)
	output, err = cmd.Output()
	if err != nil {
		return err
	}
	commits := string(output)
	cmd = exec.Command("git", "config", "remote.origin.url")
	output, err = cmd.Output()
	if err != nil {
		return err
	}
	repo := string(output)
	location, err := c.PostReview(diffText, config.username, commits, repo)
	if err != nil {
		return err
	}
	fmt.Println(location)
	return nil
}
Exemplo n.º 2
0
func authenticate(client *client.Client, username string) error {
	password, err := askCredentials(username)
	if err != nil {
		return err
	}
	response, err := client.Authenticate(username, password)
	if err != nil {
		return err
	}
	if response.StatusCode != http.StatusOK {
		// We should have been redirected but we weren't
		return errors.New(response.Status)
	}
	return nil
}