77 opts . banner = "Usage: parse_changelog.rb [options]"
88 opts . on ( "--old VERSION" , "Old version (e.g., 1.84.0)" ) { |v | options [ :old ] = v }
99 opts . on ( "--new VERSION" , "New version (e.g., 1.86.1)" ) { |v | options [ :new ] = v }
10+ opts . on ( "--no-recommendations" , "Skip recommendation and rationale columns" ) { options [ :no_recommendations ] = true }
1011end . parse!
1112
1213unless options [ :old ] && options [ :new ]
@@ -47,33 +48,60 @@ def extract_cops(lines, section_header)
4748 # 2. * [#123](url): Add new `Cop/Name` cop.
4849 # 3. * **Cop/Name**: Description ([#123](url))
4950
50- if line =~ /^\s *\* \s +.*`([^`]+)`.*\[ #(\d +)\] \( ([^)]+)\) :?\s *(.*)$/
51- cops << { name : $1, pr_id : $2, pr_url : $3, description : $4. strip . gsub ( /\. $/ , '' ) }
52- elsif line =~ /^\s *\* \s +.*`([^`]+)`.*:?\s *(.*)\s +\( \[ #(\d +)\] \( ([^)]+)\) \) $/
53- cops << { name : $1, pr_id : $3, pr_url : $4, description : $2. strip . gsub ( /\. $/ , '' ) }
54- elsif line =~ /^\s *\* \s +\[ #(\d +)\] \( ([^)]+)\) :\s +.*`([^`]+)`\s *(.*)$/
55- cops << { name : $3, pr_id : $1, pr_url : $2, description : $4. strip . gsub ( /\. $/ , '' ) }
51+ # Regex 1: * [#123](url): Add new `Cop/Name` cop. ([@user][])
52+ # Regex 2: * Add new `Cop/Name` cop. ([#123](url))
53+ # Regex 3: * **Cop/Name**: Description ([#123](url))
54+
55+ # Regex 1: * [#123](url): Add new `Cop/Name` cop. ([@user][])
56+ # Regex 2: * Add new `Cop/Name` cop. ([#123](url))
57+ # Regex 3: * **Cop/Name**: Description ([#123](url))
58+
59+ if line =~ /^\s *\* \s +\[ #(\d +)\] \( ([^)]+)\) :\s +(.*)\s *`([^`]+)`.*$/
60+ pr_id , pr_url , desc , name = $1, $2, $3, $4
61+ elsif line =~ /^\s *\* \s +(.*)\s *`([^`]+)`.*\[ #(\d +)\] \( ([^)]+)\) .*$/
62+ desc , name , pr_id , pr_url = $1, $2, $3, $4
5663 elsif line =~ /^\s *\* \s +\* \* ([^*]+)\* \* :\s *(.*)\s +\( \[ #(\d +)\] \( ([^)]+)\) \) $/
57- cops << { name : $1, pr_id : $3, pr_url : $4, description : $2. strip . gsub ( /\. $/ , '' ) }
64+ name , desc , pr_id , pr_url = $1, $2, $3, $4
65+ else
66+ next
5867 end
68+
69+ # Clean up description
70+ desc = desc . to_s . strip
71+ desc = desc . gsub ( /\s *\( \[ @[\w -]*\] \[ \] \) $/ , '' ) # Strip ([@user][])
72+ desc = desc . gsub ( /\s *cop\. ?$/ , '' ) # Strip " cop" at end
73+ desc = desc . gsub ( /^\s *:?\s */ , '' ) # Strip leading colon/space
74+ desc = desc . strip
75+ desc = "New cop" if desc . empty?
76+
77+ cops << { name : name , pr_id : pr_id , pr_url : pr_url , description : desc . gsub ( /\. $/ , '' ) }
5978 end
6079 cops . uniq { |c | c [ :name ] }
6180end
6281
6382new_cops = extract_cops ( relevant_lines , "New features" )
6483changed_cops = extract_cops ( relevant_lines , "Changes" )
6584
66- def print_table ( title , cops , column_name )
85+ def print_table ( title , cops , column_name , options = { } )
6786 return if cops . empty?
6887 puts "## #{ title } "
6988 puts ""
7089 if title == "New cops"
71- puts "| Cop | Description | Recommendation | Rationale | PR |"
72- puts "|-----|-------------|----------------|-----------|-----|"
90+ if options [ :no_recommendations ]
91+ puts "| Cop | Description | PR |"
92+ puts "|-----|-------------|-----|"
93+ else
94+ puts "| Cop | Description | Recommendation | Rationale | PR |"
95+ puts "|-----|-------------|----------------|-----------|-----|"
96+ end
7397 cops . each do |cop |
7498 desc = cop [ :description ] . empty? ? "No description provided" : cop [ :description ]
75- # Placeholders for the agent to fill in
76- puts "| `#{ cop [ :name ] } ` | #{ desc } | {RECOMMENDATION} | {RATIONALE} | [##{ cop [ :pr_id ] } ](#{ cop [ :pr_url ] } ) |"
99+ if options [ :no_recommendations ]
100+ puts "| `#{ cop [ :name ] } ` | #{ desc } | [##{ cop [ :pr_id ] } ](#{ cop [ :pr_url ] } ) |"
101+ else
102+ # Placeholders for the agent to fill in
103+ puts "| `#{ cop [ :name ] } ` | #{ desc } | {RECOMMENDATION} | {RATIONALE} | [##{ cop [ :pr_id ] } ](#{ cop [ :pr_url ] } ) |"
104+ end
77105 end
78106 else
79107 puts "| Cop | #{ column_name } | PR |"
@@ -86,5 +114,5 @@ def print_table(title, cops, column_name)
86114 puts ""
87115end
88116
89- print_table ( "New cops" , new_cops , "Description" )
90- print_table ( "Changed cops" , changed_cops , "Change" )
117+ print_table ( "New cops" , new_cops , "Description" , options )
118+ print_table ( "Changed cops" , changed_cops , "Change" , options )
0 commit comments