示例#1
0
// GetCurrent returns the current, open code review.
//
// If there are multiple matching reviews, then an error is returned.
func GetCurrent() (*Review, error) {
	reviewRef := repository.GetHeadRef()
	currentCommit := repository.GetCommitHash(reviewRef)
	var matchingReviews []Review
	for _, review := range ListOpen() {
		if review.Request.ReviewRef == reviewRef {
			matchingReviews = append(matchingReviews, review)
		}
	}
	if matchingReviews == nil {
		return nil, nil
	}
	if len(matchingReviews) != 1 {
		return nil, fmt.Errorf("There are %d open reviews for the ref \"%s\"", len(matchingReviews), reviewRef)
	}
	r := &matchingReviews[0]
	reports := ci.ParseAllValid(repository.GetNotes(ci.Ref, currentCommit))
	r.Reports = reports
	return r, nil
}
示例#2
0
// commentOnReview adds a comment to the current code review.
func commentOnReview(args []string) error {
	commentFlagSet.Parse(args)
	args = commentFlagSet.Args()
	if *lgtm && *nmw {
		return errors.New("You cannot combine the flags -lgtm and -nmw.")
	}

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

	commentedUponCommit := repository.GetCommitHash(r.Request.ReviewRef)
	location := comment.Location{
		Commit: commentedUponCommit,
	}
	if len(args) > 0 {
		location.Path = args[0]
		if len(args) > 1 {
			startLine, err := strconv.ParseUint(args[1], 0, 32)
			if err != nil {
				return err
			}
			location.Range = &comment.Range{
				StartLine: uint32(startLine),
			}
		}
	}

	c := comment.New(*commentMessage)
	c.Location = &location
	c.Parent = *parent
	if *lgtm || *nmw {
		resolved := *lgtm
		c.Resolved = &resolved
	}
	return r.AddComment(c)
}
示例#3
0
// acceptReview adds an LGTM comment to the current code review.
func acceptReview(args []string) error {
	acceptFlagSet.Parse(args)

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

	acceptedCommit := repository.GetCommitHash(r.Request.ReviewRef)
	location := comment.Location{
		Commit: acceptedCommit,
	}
	resolved := true
	c := comment.New(*acceptMessage)
	c.Location = &location
	c.Resolved = &resolved
	return r.AddComment(c)
}