Skip to content

Commit

Permalink
spike
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishnha committed Jun 17, 2024
1 parent 11ce6b8 commit f82a752
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
2 changes: 2 additions & 0 deletions updater/lib/dependabot/dependency_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def should_replace_existing_pr?
updated_dependencies.map { |x| x.name.downcase }.uniq.sort != T.must(job.dependencies).map(&:downcase).uniq.sort
end

# Now that updated_dependency_files can store the updated_dependencies too, we need to make sure they don't get lost
sig { params(dependency_changes: T::Array[DependencyChange]).void }
def merge_changes!(dependency_changes)
dependency_changes.each do |dependency_change|
Expand Down Expand Up @@ -173,6 +174,7 @@ def matches_existing_pr?

private

# FIXME: this needs to be updated to also consider the directory once it's in teh existing-group-pull-requests repsonse

Check failure on line 177 in updater/lib/dependabot/dependency_change.rb

View workflow job for this annotation

GitHub Actions / Check for spelling errors

teh ==> the

Check failure on line 177 in updater/lib/dependabot/dependency_change.rb

View workflow job for this annotation

GitHub Actions / Check for spelling errors

repsonse ==> response
sig { returns(T::Set[T::Hash[String, T.any(String, T::Boolean)]]) }
def updated_dependencies_set
Set.new(
Expand Down
40 changes: 37 additions & 3 deletions updater/lib/dependabot/updater/dependency_group_change_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(initial_dependency_files:)
@updated_dependencies = []

@dependency_file_batch = initial_dependency_files.each_with_object({}) do |file, hsh|
hsh[file.path] = { file: file, changed: false, changes: 0 }
hsh[file.path] = { file: file, updated_dependencies: [], changed: false, changes: 0 }
end

@vendored_dependency_batch = {}
Expand Down Expand Up @@ -45,8 +45,15 @@ def updated_dependency_files
end

def merge(dependency_change)
merge_dependency_changes(dependency_change.updated_dependencies)
merge_file_changes(dependency_change.updated_dependency_files)
if feature_enabled?(:dependency_has_directory)
merge_file_and_dependency_changes_to_batch(
dependency_change.updated_dependencies,
dependency_change.updated_dependency_files
)
else
merge_dependency_changes(dependency_change.updated_dependencies)
merge_file_changes(dependency_change.updated_dependency_files)
end

Dependabot.logger.debug("Dependencies updated:")
debug_updated_dependencies
Expand Down Expand Up @@ -95,6 +102,33 @@ def merge_file_to_batch(file, batch)
batch[file.path] = { file: file, changed: true, changes: change_count + 1 }
end

# FIXME: This is one of the harder changes to make
# we can either store the updated dpeendencies on the updated_dependnecy_file object

Check failure on line 106 in updater/lib/dependabot/updater/dependency_group_change_batch.rb

View workflow job for this annotation

GitHub Actions / Check for spelling errors

dpeendencies ==> dependencies
# or we can save the directory on the updated_dependency themselves
# Here I take a hybrid approach and end up saving the file separate from the updated dependencies list that goes on it
def merge_file_and_dependency_changes(updated_dependencies, updated_dependency_files)
updated_dependency_files.each do |updated_file|
if updated_file.vendored_file?
merge_file_to_batch(updated_file, @vendored_dependency_batch, updated_dependencies)
else
merge_file_to_batch(updated_file, @dependency_file_batch, updated_dependencies)
end
end
end

def merge_file_and_dependency_changes_to_batch(file, batch, updated_dependencies)
change_count = if (existing_file = batch[file.path])
existing_file.fetch(:change_count, 0)
else
# The file is newly encountered
Dependabot.logger.debug("File #{file.operation}d: '#{file.path}'")
0
end

updated_dependencies_list = merge_dependency_changes(updated_dependencies)
batch[file.path] = { file: file, updated_dependencies: updated_dependencies_list, changed: true, changes: change_count + 1 }
end

def debug_updated_dependencies
return unless Dependabot.logger.debug?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ def perform
sig { returns(Dependabot::DependencyGroup) }
attr_reader :group

# FIXME:
# - every time the directory changes we lose track of the updated_dependencies from the previous directory
# for a grouped udpate

Check failure on line 94 in updater/lib/dependabot/updater/operations/create_group_update_pull_request.rb

View workflow job for this annotation

GitHub Actions / Check for spelling errors

udpate ==> update
# - we want to list the updated dependencies under each updated_dependency_file. We will have to keep the current list
# of updated dependencies for backwards compatibility for now. We lose the list of updated dependencies for each directory
# after the dependency_change.merge_changes! call.
sig { returns(T.nilable(Dependabot::DependencyChange)) }
def dependency_change
return @dependency_change if defined?(@dependency_change)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def run_grouped_dependency_updates # rubocop:disable Metrics/AbcSize
end

groups_without_pr.each do |group|
result = run_update_for(group)
if result
grouped_update_result = run_grouped_update_for(group)
if grouped_update_result
# Add the actual updated dependencies to the handled list so they don't get updated individually.
dependency_snapshot.add_handled_dependencies(result.updated_dependencies.map(&:name))
dependency_snapshot.add_handled_dependencies(grouped_update_result.updated_dependencies.map(&:name))
else
# The update failed, add the suspected dependencies to the handled list so they don't update individually.
dependency_snapshot.add_handled_dependencies(group.dependencies.map(&:name))
Expand All @@ -138,7 +138,7 @@ def run_grouped_dependency_updates # rubocop:disable Metrics/AbcSize
end

sig { params(group: Dependabot::DependencyGroup).returns(T.nilable(Dependabot::DependencyChange)) }
def run_update_for(group)
def run_grouped_update_for(group)
Dependabot::Updater::Operations::CreateGroupUpdatePullRequest.new(
service: service,
job: job,
Expand Down

0 comments on commit f82a752

Please sign in to comment.