code_healer 0.1.6 โ†’ 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1ceaaefb9e7954b186c14720e3a68876975deed3d720e812420933dd6016484
4
- data.tar.gz: 5299cd3f4a2e394700692d65e74d8132e1bd77b779220cda6b40c0e9db6d2f76
3
+ metadata.gz: 3f73aedfb97cff3da7cb4a3f62b631886ad5cd377796473b705fe86a6311ff74
4
+ data.tar.gz: 9e7ce1d1b49920f763684844e799724078919f657c559d49e96a2784200323d2
5
5
  SHA512:
6
- metadata.gz: a84ffb72f678182aceaf0e39e206e55e9684811c1e2edbccf6bc5368a1a6330123f9215bb5fa81dd47b63042b94a01e93accaa700a958058ad155673b518b68e
7
- data.tar.gz: 1a07538709f991f556c5fe407e8212aeb21f161f107494d4a07323b6db10389b1471ddc9b61834097b8a41161c6e287ec335dd739227562a56842d67b25f7097
6
+ metadata.gz: 6038730a1146276943b9ec4c7e81569a1977873c303c1b36339b589800d55acd1d05beea95808fc34d71cafc0709cfcaaa0fa1940162f9437087baa5a49f0013
7
+ data.tar.gz: 85a7f04e29e7ae8b4ea0cb7e130432d8b5253f7fe6a0e72baa0cd826bbe6a061ee3787a8bcbe7c9080c70b08aebd8c786701aa6940ecffdff57e20e81881baa1
data/CHANGELOG.md CHANGED
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.8] - 2025-01-14
9
+
10
+ ### Changed
11
+ - **Production safety** - Healing workspace no longer modifies main directory directly
12
+ - **Git workflow** - Changes are applied to isolated healing branches only
13
+ - **Pull request automation** - Automatic PR creation when configured
14
+ - **Method renaming** - `merge_fixes_back` โ†’ `create_healing_branch` for clarity
15
+
16
+ ### Fixed
17
+ - **Git operations in isolated healing workspace** - Preserved .git directory during cloning for proper Git operations
18
+ - **Branch creation and commit operations** now work correctly in the isolated workspace
19
+ - **Workspace cleanup** properly removes .git directory to prevent conflicts
20
+
8
21
  ## [0.1.6] - 2025-01-14
9
22
 
10
23
  ### Added
@@ -22,7 +22,7 @@ class EvolutionJob
22
22
 
23
23
  if test_success
24
24
  # Merge back to main repo
