Skip to content

Commit 27e8458

Browse files
committed
Submitting review ec1a0bb
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!
2 parents 960eff4 + 48792a6 commit 27e8458

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

commands/comment.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ var (
4040
commentNmw = commentFlagSet.Bool("nmw", false, "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm")
4141
)
4242

43+
func commentHashExists(hashToFind string, threads []review.CommentThread) bool {
44+
for _, thread := range threads {
45+
if thread.Hash == hashToFind {
46+
return true
47+
}
48+
if commentHashExists(hashToFind, thread.Children) {
49+
return true
50+
}
51+
}
52+
return false
53+
}
54+
4355
// commentOnReview adds a comment to the current code review.
4456
func commentOnReview(repo repository.Repo, args []string) error {
4557
commentFlagSet.Parse(args)
@@ -100,6 +112,10 @@ func commentOnReview(repo repository.Repo, args []string) error {
100112
return errors.New("There is no matching review.")
101113
}
102114

115+
if *commentParent != "" && !commentHashExists(*commentParent, r.Comments) {
116+
return errors.New("There is no matching parent comment.")
117+
}
118+
103119
commentedUponCommit, err := r.GetHeadCommit()
104120
if err != nil {
105121
return err

0 commit comments

Comments
 (0)