forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dependabot#7354 from dependabot/brrygrdn/extract-g…
…roup-creation [Updater] Extract creation of new group Pull Requests into a discrete class
- Loading branch information
Showing
8 changed files
with
168 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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
71 changes: 71 additions & 0 deletions
71
updater/lib/dependabot/updater/operations/create_group_update_pull_request.rb
This file contains 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/updater/group_update_creation" | ||
|
||
# This class implements our strategy for creating a single Pull Request which | ||
# updates all outdated Dependencies within a specific project folder that match | ||
# a specificed Dependency Group. | ||
# | ||
# This will always post a new Pull Request to Dependabot API and does not check | ||
# to see if any exists for the group or any of the dependencies involved. | ||
# | ||
module Dependabot | ||
class Updater | ||
module Operations | ||
class CreateGroupUpdatePullRequest | ||
include GroupUpdateCreation | ||
|
||
# We do not invoke this class directly for any jobs, so let's return false in the event this | ||
# check is called. | ||
def self.applies_to?(*) | ||
false | ||
end | ||
|
||
def self.tag_name | ||
:create_version_group_pr | ||
end | ||
|
||
# Since this class is not invoked generically based on the job definition, this class accepts a `group` argument | ||
# which is expected to be a prepopulated DependencyGroup object. | ||
def initialize(service:, job:, dependency_snapshot:, error_handler:, group:) | ||
@service = service | ||
@job = job | ||
@dependency_snapshot = dependency_snapshot | ||
@error_handler = error_handler | ||
@group = group | ||
end | ||
|
||
def perform | ||
Dependabot.logger.info("Starting update group for '#{group.name}'") | ||
|
||
dependency_change = compile_all_dependency_changes_for(group) | ||
|
||
if dependency_change.updated_dependencies.any? | ||
Dependabot.logger.info("Creating a pull request for '#{group.name}'") | ||
begin | ||
service.create_pull_request(dependency_change, dependency_snapshot.base_commit_sha) | ||
rescue StandardError => e | ||
raise if ErrorHandler::RUN_HALTING_ERRORS.keys.any? { |err| e.is_a?(err) } | ||
|
||
# FIXME: This will result in us reporting a the group name as a dependency name | ||
# | ||
# In future we should modify this method to accept both dependency and group | ||
# so the downstream error handling can tag things appropriately. | ||
error_handler.handle_dependabot_error(error: e, dependency: group) | ||
end | ||
else | ||
Dependabot.logger.info("Nothing to update for Dependency Group: '#{group.name}'") | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :job, | ||
:service, | ||
:dependency_snapshot, | ||
:error_handler, | ||
:group | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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 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
43 changes: 43 additions & 0 deletions
43
...c/fixtures/job_definitions/bundler/version_updates/group_update_all_with_existing_pr.yaml
This file contains 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
job: | ||
package-manager: bundler | ||
source: | ||
provider: github | ||
repo: dependabot/smoke-tests | ||
directory: "/bundler" | ||
branch: | ||
api-endpoint: https://api.github.com/ | ||
hostname: github.com | ||
dependencies: | ||
existing-pull-requests: [] | ||
existing-group-pull-requests: | ||
- dependency-group-name: "group-b" | ||
dependencies: | ||
- dependency-name: "dummy-pkg-b" | ||
dependency-version: "1.2.0" | ||
updating-a-pull-request: false | ||
lockfile-only: false | ||
update-subdependencies: false | ||
ignore-conditions: [] | ||
requirements-update-strategy: | ||
allowed-updates: | ||
- dependency-type: direct | ||
update-type: all | ||
credentials-metadata: | ||
- type: git_source | ||
host: github.com | ||
security-advisories: [] | ||
max-updater-run-time: 2700 | ||
vendor-dependencies: false | ||
experiments: | ||
grouped-updates-prototype: true | ||
reject-external-code: false | ||
commit-message-options: | ||
prefix: | ||
prefix-development: | ||
include-scope: | ||
security-updates-only: false | ||
dependency-groups: | ||
- name: group-b | ||
rules: | ||
patterns: | ||
- "dummy-pkg-b" |