Example #1
0
func main() {
	flag.Parse()
	pull, err := strconv.ParseInt(flag.Arg(0), 10, 64)
	if err != nil {
		showError(err)
	}

	c, err = github.ApiClientFromHubCredentials()
	if err != nil {
		showError(err)
	}

	user, repo, err := github.GetUserAndRepo()
	if err != nil {
		showError(err)
	}

	getAllComments(c.GetPullRequest(user, repo, int(pull)))
}
Example #2
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [-d] [-p] [-i issue] [-r reviewers]\n\n", os.Args[0])
		fmt.Print("The pull request will be\n  FROM the remote branch with the same name " +
			"as your local branch\n  TO master\n\n")
		fmt.Print("Options:\n")
		flag.PrintDefaults()
	}
	flag.Parse()

	var err error

	// Create API client
	c, err := github.ApiClientFromHubCredentials()
	if err != nil {
		showError(err)
	}
	c.Debug = *debug

	// Determine branch.
	branch, err := getBranch()
	if err != nil {
		showError(err)
	}

	// Get repo.
	user, repo, err := github.GetUserAndRepo()
	if err != nil {
		showError(err)
	}

	revs, err := getRevList(branch)
	if err != nil {
		showError(err)
	}
	if revs == nil {
		showError(
			errors.New(
				fmt.Sprintf("No commits between origin/master and %s. Did you forget to commit?",
					branch)))
	}

	if *pushFirst {
		// Push to origin.
		err = push(branch)
		if err != nil {
			showError(err)
		}
	}

	var pull github.PullRequest
	if *issue >= 0 {
		pull = c.CreatePullRequestFromIssue(user, repo, *issue, branch, "master")
	} else {
		defaultMsg := ""
		if len(revs) == 1 {
			defaultMsg, err = getCommitMessage(revs[0])
			if err != nil {
				showError(err)
			}
		}

		title, body, err := getCommitMessageFromUser(defaultMsg)
		if err != nil {
			showError(err)
		}

		pull = c.CreatePullRequest(user, repo, title, body, branch, "master")
	}

	if pull.Errors != nil {
		showError(errors.New(fmt.Sprintf("error creating PR: %s", pull.Errors)))
	}

	if pull.Number == 0 {
		showError(errors.New("Unknown error creating pull request"))
	}

	fmt.Printf("%s\n", pull.IssueUrl)

	if *reviewers != "" {
		for _, reviewer := range strings.Split(*reviewers, ",") {
			comment := c.CommentOnPullRequest(user, repo, pull.Number,
				fmt.Sprintf("@%s Please review at your leisure", reviewer))
			if comment.Errors != nil {
				showError(errors.New(fmt.Sprintf("error adding comment: %s", comment.Errors)))
			}
		}
	}
}