示例#1
0
// Submit the current code review request.
//
// The "args" parameter contains all of the command line arguments that followed the subcommand.
func submitReview(repo repository.Repo, args []string) error {
	submitFlagSet.Parse(args)

	if *submitMerge && *submitRebase {
		return errors.New("Only one of --merge or --rebase is allowed.")
	}

	r, err := review.GetCurrent(repo)
	if err != nil {
		return err
	}
	if r == nil {
		return errors.New("There is nothing to submit")
	}

	if !*submitTBR && (r.Resolved == nil || !*r.Resolved) {
		return errors.New("Not submitting as the review has not yet been accepted.")
	}

	target := r.Request.TargetRef
	source := r.Request.ReviewRef
	repo.VerifyGitRefOrDie(target)
	repo.VerifyGitRefOrDie(source)

	if !repo.IsAncestor(target, source) {
		return errors.New("Refusing to submit a non-fast-forward review. First merge the target ref.")
	}

	repo.SwitchToRef(target)
	if *submitMerge {
		repo.MergeRef(source, false)
	} else if *submitRebase {
		repo.RebaseRef(source)
	} else {
		repo.MergeRef(source, true)
	}
	return nil
}
示例#2
0
// 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
}