Class: Ruby::Reforge::GitIntegration
- Inherits:
-
Object
- Object
- Ruby::Reforge::GitIntegration
- Defined in:
- lib/ruby/reforge/git_integration.rb
Instance Method Summary collapse
- #available? ⇒ Boolean
- #commit_code_changes ⇒ Object
- #commit_version_files ⇒ Object
- #create_branch(branch_name) ⇒ Object
-
#initialize(root_path) ⇒ GitIntegration
constructor
A new instance of GitIntegration.
Constructor Details
#initialize(root_path) ⇒ GitIntegration
Returns a new instance of GitIntegration.
8 9 10 |
# File 'lib/ruby/reforge/git_integration.rb', line 8 def initialize(root_path) @root_path = root_path end |
Instance Method Details
#available? ⇒ Boolean
12 13 14 15 |
# File 'lib/ruby/reforge/git_integration.rb', line 12 def available? git_dir = File.join(@root_path, ".git") File.directory?(git_dir) && system("git --version > /dev/null 2>&1") end |
#commit_code_changes ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby/reforge/git_integration.rb', line 37 def commit_code_changes return unless available? # Get list of modified Ruby files modified = `cd #{@root_path} && git diff --name-only --diff-filter=M`.split("\n") ruby_files = modified.select { |f| f.end_with?(".rb") } return if ruby_files.empty? system("cd #{@root_path} && git add #{ruby_files.join(' ')}") system("cd #{@root_path} && git commit -m 'fix: update deprecated Ruby syntax'") end |
#commit_version_files ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ruby/reforge/git_integration.rb', line 24 def commit_version_files return unless available? files = [".ruby-version", "Gemfile"] files += Dir.glob(File.join(@root_path, "**/*.gemspec")) staged_files = files.select { |f| File.exist?(File.join(@root_path, f)) } return if staged_files.empty? system("cd #{@root_path} && git add #{staged_files.join(' ')}") system("cd #{@root_path} && git commit -m 'chore: update Ruby version files'") end |
#create_branch(branch_name) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ruby/reforge/git_integration.rb', line 17 def create_branch(branch_name) return unless available? system("cd #{@root_path} && git checkout -b #{branch_name} 2>/dev/null") || system("cd #{@root_path} && git checkout #{branch_name} 2>/dev/null") end |