1818"""
1919
2020import argparse
21+ from operator import attrgetter
2122import os
2223import subprocess
2324import sys
@@ -107,7 +108,7 @@ def pr_comment_text_for_diff(
107108
108109 # TODO: Refactor this
109110 def find_comment (self , pr : any ) -> any :
110- all_linter_names = [ l . name for l in ALL_LINTERS ]
111+ all_linter_names = list ( map ( attrgetter ( " name" ), ALL_LINTERS ))
111112 other_linter_names = [name for name in all_linter_names if name != self .name ]
112113
113114 other_tags = [
@@ -116,9 +117,10 @@ def find_comment(self, pr: any) -> any:
116117
117118 for comment in pr .as_issue ().get_comments ():
118119 body = comment .body
119- if self .comment_tag in body :
120- if not any (other_tag in body for other_tag in other_tags ):
121- return comment
120+ if self .comment_tag in body and not any (
121+ other_tag in body for other_tag in other_tags
122+ ):
123+ return comment
122124 return None
123125
124126 def update_pr (self , comment_text : str , args : LintArgs , create_new : bool ) -> None :
@@ -139,8 +141,14 @@ def update_pr(self, comment_text: str, args: LintArgs, create_new: bool) -> None
139141
140142
141143 def run (self , args : LintArgs ) -> bool :
144+ if args .verbose :
145+ print (f"got changed files: { args .changed_files } " )
146+
142147 files_to_lint = self .filter_changed_files (args .changed_files )
143148
149+ if not files_to_lint and args .verbose :
150+ print ("no modified files found" )
151+
144152 is_success = True
145153 linter_output = None
146154
@@ -237,10 +245,12 @@ def run_linter_tool(self, cpp_files: List[str], args: LintArgs) -> Optional[str]
237245
238246 if diff_proc .returncode != 0 :
239247 print (f"Git diff failed: { diff_proc .stderr } " )
240- return "Git diff failed"
248+ return None
241249
242250 diff_content = diff_proc .stdout
243251 if not diff_content .strip ():
252+ if args .verbose :
253+ print ("No diff content found" )
244254 return None
245255
246256 tidy_diff_cmd = [
@@ -290,7 +300,7 @@ def _clean_clang_tidy_output(self, output: str) -> Optional[str]:
290300
291301class Doc8LintHelper (LintHelper ):
292302 name = "doc8"
293- friendly_name = "Documentation linter"
303+ friendly_name = "documentation linter"
294304
295305 def instructions (self , doc_files : List [str ], args : LintArgs ) -> str :
296306 files_str = " " .join (doc_files )
@@ -393,31 +403,45 @@ def run_linter_tool(self, doc_files: List[str], args: LintArgs) -> Optional[str]
393403 parsed_args = parser .parse_args ()
394404 args = LintArgs (parsed_args )
395405
396- if args .verbose :
397- print ("Running all linters." )
398-
399406 overall_success = True
407+ failed_linters = []
400408 all_comments = []
401409
402410 for linter in ALL_LINTERS :
403411 if args .verbose :
404- print (f"Running linter: { linter .name } " )
412+ print (f"running linter { linter .name } " )
405413
406414 linter_passed = linter .run (args )
407415 if not linter_passed :
408416 overall_success = False
417+ failed_linters .append (linter .name )
418+ if args .verbose :
419+ print (f"linter { linter .name } failed" )
409420
410421 if linter .comment :
422+ if args .verbose :
423+ print (f"linter { linter .name } has comment: { linter .comment } " )
411424 all_comments .append (linter .comment )
412425
413426 if len (all_comments ):
414427 import json
415428
429+ existing_comments = []
430+ if os .path .exists ("comments" ):
431+ try :
432+ with open ("comments" , "r" ) as f :
433+ existing_comments = json .load (f )
434+ if not isinstance (existing_comments , list ):
435+ existing_comments = []
436+ except Exception :
437+ existing_comments = []
438+
439+ existing_comments .extend (all_comments )
440+
416441 with open ("comments" , "w" ) as f :
417- json .dump (all_comments , f )
442+ json .dump (existing_comments , f )
418443
419444 if not overall_success :
420- print ("error: Some linters failed." )
445+ for name in failed_linters :
446+ print (f"error: linter { name } failed" )
421447 sys .exit (1 )
422- else :
423- print ("All linters passed." )
0 commit comments