Class: ClaudeTaskMaster::PRComment

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_task_master/pr_comment.rb

Overview

Represents a GitHub PR review comment Detects CodeRabbit, Copilot, and other review bot comments

Constant Summary collapse

ACTIONABLE_SEVERITIES =
%w[major critical warning].freeze
CODERABBIT_BOT =

Known bot authors

'coderabbitai[bot]'
COPILOT_BOT =
'github-copilot[bot]'
KNOWN_BOTS =
[CODERABBIT_BOT, COPILOT_BOT].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ PRComment

Returns a new instance of PRComment.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/claude_task_master/pr_comment.rb', line 17

def initialize(attrs = {})
  @id = attrs[:id] || attrs['id']
  @file_path = attrs[:path] || attrs['path']
  @line = attrs[:line] || attrs['line']
  @start_line = attrs[:start_line] || attrs['start_line']
  @body = attrs[:body] || attrs['body']
  @author = extract_author(attrs[:user] || attrs['user'])
  @created_at = attrs[:created_at] || attrs['created_at']
  @updated_at = attrs[:updated_at] || attrs['updated_at']
  @html_url = attrs[:html_url] || attrs['html_url']
  @resolved = attrs[:resolved] || attrs['resolved']
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def body
  @body
end

#created_atObject (readonly)

Returns the value of attribute created_at.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def created_at
  @created_at
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def file_path
  @file_path
end

#html_urlObject (readonly)

Returns the value of attribute html_url.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def html_url
  @html_url
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def id
  @id
end

#lineObject (readonly)

Returns the value of attribute line.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def line
  @line
end

#resolvedObject (readonly)

Returns the value of attribute resolved.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def resolved
  @resolved
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def start_line
  @start_line
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



14
15
16
# File 'lib/claude_task_master/pr_comment.rb', line 14

def updated_at
  @updated_at
end

Class Method Details

.from_api_response(data) ⇒ Object

Create collection from API response



31
32
33
34
# File 'lib/claude_task_master/pr_comment.rb', line 31

def self.from_api_response(data)
  data = [data] unless data.is_a?(Array)
  data.map { |item| new(item) }
end

Instance Method Details

#actionable?Boolean

Check if comment requires attention

Returns:

  • (Boolean)


55
56
57
# File 'lib/claude_task_master/pr_comment.rb', line 55

def actionable?
  ACTIONABLE_SEVERITIES.include?(severity)
end

#from_bot?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/claude_task_master/pr_comment.rb', line 68

def from_bot?
  KNOWN_BOTS.include?(author) || author&.end_with?('[bot]')
end

#from_coderabbit?Boolean

Bot detection

Returns:

  • (Boolean)


60
61
62
# File 'lib/claude_task_master/pr_comment.rb', line 60

def from_coderabbit?
  author == CODERABBIT_BOT
end

#from_copilot?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/claude_task_master/pr_comment.rb', line 64

def from_copilot?
  author == COPILOT_BOT
end

#from_human?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/claude_task_master/pr_comment.rb', line 72

def from_human?
  !from_bot?
end

#has_suggestion?Boolean

Check if comment has committable suggestion

Returns:

  • (Boolean)


86
87
88
# File 'lib/claude_task_master/pr_comment.rb', line 86

def has_suggestion?
  body&.include?('```suggestion') || false
end

#line_rangeObject

Line range as string (e.g., “40-42” or “42”)



37
38
39
40
41
42
# File 'lib/claude_task_master/pr_comment.rb', line 37

def line_range
  @line_range ||= begin
    start = start_line || line
    start == line ? line.to_s : "#{start}-#{line}"
  end
end

#resolved?Boolean

Resolved status

Returns:

  • (Boolean)


77
78
79
# File 'lib/claude_task_master/pr_comment.rb', line 77

def resolved?
  @resolved == true
end

#severityObject

Parse severity from CodeRabbit/Copilot comment body



45
46
47
# File 'lib/claude_task_master/pr_comment.rb', line 45

def severity
  @severity ||= parse_severity
end

#suggestion_codeObject

Extract suggestion code from body



91
92
93
94
95
96
97
98
# File 'lib/claude_task_master/pr_comment.rb', line 91

def suggestion_code
  @suggestion_code ||= begin
    return nil unless body&.include?('```suggestion')

    match = body.match(/```suggestion[^\n]*\n(.*?)\n```/m)
    match ? match[1] : nil
  end
end

#summaryObject

Extract summary from comment body



50
51
52
# File 'lib/claude_task_master/pr_comment.rb', line 50

def summary
  @summary ||= extract_summary
end

#to_hObject

Serialize to hash



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/claude_task_master/pr_comment.rb', line 101

def to_h
  {
    id: id,
    file_path: file_path,
    line_range: line_range,
    author: author,
    severity: severity,
    summary: summary,
    actionable: actionable?,
    from_bot: from_bot?,
    resolved: resolved?,
    has_suggestion: has_suggestion?,
    html_url: html_url
  }
end

#unresolved?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/claude_task_master/pr_comment.rb', line 81

def unresolved?
  @resolved == false
end