Skip to content

[Updater] Absorb Security Advisory and Ignore Conditions into Job#6989

Merged
brrygrdn merged 3 commits intomainfrom
brrygrdn/dry-out-filtering-and-config
Apr 4, 2023
Merged

[Updater] Absorb Security Advisory and Ignore Conditions into Job#6989
brrygrdn merged 3 commits intomainfrom
brrygrdn/dry-out-filtering-and-config

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.

Changes to Dependabot::Job

This PR follows up the observation that the Dependabot::Job already implements a security_advisories_for private method which is duplicated and used by the Updater and now the Operation classes. By making this method public, we can just call it from the Job, removing the need to duplicate the method as well as the name_match? helper.

Another source of duplicate is filtering the job.ignore_conditions by a given Dependency name and then hydrating them into a Dependabot::Config::UpdateConfig so they can be passed into core classes as Dependabot::Config::IgnoreCondition object. By preparing the Dependabot::Config::UpdateConfig within the Dependabot::Job once, we can use it to provide this functionality as required.

Finally, there's a duplicated log helper which needs knowledge internal to the Job that isn't otherwise required by the Updater anymore. I've moved it into the job for simplicity, but this isn't an ideal home for it. I've added a note on making this better in future but it requires a deeper change.

@brrygrdn brrygrdn requested a review from a team as a code owner April 3, 2023 14:32
@brrygrdn brrygrdn changed the base branch from main to brrygrdn/dependency-snapshot-can-filter April 3, 2023 15:55
@brrygrdn brrygrdn force-pushed the brrygrdn/dry-out-filtering-and-config branch from acd6322 to 0212772 Compare April 3, 2023 16:28
@brrygrdn brrygrdn changed the base branch from brrygrdn/dependency-snapshot-can-filter to main April 3, 2023 16:29
@brrygrdn brrygrdn force-pushed the brrygrdn/dry-out-filtering-and-config branch from 0212772 to ee46de9 Compare April 3, 2023 17:29
Comment on lines +235 to +250
# This is a workaround for our existing logging using the 'raw'
# ignore conditions passed into the job definition rather than
# the objects returned by `ignore_conditions_for`.
#
# The blocker on adopting Dependabot::Config::IgnoreCondition is
# that it does not have a 'source' attribute which we currently
# use to distinguish rules from the config file from those that
# were created via "@dependabot ignore version" commands
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.

Thanks for the context here 😄

job.name_normaliser.call(name1),
job.name_normaliser.call(name2)
)
job.log_ignore_conditions_for(dependency)
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 see this is a refactor, where behavior shouldn't change at all. I'm still going to take the opportunity to ask about the code that's being updated 😇

It feels 🤏 strange to me to have an operations class tell the job to log something. I wonder if in the longer term it would make sense for the job to return the ignore conditions in a format that can be logged. I have a feeling this is related to your comment in the job class, which I commented on.

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, this is definitely clunky, if it wasn't for the size of the method required to parse the 'raw' ignore_conditions I wouldn't mind it being duplicated.

I did also think about having a mixin that collects up all the common logging methods which might be an adequate middle ground but I punted on it as part of this as there's actually fewer shared logging methods that it seems.

My first preference would be that we effectively only have one notation of ignore conditions, as objects, available on the Job and then have a single log-presentation method but that's annoying non-trivial.

@brrygrdn brrygrdn force-pushed the brrygrdn/dry-out-filtering-and-config branch from ee46de9 to d97e14c Compare April 4, 2023 12:34
@brrygrdn brrygrdn merged commit b1f336e into main Apr 4, 2023
@brrygrdn brrygrdn deleted the brrygrdn/dry-out-filtering-and-config branch April 4, 2023 13:30
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