Class: RubynCode::Tools::ReviewPr

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/review_pr.rb

Constant Summary collapse

TOOL_NAME =
'review_pr'
DESCRIPTION =
'Review current branch changes against Ruby/Rails best practices. ' \
'Gets the diff of the current branch vs the base branch, analyzes ' \
'each changed file, and provides actionable suggestions with explanations.'
PARAMETERS =
{
  base_branch: {
    type: :string,
    description: 'Base branch to diff against (default: main)',
    required: false
  },
  focus: {
    type: :string,
    description: "Focus area: 'all', 'security', 'performance', 'style', 'testing' (default: all)",
    required: false
  }
}.freeze
RISK_LEVEL =
:read
FILE_CATEGORIES =
[
  ['Ruby',       /\.(rb|rake|gemspec|ru)$/],
  ['Templates',  /\.(erb|haml|slim)$/],
  ['Specs',      /_spec\.rb$|_test\.rb$/],
  ['Migrations', %r{db/migrate}],
  ['Config',     %r{config/|\.ya?ml$}]
].freeze

Constants inherited from Base

Base::REQUIRES_CONFIRMATION

Instance Attribute Summary

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Instance Method Details

#execute(base_branch: 'main', focus: 'all') ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubyn_code/tools/review_pr.rb', line 27

def execute(base_branch: 'main', focus: 'all')
  error = validate_git_repo
  return error if error

  current = current_branch_name
  return current if current.start_with?('Error:')

  base_branch, error = resolve_base(base_branch, current)
  return error if error

  diff = run_git("diff #{base_branch}...HEAD")
  return "No changes found between #{current} and #{base_branch}." if diff.strip.empty?

  build_full_review(current, base_branch, diff, focus)
end