Module: Dependabot::Devbox::UpdateRunner
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/devbox/update_runner.rb
Overview
Extracted from exe/dependabot-devbox-update so its per-dependency and
per-PR logic can be unit tested without loading the executable itself
(which RubyGems' bin stub runs via Kernel#load, under which the
conventional $PROGRAM_NAME == __FILE__ require-guard never matches).
Class Method Summary collapse
- .build_cooldown(days) ⇒ Object
- .check_dependency(dependency, files, credentials, cooldown) ⇒ Object
- .major_bump?(dependency) ⇒ Boolean
- .open_pr(source, commit, dependencies, files, credentials, indent: "") ⇒ Object
- .partition_majors(dependencies) ⇒ Object
Class Method Details
.build_cooldown(days) ⇒ Object
21 22 23 24 25 |
# File 'lib/dependabot/devbox/update_runner.rb', line 21 def self.build_cooldown(days) return nil unless days.positive? Dependabot::Package::ReleaseCooldownOptions.new(default_days: days) end |
.check_dependency(dependency, files, credentials, cooldown) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dependabot/devbox/update_runner.rb', line 55 def self.check_dependency(dependency, files, credentials, cooldown) puts "Checking #{dependency.name} (#{dependency.version})..." checker = Dependabot::UpdateCheckers.for_package_manager("devbox").new( dependency: dependency, dependency_files: files, credentials: credentials, update_cooldown: cooldown ) if checker.up_to_date? puts " up to date" return nil end requirements_to_unlock = checker.requirements_unlocked_or_can_be? ? :own : :none begin checker.updated_dependencies(requirements_to_unlock: requirements_to_unlock) rescue Dependabot::AllVersionsIgnored puts " all versions ignored" nil end end |
.major_bump?(dependency) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/dependabot/devbox/update_runner.rb', line 31 def self.major_bump?(dependency) previous = dependency.previous_version current = dependency.version return false unless previous && current previous.to_s.split(".").first != current.to_s.split(".").first end |
.open_pr(source, commit, dependencies, files, credentials, indent: "") ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/dependabot/devbox/update_runner.rb', line 90 def self.open_pr(source, commit, dependencies, files, credentials, indent: "") updater = Dependabot::FileUpdaters.for_package_manager("devbox").new( dependencies: dependencies, dependency_files: files, credentials: credentials ) updated_files = updater.updated_dependency_files pr_creator = Dependabot::PullRequestCreator.new( source: source, base_commit: commit, dependencies: dependencies, files: updated_files, credentials: credentials, label_language: true ) pr = pr_creator.create if pr puts "#{indent}PR created: #{pr.html_url}" else puts "#{indent}PR already exists or no changes needed" end rescue Dependabot::PullRequestCreator::UnmergedPRExists => e puts "#{indent}Skipping: #{e.} (closed but not merged — delete the branch to recreate)" rescue Dependabot::PullRequestCreator::BranchAlreadyExists => e puts "#{indent}Skipping: #{e.} (stale branch with no open PR — delete it to retry)" end |
.partition_majors(dependencies) ⇒ Object
43 44 45 |
# File 'lib/dependabot/devbox/update_runner.rb', line 43 def self.partition_majors(dependencies) dependencies.partition { |dep| major_bump?(dep) } end |