Skip to content

Commit

Permalink
Read Gemfile to get current version before downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Sep 17, 2023
1 parent 0879961 commit b6d85d1
Show file tree
Hide file tree
Showing 42 changed files with 241 additions and 193 deletions.
10 changes: 6 additions & 4 deletions copy-updater-files.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Param(
[string] $tag = "v0.230.0"
)
# Find the current version for dependabot-omnibus
$gemfileContent = Get-Content -Path "updater\Gemfile" -Raw
$versionLine = $gemfileContent | Select-String 'gem "dependabot-omnibus", "(.*)"' | Select-Object -ExpandProperty Line
$version = [regex]::Match($versionLine, '"~>(\d+\.\d+\.\d+)"').Groups[1].Value
Write-Output "Found dependabot-omnibus version: $version"

$files = @(
".ruby-version"
Expand Down Expand Up @@ -108,7 +110,7 @@ $files = @(
$baseUrl = "https://raw.githubusercontent.com/dependabot/dependabot-core"

foreach ($name in $files) {
$sourceUrl = "$baseUrl/$tag/$($name)"
$sourceUrl = "$baseUrl/v$version/$($name)"
$destinationPath = Join-Path -Path '.' -ChildPath "$name"

# Write-Host "`Downloading $name ..."
Expand Down
1 change: 1 addition & 0 deletions updater/bin/fetch_files.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__ + "/../lib")
Expand Down
1 change: 1 addition & 0 deletions updater/bin/update_files.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__ + "/../lib")
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/api_client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "http"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/base_command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "raven"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/dependency_change.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This class describes a change to the project's Dependencies which has been
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/dependency_change_builder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/dependency"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/dependency_group_engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/dependency_group"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/dependency_snapshot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "base64"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/environment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Dependabot
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/file_fetcher_command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "base64"
Expand Down
13 changes: 7 additions & 6 deletions updater/lib/dependabot/job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/config/ignore_condition"
Expand Down Expand Up @@ -210,12 +211,12 @@ def vulnerable?(dependency)

# Can't (currently) detect whether git dependencies are vulnerable
version_class =
Dependabot::Utils.
version_class_for_package_manager(dependency.package_manager)
Dependabot::Utils
.version_class_for_package_manager(dependency.package_manager)
return false unless version_class.correct?(dependency.version)

all_versions = dependency.all_versions.
filter_map { |v| version_class.new(v) if version_class.correct?(v) }
all_versions = dependency.all_versions
.filter_map { |v| version_class.new(v) if version_class.correct?(v) }
security_advisories.any? { |a| all_versions.any? { |v| a.vulnerable?(v) } }
end

Expand All @@ -241,8 +242,8 @@ def commit_message_options

def security_advisories_for(dependency)
relevant_advisories =
security_advisories.
select { |adv| adv.fetch("dependency-name").casecmp(dependency.name).zero? }
security_advisories
.select { |adv| adv.fetch("dependency-name").casecmp(dependency.name).zero? }

relevant_advisories.map do |adv|
vulnerable_versions = adv["affected-versions"] || []
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/logger/formats.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "logger"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "raven"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "raven"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/setup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/logger"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/update_files_command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "base64"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/updater.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# Dependabot components
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This class is responsible for aggregating individual DependencyChange objects
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/updater/error_handler.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/errors"
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/updater/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

module Dependabot
Expand Down
6 changes: 5 additions & 1 deletion updater/lib/dependabot/updater/group_update_creation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/dependency_change_builder"
Expand Down Expand Up @@ -217,8 +218,11 @@ def semver_rules_allow_grouping?(group, dependency, checker)
return false if git_dependency?(dependency)

version = Dependabot::Utils.version_class_for_package_manager(job.package_manager).new(dependency.version.to_s)
latest_version = Dependabot::Utils.version_class_for_package_manager(job.package_manager)
.new(checker.latest_version)

# Not every version class implements .major, .minor, .patch so we calculate it here from the segments
latest = semver_segments(checker.latest_version)
latest = semver_segments(latest_version)
current = semver_segments(version)
return group.rules["update-types"].include?("major") if latest[:major] > current[:major]
return group.rules["update-types"].include?("minor") if latest[:minor] > current[:minor]
Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/updater/operations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/operations/create_security_update_pull_request"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/group_update_creation"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/security_update_helpers"
Expand Down Expand Up @@ -201,11 +202,11 @@ def pr_exists_for_latest_version?(checker)
latest_version = checker.latest_version&.to_s
return false if latest_version.nil?

job.existing_pull_requests.
select { |pr| pr.count == 1 }.
map(&:first).
select { |pr| pr.fetch("dependency-name") == checker.dependency.name }.
any? { |pr| pr.fetch("dependency-version", nil) == latest_version }
job.existing_pull_requests
.select { |pr| pr.count == 1 }
.map(&:first)
.select { |pr| pr.fetch("dependency-name") == checker.dependency.name }
.any? { |pr| pr.fetch("dependency-version", nil) == latest_version }
end

def existing_pull_request(updated_dependencies)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/operations/create_group_update_pull_request"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

require "dependabot/updater/group_update_creation"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This class implements our strategy for 'refreshing' an existing Pull Request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This class implements our strategy for 'refreshing' an existing Pull Request
Expand Down
21 changes: 11 additions & 10 deletions updater/lib/dependabot/updater/operations/update_all_versions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This class implements our strategy for iterating over all of the dependencies
Expand Down Expand Up @@ -173,11 +174,11 @@ def pr_exists_for_latest_version?(checker)
latest_version = checker.latest_version&.to_s
return false if latest_version.nil?

job.existing_pull_requests.
select { |pr| pr.count == 1 }.
map(&:first).
select { |pr| pr.fetch("dependency-name") == checker.dependency.name }.
any? { |pr| pr.fetch("dependency-version", nil) == latest_version }
job.existing_pull_requests
.select { |pr| pr.count == 1 }
.map(&:first)
.select { |pr| pr.fetch("dependency-name") == checker.dependency.name }
.any? { |pr| pr.fetch("dependency-version", nil) == latest_version }
end

def existing_pull_request(updated_dependencies)
Expand Down Expand Up @@ -221,9 +222,9 @@ def log_requirements_for_update(requirements_to_unlock, checker)
# If a version update for a peer dependency is possible we should
# defer to the PR that will be created for it to avoid duplicate PRs.
def peer_dependency_should_update_instead?(dependency_name, updated_deps)
updated_deps.
reject { |dep| dep.name == dependency_name }.
any? do |dep|
updated_deps
.reject { |dep| dep.name == dependency_name }
.any? do |dep|
next true if existing_pull_request([dep])

original_peer_dep = ::Dependabot::Dependency.new(
Expand All @@ -232,8 +233,8 @@ def peer_dependency_should_update_instead?(dependency_name, updated_deps)
requirements: dep.previous_requirements,
package_manager: dep.package_manager
)
update_checker_for(original_peer_dep, raise_on_ignored: false).
can_update?(requirements_to_unlock: :own)
update_checker_for(original_peer_dep, raise_on_ignored: false)
.can_update?(requirements_to_unlock: :own)
end
end

Expand Down
1 change: 1 addition & 0 deletions updater/lib/dependabot/updater/security_update_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: false
# frozen_string_literal: true

# This module extracts all helpers required to perform additional update job
Expand Down
Loading

0 comments on commit b6d85d1

Please sign in to comment.