Repositories

Omar Jarjur <ojarjur@google.com>
27e845 Submitting review ec1a0bb46132
Omar Jarjur committed at 2016-01-04 22:58:51

Check that parent comment exists before creating a comment A proposed fix to issue #25

Would be nice to be able to instead use the commentsByHash that is already computed in [review.loadComments](https://github.com/google/git-appraise/blob/master/review/review.go#L177). Suggestions welcome!

Modified commands/comment.go

@@ -40,6 +40,18 @@ var (
commentNmw = commentFlagSet.Bool("nmw", false, "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm")
)
func commentHashExists(hashToFind string, threads []review.CommentThread) bool {
for _, thread := range threads {
if thread.Hash == hashToFind {
return true
}
if commentHashExists(hashToFind, thread.Children) {
return true
}
}
return false
}
// commentOnReview adds a comment to the current code review.
func commentOnReview(repo repository.Repo, args []string) error {
commentFlagSet.Parse(args)
@@ -100,6 +112,10 @@ func commentOnReview(repo repository.Repo, args []string) error {
return errors.New("There is no matching review.")
}
if *commentParent != "" && !commentHashExists(*commentParent, r.Comments) {
return errors.New("There is no matching parent comment.")
}
commentedUponCommit, err := r.GetHeadCommit()
if err != nil {
return err