13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/gem_guard/auto_fixer.rb', line 13
def fix_vulnerabilities(vulnerable_dependencies, options = {})
dry_run = options.fetch(:dry_run, false)
interactive = options.fetch(:interactive, false)
create_backup = options.fetch(:backup, true)
unless File.exist?(@gemfile_path)
raise GemGuard::FileError, "Gemfile not found at #{@gemfile_path}. Auto-fix requires a Gemfile."
end
unless File.exist?(@lockfile_path)
raise GemGuard::FileError, "Gemfile.lock not found at #{@lockfile_path}. Run 'bundle install' first."
end
fixes = plan_fixes(vulnerable_dependencies)
if fixes.empty?
return {status: :no_fixes_needed, message: "No automatic fixes available."}
end
if dry_run
return {status: :dry_run, fixes: fixes, message: "Dry run completed. #{fixes.length} fixes planned."}
end
applied_fixes, cancelled = apply_fixes(fixes, interactive: interactive, backup: create_backup)
if cancelled
return {status: :cancelled, message: "No fixes approved."}
end
{
status: :completed,
fixes: applied_fixes,
message: "Applied #{applied_fixes.length} fixes successfully."
}
end
|