Skip to content

[Updater] Move filtering of parsed dependencies by allow rules or job dependencies#6991

Merged
brrygrdn merged 5 commits intomainfrom
brrygrdn/dependency-snapshot-can-filter
Apr 4, 2023
Merged

[Updater] Move filtering of parsed dependencies by allow rules or job dependencies#6991
brrygrdn merged 5 commits intomainfrom
brrygrdn/dependency-snapshot-can-filter

Conversation

@brrygrdn
Copy link
Copy Markdown
Contributor

@brrygrdn brrygrdn commented Apr 3, 2023

Before adding two more "Operation" classes for Security Updates, we should ensure that any code that is starting to be carried into every Operation class so far is de-duplicated as much as possible.

Rather than repeat logic to filter the parsed dependencies by either those that are permitted by allow_conditions or those which intersect with the job.dependencies within the Updater, I've just moved this logic unto Dependabot::Snapshot and slimmed down the dependencies method(s) in the various classes.

@brrygrdn brrygrdn requested a review from a team as a code owner April 3, 2023 15:55
@brrygrdn brrygrdn force-pushed the brrygrdn/dependency-snapshot-can-filter branch from 120ea42 to 43f450f Compare April 3, 2023 16:30
Comment on lines +139 to +143
# This method does too much, let's make it focused on _just_ determining
# if the given dependency is within the configurations allowed_updates.
#
# The calling operation should be responsible for checking vulnerability
# separately, if required.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +39 to +40
return [] unless job.dependencies&.any?
return @job_dependencies if defined? @job_dependencies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💅 Not significant!

Are there cases where job.dependencies would change? It seems 🤏 surprising to have a guard clause that checks state before the return @ivar if defined? @ivar clause. I would typically expect that to be a part of the memoization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could just remove that line and let it return an implicit empty set it memoizes, I kind of just wanted to call out that we make no attempt to derive the job dependencies if the source is empty - and it shouldn't ever change as all job data is effectively immutable ( something we could maybe enforce later? )

error_handler: error_handler
).perform
rescue *ErrorHandler::RUN_HALTING_ERRORS.keys => e
# TODO: Drop this into Security-specific operations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤤

Comment on lines -602 to +593
allowed_deps = all_deps.select { |d| job.allowed_update?(d) }
allowed_deps = dependency_snapshot.allowed_dependencies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm loving the ergonomics of having dependency_snapshot! 👏

Dependabot.logger.info("Found no dependencies to update after filtering allowed " \
"updates")
end
allowed_deps = allowed_deps.shuffle unless Environment.deterministic_updates?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig the naming. It adds helpful context to a variable name that I had to think about 🙂

dependency_snapshot.dependencies.select do |dep|
job_dependencies.include?(dep.name.downcase)
end
dependency_snapshot.job_dependencies
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

@brrygrdn brrygrdn force-pushed the brrygrdn/dependency-snapshot-can-filter branch from d453cc7 to 6cddb03 Compare April 4, 2023 08:58
@brrygrdn brrygrdn merged commit 0496f2e into main Apr 4, 2023
@brrygrdn brrygrdn deleted the brrygrdn/dependency-snapshot-can-filter branch April 4, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants