Skip to content

Commit 34bc911

Browse files
committed
Merge branch 'master' into reject-review
2 parents 66e648a + 27e8458 commit 34bc911

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

commands/comment.go

Lines changed: 22 additions & 6 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)
@@ -64,6 +76,16 @@ func commentOnReview(repo repository.Repo, args []string) error {
6476
return errors.New("There is no matching review.")
6577
}
6678

79+
if *commentLgtm && *commentNmw {
80+
return errors.New("You cannot combine the flags -lgtm and -nmw.")
81+
}
82+
if *commentLine != 0 && *commentFile == "" {
83+
return errors.New("Specifying a line number with the -l flag requires that you also specify a file name with the -f flag.")
84+
}
85+
if *commentParent != "" && !commentHashExists(*commentParent, r.Comments) {
86+
return errors.New("There is no matching parent comment.")
87+
}
88+
6789
if *commentMessage == "" {
6890
editor, err := repo.GetCoreEditor()
6991
if err != nil {
@@ -94,12 +116,6 @@ func commentOnReview(repo repository.Repo, args []string) error {
94116
*commentMessage = string(comment)
95117
os.Remove(path)
96118
}
97-
if *commentLgtm && *commentNmw {
98-
return errors.New("You cannot combine the flags -lgtm and -nmw.")
99-
}
100-
if *commentLine != 0 && *commentFile == "" {
101-
return errors.New("Specifying a line number with the -l flag requires that you also specify a file name with the -f flag.")
102-
}
103119

104120
commentedUponCommit, err := r.GetHeadCommit()
105121
if err != nil {

review/review.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func updateThreadsStatus(threads []CommentThread) *bool {
8282
sort.Sort(byTimestamp(threads))
8383
noUnresolved := true
8484
var result *bool
85-
for _, thread := range threads {
85+
for i := range threads {
86+
thread := &threads[i]
8687
thread.updateResolvedStatus()
8788
if thread.Resolved != nil {
8889
noUnresolved = noUnresolved && *thread.Resolved

0 commit comments

Comments
 (0)