예제 #1
0
// 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
}
예제 #2
0
// updateReviewDiffs updates the status of a differential review so that it matches the state of the repo.
//
// This consists of making sure the latest commit pushed to the review ref has a corresponding
// diff in the differential review.
func (arc Arcanist) updateReviewDiffs(repo repository.Repo, differentialReview DifferentialReview, headCommit string, req request.Request, r review.Review) {
	if differentialReview.isClosed() {
		return
	}

	headRevision := headCommit
	mergeBase, err := repo.MergeBase(req.TargetRef, headRevision)
	if err != nil {
		log.Fatal(err)
	}
	for _, hashPair := range differentialReview.Hashes {
		if len(hashPair) == 2 && hashPair[0] == commitHashType && hashPair[1] == headCommit {
			// The review already has the hash of the HEAD commit, so we have nothing to do beyond mirroring comments
			// and build status if applicable
			arc.mirrorCommentsIntoReview(repo, differentialReview, r)
			return
		}
	}

	diff, err := arc.createDifferentialDiff(repo, mergeBase, headRevision, req, differentialReview.Diffs)
	if err != nil {
		log.Fatal(err)
	}
	if diff == nil {
		// This means that phabricator silently refused to create the diff. Just move on.
		return
	}

	updateRequest := differentialUpdateRevisionRequest{ID: differentialReview.ID, DiffID: strconv.Itoa(diff.ID)}
	var updateResponse differentialUpdateRevisionResponse
	runArcCommandOrDie("differential.updaterevision", updateRequest, &updateResponse)
	if updateResponse.Error != "" {
		log.Fatal(updateResponse.ErrorMessage)
	}
}
예제 #3
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.
		hasUncommitted, err := repo.HasUncommittedChanges()
		if err != nil {
			return err
		}
		if hasUncommitted {
			return errors.New("You have uncommitted or untracked files. Use --allow-uncommitted to ignore those.")
		}
	}

	userEmail, err := repo.GetUserEmail()
	if err != nil {
		return err
	}
	r := buildRequestFromFlags(userEmail)
	if r.ReviewRef == "HEAD" {
		headRef, err := repo.GetHeadRef()
		if err != nil {
			return err
		}
		r.ReviewRef = headRef
	}
	if err := repo.VerifyGitRef(r.TargetRef); err != nil {
		return err
	}
	if err := repo.VerifyGitRef(r.ReviewRef); err != nil {
		return err
	}
	base, err := repo.MergeBase(r.TargetRef, r.ReviewRef)
	if err != nil {
		return err
	}
	r.BaseCommit = base

	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")
	}

	if r.Description == "" {
		description, err := repo.GetCommitMessage(reviewCommits[0])
		if err != nil {
			return err
		}
		r.Description = description
	}

	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
}