40
40
commentNmw = commentFlagSet .Bool ("nmw" , false , "'Needs More Work'. Set this to express your disapproval. This cannot be combined with lgtm" )
41
41
)
42
42
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
+
43
55
// commentOnReview adds a comment to the current code review.
44
56
func commentOnReview (repo repository.Repo , args []string ) error {
45
57
commentFlagSet .Parse (args )
@@ -64,6 +76,16 @@ func commentOnReview(repo repository.Repo, args []string) error {
64
76
return errors .New ("There is no matching review." )
65
77
}
66
78
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
+
67
89
if * commentMessage == "" {
68
90
editor , err := repo .GetCoreEditor ()
69
91
if err != nil {
@@ -94,12 +116,6 @@ func commentOnReview(repo repository.Repo, args []string) error {
94
116
* commentMessage = string (comment )
95
117
os .Remove (path )
96
118
}
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
- }
103
119
104
120
commentedUponCommit , err := r .GetHeadCommit ()
105
121
if err != nil {
0 commit comments