// Get the commit at which the review request should be anchored. func getReviewCommit(repo repository.Repo, r request.Request, args []string) (string, string, error) { if len(args) > 1 { return "", "", errors.New("Only updating a single review is supported.") } if len(args) == 1 { base, err := repo.MergeBase(r.TargetRef, args[0]) if err != nil { return "", "", err } return args[0], base, nil } base, err := repo.MergeBase(r.TargetRef, r.ReviewRef) if err != nil { return "", "", err } reviewCommits, err := repo.ListCommitsBetween(base, r.ReviewRef) if err != nil { return "", "", err } if reviewCommits == nil { return "", "", errors.New("There are no commits included in the review request") } return reviewCommits[0], base, nil }
// computeReviewStartingCommit computes the first commit in the review. func computeReviewStartingCommit(pr github.PullRequest, repo repository.Repo) (string, error) { if pr.Base == nil || pr.Base.SHA == nil || pr.Head == nil || pr.Head.SHA == nil { return "", ErrInsufficientInfo } prCommits, err := repo.ListCommitsBetween(*pr.Base.SHA, *pr.Head.SHA) if err != nil { return "", err } if len(prCommits) == 0 { return *pr.Head.SHA, nil } return prCommits[0], nil }
// Create a new code review request. // // The "args" parameter is all of the command line arguments that followed the subcommand. func requestReview(repo repository.Repo, args []string) error { requestFlagSet.Parse(args) if !*requestAllowUncommitted { // Requesting a code review with uncommited local changes is usually a mistake, so // we want to report that to the user instead of creating the request. if repo.HasUncommittedChanges() { return errors.New("You have uncommitted or untracked files. Use --allow-uncommitted to ignore those.") } } r := buildRequestFromFlags(repo.GetUserEmail()) if r.ReviewRef == "HEAD" { r.ReviewRef = repo.GetHeadRef() } repo.VerifyGitRefOrDie(r.TargetRef) repo.VerifyGitRefOrDie(r.ReviewRef) r.BaseCommit = repo.GetCommitHash(r.TargetRef) reviewCommits := repo.ListCommitsBetween(r.TargetRef, r.ReviewRef) if reviewCommits == nil { return errors.New("There are no commits included in the review request") } if r.Description == "" { r.Description = repo.GetCommitMessage(reviewCommits[0]) } note, err := r.Write() if err != nil { return err } repo.AppendNote(request.Ref, reviewCommits[0], note) if !*requestQuiet { fmt.Printf(requestSummaryTemplate, reviewCommits[0], r.TargetRef, r.ReviewRef, r.Description) } return nil }