Esempio n. 1
0
// Get returns the specified code review.
//
// If no review request exists, the returned review is nil.
func Get(revision string) *Review {
	requestNotes := repository.GetNotes(request.Ref, revision)
	requests := request.ParseAllValid(requestNotes)
	if requests == nil {
		return nil
	}
	review := Review{
		Revision: revision,
		Request:  requests[len(requests)-1],
	}
	review.Comments = review.loadComments()
	review.Resolved = updateThreadsStatus(review.Comments)
	review.Submitted = repository.IsAncestor(revision, review.Request.TargetRef)
	// TODO(ojarjur): Optionally fetch the CI status of the last commit
	// in the review for which there are comments.
	return &review
}
Esempio n. 2
0
// Submit the current code review request.
//
// The "args" parameter contains all of the command line arguments that followed the subcommand.
func submitReview(args []string) error {
	submitFlagSet.Parse(args)

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

	r, err := review.GetCurrent()
	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
	repository.VerifyGitRefOrDie(target)
	repository.VerifyGitRefOrDie(source)

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

	repository.SwitchToRef(target)
	if *submitMerge {
		repository.MergeRef(source, false)
	} else if *submitRebase {
		repository.RebaseRef(source)
	} else {
		repository.MergeRef(source, true)
	}
	return nil
}