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 +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/code_healer/evolution_job.rb +1 -1
- data/lib/code_healer/healing_job.rb +1 -1
- data/lib/code_healer/healing_workspace_manager.rb +78 -10
- data/lib/code_healer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f73aedfb97cff3da7cb4a3f62b631886ad5cd377796473b705fe86a6311ff74
|
4
|
+
data.tar.gz: 9e7ce1d1b49920f763684844e799724078919f657c559d49e96a2784200323d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
124
|
-
puts "๐
|
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
|
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]
|
211
|
-
#
|
212
|
-
|
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
|
data/lib/code_healer/version.rb
CHANGED