Example #1
0
func GetPullRequest(user string, quiet bool) error {
	client := github.Login()
	result, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
	if err != nil {
		return err
	}
	if len(user) == 0 {
		return fmt.Errorf("no user specified, use --user option")
	}
	branchName := strings.TrimSpace(string(result))
	opts := &gh.PullRequestListOptions{Head: user + ":" + branchName}
	if !quiet {
		fmt.Fprintf(os.Stdout, "Searching pull request based on %q ...\n", user+":"+branchName)
	}
	prs, _, err := client.PullRequests.List(api.OriginRepoOwner, api.OriginRepoName, opts)
	if err != nil {
		if quiet {
			return nil
		}
		return err
	}
	if len(prs) == 0 && !quiet {
		return fmt.Errorf("no pull request for %q", user+":"+branchName)
	}
	for _, p := range prs {
		if quiet {
			fmt.Fprintf(os.Stdout, "%d\n", *p.Number)
			continue
		}
		fmt.Fprintf(os.Stdout, "[%s] #%d: %q (%s)\n", strings.ToUpper(*p.State), *p.Number, *p.Title, *p.HTMLURL)
	}
	return nil
}
Example #2
0
func CheckoutPullRequest(user, pullName string) error {
	client := github.Login()
	// For lazy people, support using the github urls
	if strings.Contains(pullName, "github.com") {
		parts := strings.Split(pullName, "/")
		pullName = parts[len(parts)-1]
	}
	number, err := strconv.ParseInt(pullName, 10, 64)
	if err != nil {
		return err
	}
	pr, _, err := client.PullRequests.Get(api.OriginRepoOwner, api.OriginRepoName, int(number))
	if err != nil {
		return nil
	}
	fmt.Fprintf(os.Stdout, "--> The local branch name for #%d is %q\n", number, *pr.Head.Ref)
	result, err := exec.Command("git", "rev-parse", "--verify", *pr.Head.Ref).Output()
	if err != nil {
		return fmt.Errorf("Unable to find local branch %q: %v", *pr.Head.Ref, err)
	}
	fmt.Fprintf(os.Stdout, "--> Branch %q points to %q\n", *pr.Head.Ref, string(result))
	if _, err := exec.Command("git", "checkout", *pr.Head.Ref).Output(); err != nil {
		return fmt.Errorf("Unable to checkout  branch %q: %v", *pr.Head.Ref, err)
	}
	fmt.Fprintf(os.Stdout, "--> Switched branch to %q\n", *pr.Head.Ref)
	return nil
}
Example #3
0
func AddTestComment(pullId int, extended, onlyExtended bool, focus, group string) error {
	client := github.Login()
	var commentString = ""
	if extended {
		if len(group) > 0 {
			commentString = testComment + "[extended:" + group + "]"
		} else {
			commentString = testComment + "[extended]"
		}
	}
	if onlyExtended {
		if len(focus) > 0 {
			group += "(" + focus + ")"
		}
		if len(group) > 0 {
			commentString = onlyExtendedComment + "[extended:" + group + "]"
		}
	}
	if len(commentString) == 0 {
		commentString = testComment
	}
	c := &gh.IssueComment{Body: &commentString}
	comment, _, err := client.Issues.CreateComment(api.OriginRepoOwner, api.OriginRepoName, pullId, c)
	if err != nil {
		return err
	}
	fmt.Fprintf(os.Stdout, "Pull request #%d tagged for test %q\n", pullId, *comment.HTMLURL)
	return nil
}
Example #4
0
func AddMergeComment(pullId int) error {
	client := github.Login()
	c := &gh.IssueComment{Body: &mergeComment}
	comment, _, err := client.Issues.CreateComment(api.OriginRepoOwner, api.OriginRepoName, pullId, c)
	if err != nil {
		return err
	}
	fmt.Fprintf(os.Stdout, "Pull request #%d tagged for merge %q\n", pullId, *comment.HTMLURL)
	return nil
}