25
- healing_branch = CodeHealer::HealingWorkspaceManager.merge_fixes_back(
25
+ healing_branch = CodeHealer::HealingWorkspaceManager.create_healing_branch(
26
26
  Rails.root.to_s,
27
27
  workspace_path,
28
28
  CodeHealer::ConfigManager.git_settings['pr_target_branch'] || 'main'
@@ -33,7 +33,7 @@ module CodeHealer
33
33
 
34
34
  if test_success
35
35
  # Merge back to main repo
36
- healing_branch = CodeHealer::HealingWorkspaceManager.merge_fixes_back(
36
+ healing_branch = CodeHealer::HealingWorkspaceManager.create_healing_branch(
37
37
  Rails.root.to_s,
38
38
  workspace_path,
39
39
  CodeHealer::ConfigManager.git_settings['pr_target_branch'] || 'main'
@@ -120,8 +120,8 @@ module CodeHealer
120
120
  end
121
121
  end
122
122
 
123
- def merge_fixes_back(repo_path, workspace_path, branch_name)
124
- puts "๐Ÿ”„ Merging fixes back to main repository"
123
+ def create_healing_branch(repo_path, workspace_path, branch_name)
124
+ puts "๐Ÿ”„ Creating healing branch for code review"
125
125
 
126
126
  begin
127
127
  # Create healing branch in main repo
@@ -134,22 +134,38 @@ module CodeHealer
134
134
  healing_branch = "code-healer-fix-#{Time.now.to_i}"
135
135
  system("git checkout -b #{healing_branch}")
136
136
 
137
- # Copy fixed files from workspace
137
+ # Copy fixed files from workspace to the new branch
138
+ # This is safe as we're on a new branch, not the main branch
138
139
  copy_fixed_files(workspace_path, repo_path)
139
140
 
140
- # Commit changes
141
+ # Commit changes to the healing branch
141
142
  system("git add .")
142
143
  commit_message = "Fix applied by CodeHealer: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
143
144
  system("git commit -m '#{commit_message}'")
144
145
 
145
- # Push branch
146
+ # Push healing branch (this doesn't affect the main branch)
146
147
  system("git push origin #{healing_branch}")
147
148
 
148
149
  puts "โœ… Healing branch created: #{healing_branch}"
150
+ puts "๐Ÿ”’ Main branch (#{branch_name}) remains unchanged"
151
+ puts "๐Ÿ“ Changes are now available in branch: #{healing_branch}"
152
+
153
+ # Create pull request if auto-create is enabled
154
+ if should_create_pull_request?
155
+ pr_url = create_pull_request(healing_branch, branch_name)
156
+ if pr_url
157
+ puts "๐Ÿ”— Pull request created: #{pr_url}"
158
+ else
159
+ puts "โš ๏ธ Failed to create pull request, but branch is ready"
160
+ end
161
+ else
162
+ puts "๐Ÿ” Review the changes and create a pull request when ready"
163
+ end
164
+
149
165
  healing_branch
150
166
  end
151
167
  rescue => e
152
- puts "โŒ Failed to merge fixes back: #{e.message}"
168
+ puts "โŒ Failed to create healing branch: #{e.message}"
153
169
  nil
154
170
  end
155
171
  end
@@ -161,6 +177,13 @@ module CodeHealer
161
177
 
162
178
  return unless Dir.exist?(workspace_path)
163
179
 
180
+ # Remove .git directory first to avoid conflicts
181
+ git_dir = File.join(workspace_path, '.git')
182
+ if Dir.exist?(git_dir)
183
+ puts "๐Ÿงน [WORKSPACE] Removing .git directory to prevent conflicts..."
184
+ FileUtils.rm_rf(git_dir)
185
+ end
186
+
164
187
  puts "๐Ÿงน [WORKSPACE] Removing workspace directory..."
165
188
  FileUtils.rm_rf(workspace_path)
166
189
  puts "๐Ÿงน [WORKSPACE] Workspace cleanup completed"
@@ -190,6 +213,51 @@ module CodeHealer
190
213
 
191
214
  private
192
215
 
216
+ def should_create_pull_request?
217
+ config = CodeHealer::ConfigManager.config
218
+ auto_create = config.dig('pull_request', 'auto_create')
219
+ auto_create = config.dig(:pull_request, :auto_create) if auto_create.nil?
220
+ auto_create == true
221
+ end
222
+
223
+ def create_pull_request(healing_branch, target_branch)
224
+ puts "๐Ÿ”— Creating pull request for #{healing_branch} โ†’ #{target_branch}"
225
+
226
+ begin
227
+ require 'octokit'
228
+
229
+ config = CodeHealer::ConfigManager.config
230
+ github_token = ENV['GITHUB_TOKEN']
231
+ repo_name = config['github_repo'] || config[:github_repo]
232
+
233
+ unless github_token && repo_name
234
+ puts "โŒ Missing GitHub token or repository configuration"
235
+ return nil
236
+ end
237
+
238
+ # Parse repo name (owner/repo)
239
+ owner, repo = repo_name.split('/')
240
+
241
+ client = Octokit::Client.new(access_token: github_token)
242
+
243
+ # Create pull request
244
+ pr = client.create_pull_request(
245
+ repo_name,
246
+ target_branch,
247
+ healing_branch,
248
+ "CodeHealer: Automated Fix",
249
+ "This pull request contains automated fixes generated by CodeHealer.\n\n" \
250
+ "**Please review the changes before merging.**\n\n" \
251
+ "Generated at: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
252
+ )
253
+
254
+ pr.html_url
255
+ rescue => e
256
+ puts "โŒ Failed to create pull request: #{e.message}"
257
+ nil
258
+ end
259
+ end
260
+
193
261
  def clone_strategy
194
262
  cfg = CodeHealer::ConfigManager.code_heal_directory_config
195
263
  cfg['clone_strategy'] || cfg[:clone_strategy] || "branch"
@@ -207,10 +275,9 @@ module CodeHealer
207
275
  puts "๐ŸŒฟ [WORKSPACE] Clone result: #{result ? 'SUCCESS' : 'FAILED'}"
208
276
 
209
277
  if result
210
- puts "๐ŸŒฟ [WORKSPACE] Removing .git to avoid conflicts..."
211
- # Remove .git to avoid conflicts
212
- FileUtils.rm_rf(File.join(workspace_path, '.git'))
213
- puts "๐ŸŒฟ [WORKSPACE] .git removed successfully"
278
+ puts "๐ŸŒฟ [WORKSPACE] Git repository preserved for healing operations"
279
+ # Keep .git for Git operations during healing
280
+ # We'll clean it up later in cleanup_workspace
214
281
  else
215
282
  puts "๐ŸŒฟ [WORKSPACE] Clone failed, checking workspace..."
216
283
  puts "๐ŸŒฟ [WORKSPACE] Workspace exists: #{Dir.exist?(workspace_path)}"
@@ -237,6 +304,7 @@ module CodeHealer
237
304
  checkout_result = system("git checkout #{current_branch}")
238
305
  puts "๐ŸŒฟ [WORKSPACE] Checkout result: #{checkout_result ? 'SUCCESS' : 'FAILED'}"
239
306
  end
307
+ puts "๐ŸŒฟ [WORKSPACE] Git repository preserved for healing operations"
240
308
  else
241
309
  puts "๐ŸŒฟ [WORKSPACE] Full repo clone failed"
242
310
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeHealer
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_healer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepan Kumar