Class: Aidp::CommentConsolidator
- Inherits:
-
Object
- Object
- Aidp::CommentConsolidator
- Defined in:
- lib/aidp/comment_consolidator.rb
Overview
Consolidates comments for GitHub issues and PRs by category
Constant Summary collapse
- CATEGORY_HEADERS =
{ progress: "## 🔄 Progress Report", exceptions: "## 🚨 Exceptions and Errors", completion: "## ✅ Completion Summary" }
Instance Method Summary collapse
-
#consolidate_comment(category:, new_content:, append: true) ⇒ String
Update an existing category comment or create a new one.
-
#find_category_comment(category) ⇒ Hash?
Search for an existing comment by its category header.
-
#initialize(repository_client:, number:) ⇒ CommentConsolidator
constructor
A new instance of CommentConsolidator.
Constructor Details
#initialize(repository_client:, number:) ⇒ CommentConsolidator
Returns a new instance of CommentConsolidator.
14 15 16 17 |
# File 'lib/aidp/comment_consolidator.rb', line 14 def initialize(repository_client:, number:) @client = repository_client @number = number end |
Instance Method Details
#consolidate_comment(category:, new_content:, append: true) ⇒ String
Update an existing category comment or create a new one
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aidp/comment_consolidator.rb', line 40 def consolidate_comment(category:, new_content:, append: true) Aidp.log_debug("comment_consolidator", "consolidating_comment", number: @number, category: category, append: append) header = CATEGORY_HEADERS[category] raise ArgumentError, "Invalid category: #{category}" unless header existing_comment = find_category_comment(category) content = if existing_comment && append # Append new content with timestamp existing_body = existing_comment[:body] updated_body = if existing_body.include?(header) existing_body.lines.first(1).join + "### #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\n\n" + new_content + "\n\n" + existing_body.lines[1..]&.join else # Reconstruct comment if header is missing "#{header}\n\n### #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\n\n" + new_content + "\n\n" + existing_body end updated_body else # Create new or replace content "#{header}\n\n### #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}\n\n" + new_content end # Update or create comment if existing_comment Aidp.log_debug("comment_consolidator", "updating_existing_comment", comment_id: existing_comment[:id]) @client.update_comment(existing_comment[:id], content) else Aidp.log_debug("comment_consolidator", "creating_new_comment") @client.post_comment(@number, content) end end |
#find_category_comment(category) ⇒ Hash?
Search for an existing comment by its category header
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aidp/comment_consolidator.rb', line 22 def find_category_comment(category) Aidp.log_debug("comment_consolidator", "searching_category_comment", number: @number, category: category) header = CATEGORY_HEADERS[category] raise ArgumentError, "Invalid category: #{category}" unless header comment = @client.find_comment(@number, header) Aidp.log_debug("comment_consolidator", "find_category_comment_result", found: !comment.nil?) comment end |