-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Updater] Remove an unused ApiClient method, Make Dependabot::Job an explicit receiver for more parameters #6810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6fc9a8f
Remove the ApiClient#fetch_job method
brrygrdn 5ae1726
Dependabot::Job knows how to sanitize fetch job definitions
brrygrdn ca32c34
Dependabot::Job knows how to sanitize update job definitions
brrygrdn 3ba8d7b
Remove job from the build_service test helper as it is unused
brrygrdn b1aeef3
Dependabot::Job knows its repo_contents_path
brrygrdn 208c4f7
Command classes have privacy
brrygrdn 8d35610
Use Dependabot::Job as a receiver for job_id, repo_contents_path
brrygrdn 353b016
DRY out job.json key transforms
brrygrdn 29b14e9
Prefer to use job.credentials directly
brrygrdn 5490d47
Improve comment readability, Prefer boolean for predicate methods
brrygrdn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,58 @@ | |
| module Dependabot | ||
| class Job | ||
| TOP_LEVEL_DEPENDENCY_TYPES = %w(direct production development).freeze | ||
|
|
||
| attr_reader :id, :token, :dependencies, :package_manager, :ignore_conditions, | ||
| :existing_pull_requests, :source, :credentials, | ||
| :requirements_update_strategy, :security_advisories, | ||
| :allowed_updates, :vendor_dependencies, :security_updates_only | ||
| PERMITTED_KEYS = %i( | ||
| allowed_updates | ||
| commit_message_options | ||
| dependencies | ||
| existing_pull_requests | ||
| experiments | ||
| ignore_conditions | ||
| lockfile_only | ||
| package_manager | ||
| reject_external_code | ||
| repo_contents_path | ||
| requirements_update_strategy | ||
| security_advisories | ||
| security_updates_only | ||
| source | ||
| update_subdependencies | ||
| updating_a_pull_request | ||
| vendor_dependencies | ||
| ) | ||
|
|
||
| attr_reader :allowed_updates, | ||
| :credentials, | ||
| :dependencies, | ||
| :existing_pull_requests, | ||
| :id, | ||
| :ignore_conditions, | ||
| :package_manager, | ||
| :requirements_update_strategy, | ||
| :security_advisories, | ||
| :security_updates_only, | ||
| :source, | ||
| :token, | ||
| :vendor_dependencies | ||
|
|
||
| def self.new_fetch_job(job_id:, job_definition:, repo_contents_path: nil) | ||
| attrs = standardise_keys(job_definition["job"]).slice(*PERMITTED_KEYS) | ||
|
||
|
|
||
| new(attrs.merge(id: job_id, repo_contents_path: repo_contents_path)) | ||
| end | ||
|
|
||
| def self.new_update_job(job_id:, job_definition:, repo_contents_path: nil) | ||
| attrs = standardise_keys(job_definition["job"]).slice(*PERMITTED_KEYS) | ||
| # The Updater should NOT have access to credentials. Let's use metadata, which | ||
| # can be used by the proxy for matching and applying the real credentials | ||
| attrs[:credentials] = job_definition.dig("job", "credentials_metadata") || [] | ||
|
|
||
| new(attrs.merge(id: job_id, repo_contents_path: repo_contents_path)) | ||
| end | ||
|
|
||
| def self.standardise_keys(hash) | ||
| hash.transform_keys { |key| key.tr("-", "_").to_sym } | ||
| end | ||
|
|
||
| # NOTE: "attributes" are fetched and injected at run time from | ||
| # dependabot-api using the UpdateJobPrivateSerializer | ||
|
|
@@ -37,6 +84,7 @@ def initialize(attributes) | |
| @lockfile_only = attributes.fetch(:lockfile_only) | ||
| @package_manager = attributes.fetch(:package_manager) | ||
| @reject_external_code = attributes.fetch(:reject_external_code, false) | ||
| @repo_contents_path = attributes.fetch(:repo_contents_path, nil) | ||
| @requirements_update_strategy = attributes.fetch(:requirements_update_strategy) | ||
| @security_advisories = attributes.fetch(:security_advisories) | ||
| @security_updates_only = attributes.fetch(:security_updates_only) | ||
|
|
@@ -54,11 +102,13 @@ def clone? | |
| Dependabot::Utils.always_clone_for_package_manager?(@package_manager) | ||
| end | ||
|
|
||
| def already_cloned? | ||
| return unless Environment.repo_contents_path | ||
| # Some Core components test for a non-nil repo_contents_path as an implicit | ||
| # signal they should use cloning behaviour, so we present it as nil unless | ||
| # cloning is enabled to avoid unexpected behaviour. | ||
| def repo_contents_path | ||
| return nil unless clone? | ||
|
|
||
| # For testing, the source repo may already be mounted. | ||
| @already_cloned ||= File.directory?(File.join(Environment.repo_contents_path, ".git")) | ||
| @repo_contents_path | ||
| end | ||
|
|
||
| def lockfile_only? | ||
|
|
@@ -140,25 +190,19 @@ def security_fix?(dependency) | |
| end | ||
|
|
||
| def name_normaliser | ||
| Dependabot::Dependency. | ||
| name_normaliser_for_package_manager(package_manager) | ||
| Dependabot::Dependency.name_normaliser_for_package_manager(package_manager) | ||
| end | ||
|
|
||
| def experiments | ||
| return {} unless @experiments | ||
|
|
||
| @experiments. | ||
| transform_keys { |key| key.tr("-", "_") }. | ||
| transform_keys(&:to_sym) | ||
| self.class.standardise_keys(@experiments) | ||
| end | ||
|
|
||
| def commit_message_options | ||
| return {} unless @commit_message_options | ||
|
|
||
| @commit_message_options. | ||
| transform_keys { |key| key.tr("-", "_") }. | ||
| transform_keys(&:to_sym). | ||
| compact | ||
| self.class.standardise_keys(@commit_message_options).compact | ||
| end | ||
|
|
||
| private | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since a job is supposed to live/execute in a transient environment, I'm really digging
Environmentas a global (hopefully unchanging) space to store facts 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is currently an Updater-isim but I think we should probably split it out into Core and have an
Dependabot::UpdaterEnvironmentmodule which extendsDependabot::Environmentat some point as I like the pattern.