Exemple #1
0
// GetSummary returns the summary of the specified code review.
//
// If no review request exists, the returned review summary is nil.
func GetSummary(repo repository.Repo, revision string) (*Summary, error) {
	requestNotes := repo.GetNotes(request.Ref, revision)
	commentNotes := repo.GetNotes(comment.Ref, revision)
	summary, err := getSummaryFromNotes(repo, revision, requestNotes, commentNotes)
	if err != nil {
		return nil, err
	}
	currentCommit := revision
	if summary.Request.Alias != "" {
		currentCommit = summary.Request.Alias
	}
	submitted, err := repo.IsAncestor(currentCommit, summary.Request.TargetRef)
	if err != nil {
		return nil, err
	}
	summary.Submitted = submitted
	return summary, nil
}
Exemple #2
0
// Get returns the specified code review.
//
// If no review request exists, the returned review is nil.
func Get(repo repository.Repo, revision string) *Review {
	requestNotes := repo.GetNotes(request.Ref, revision)
	requests := request.ParseAllValid(requestNotes)
	if requests == nil {
		return nil
	}
	review := Review{
		Repo:     repo,
		Revision: revision,
		Request:  requests[len(requests)-1],
	}
	review.Comments = review.loadComments()
	review.Resolved = updateThreadsStatus(review.Comments)
	review.Submitted = repo.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
}
Exemple #3
0
// Get returns the summary of the specified code review.
//
// If no review request exists, the returned review summary is nil.
func GetSummary(repo repository.Repo, revision string) (*ReviewSummary, error) {
	requestNotes := repo.GetNotes(request.Ref, revision)
	requests := request.ParseAllValid(requestNotes)
	if requests == nil {
		return nil, nil
	}
	reviewSummary := ReviewSummary{
		Repo:     repo,
		Revision: revision,
		Request:  requests[len(requests)-1],
	}
	reviewSummary.Comments = reviewSummary.loadComments()
	reviewSummary.Resolved = updateThreadsStatus(reviewSummary.Comments)
	submitted, err := repo.IsAncestor(revision, reviewSummary.Request.TargetRef)
	if err != nil {
		return nil, err
	}
	reviewSummary.Submitted = submitted
	return &reviewSummary, nil
}
Exemple #4
0
// Get returns the specified code review.
//
// If no review request exists, the returned review is nil.
func Get(repo repository.Repo, revision string) *Review {
	requestNotes := repo.GetNotes(request.Ref, revision)
	requests := request.ParseAllValid(requestNotes)
	if requests == nil {
		return nil
	}
	review := Review{
		Repo:     repo,
		Revision: revision,
		Request:  requests[len(requests)-1],
	}
	review.Comments = review.loadComments()
	review.Resolved = updateThreadsStatus(review.Comments)
	review.Submitted = repo.IsAncestor(revision, review.Request.TargetRef)
	currentCommit, err := review.GetHeadCommit()
	if err == nil {
		review.Reports = ci.ParseAllValid(repo.GetNotes(ci.Ref, currentCommit))
		review.Analyses = analyses.ParseAllValid(repo.GetNotes(analyses.Ref, currentCommit))
	}
	return &review
}
Exemple #5
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
}
Exemple #6
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)
	args = submitFlagSet.Args()

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

	var r *review.Review
	var err error
	if len(args) > 1 {
		return errors.New("Only accepting a single review is supported.")
	}
	if len(args) == 1 {
		r, err = review.Get(repo, args[0])
	} else {
		r, err = review.GetCurrent(repo)
	}

	if err != nil {
		return fmt.Errorf("Failed to load the review: %v\n", err)
	}
	if r == nil {
		return errors.New("There is no matching review.")
	}

	if r.Submitted {
		return errors.New("The review has already been submitted.")
	}

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

	target := r.Request.TargetRef
	if err := repo.VerifyGitRef(target); err != nil {
		return err
	}
	source, err := r.GetHeadCommit()
	if err != nil {
		return err
	}

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

	if !(*submitRebase || *submitMerge || *submitFastForward) {
		submitStrategy, err := repo.GetSubmitStrategy()
		if err != nil {
			return err
		}
		if submitStrategy == "merge" && !*submitRebase && !*submitFastForward {
			*submitMerge = true
		}
		if submitStrategy == "rebase" && !*submitMerge && !*submitFastForward {
			*submitRebase = true
		}
		if submitStrategy == "fast-forward" && !*submitRebase && !*submitMerge {
			*submitFastForward = true
		}
	}

	if *submitRebase {
		if err := r.Rebase(*submitArchive); err != nil {
			return err
		}
		source, err = r.GetHeadCommit()
		if err != nil {
			return err
		}
	}

	if err := repo.SwitchToRef(target); err != nil {
		return err
	}
	if *submitMerge {
		submitMessage := fmt.Sprintf("Submitting review %.12s", r.Revision)
		return repo.MergeRef(source, false, submitMessage, r.Request.Description)
	} else {
		return repo.MergeRef(source, true)
	}
}