@@ -95,7 +95,7 @@ def self.request(request_class, path, params = nil)
9595
9696# Fetch existing pull request comments
9797
98- puts "Fetching comments from https://api.github.com/repos/#{ owner_and_repository } /pulls/#{ pr_number } /comments"
98+ puts "Fetching PR comments from https://api.github.com/repos/#{ owner_and_repository } /pulls/#{ pr_number } /comments"
9999
100100existing_comments = Github . get! ( "/repos/#{ owner_and_repository } /pulls/#{ pr_number } /comments" )
101101
@@ -192,10 +192,11 @@ def self.request(request_class, path, params = nil)
192192
193193# If there are any offenses outside the diff, make a separate comment for them
194194
195+ separate_comments = Github . get! ( "/repos/#{ owner_and_repository } /issues/#{ pr_number } /comments" )
196+ existing_separate_comment = separate_comments . find do |comment |
197+ comment . fetch ( "body" ) . include? ( "rubocop-comment-id: outside-diff" )
198+ end
195199if offences_outside_diff . any?
196- existing_comment = comments_made_by_rubocop . find do |comment |
197- comment . fetch ( "body" ) . include? ( "rubocop-comment-id: outside-diff" )
198- end
199200
200201 body = <<~BODY
201202 <!-- rubocop-comment-id: outside-diff -->
@@ -207,11 +208,11 @@ def self.request(request_class, path, params = nil)
207208 "**#{ offense . fetch ( :path ) } :#{ offense . fetch ( :line ) } **\n #{ offense . fetch ( :message ) } "
208209 end . join ( "\n \n " )
209210
210- if existing_comment
211- existing_comment_id = existing_comment . fetch ( "id" )
211+ if existing_separate_comment
212+ existing_comment_id = existing_separate_comment . fetch ( "id" )
212213
213214 # No need to do anything if the offense already exists and hasn't changed
214- if existing_comment . fetch ( "body" ) == body
215+ if existing_separate_comment . fetch ( "body" ) == body
215216 puts "Skipping unchanged separate comment #{ existing_comment_id } "
216217 else
217218 puts "Updating comment #{ existing_comment_id } on pull request"
@@ -222,6 +223,10 @@ def self.request(request_class, path, params = nil)
222223
223224 Github . post! ( "/repos/#{ owner_and_repository } /issues/#{ pr_number } /comments" , body : body )
224225 end
226+ elsif existing_separate_comment
227+ existing_comment_id = existing_separate_comment . fetch ( "id" )
228+ puts "Deleting resolved separate comment #{ existing_comment_id } "
229+ Github . delete ( "/repos/#{ owner_and_repository } /issues/comments/#{ existing_comment_id } " )
225230end
226231
227232# Fail the build if there were any offenses
0 commit comments