-
Notifications
You must be signed in to change notification settings - Fork 1
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 #12 from NoRedInk/format-dependency-changes
Format dependency changes for slack output
- Loading branch information
Showing
23 changed files
with
864 additions
and
304 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,34 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2019-01-03 16:54:26 -0600 using RuboCop version 0.60.0. | ||
# on 2019-01-22 16:22:58 -0600 using RuboCop version 0.60.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 1 | ||
# Cop supports --auto-correct. | ||
Lint/UnneededCopDisableDirective: | ||
Exclude: | ||
- 'lib/deploy_complexity/checklists.rb' | ||
|
||
# Offense count: 6 | ||
# Cop supports --auto-correct. | ||
Lint/UnneededCopEnableDirective: | ||
Exclude: | ||
- 'exe/deploy-complexity.rb' | ||
|
||
# Offense count: 2 | ||
# Offense count: 3 | ||
Metrics/AbcSize: | ||
Max: 43 | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: CountComments, ExcludedMethods. | ||
# ExcludedMethods: refine | ||
Metrics/BlockLength: | ||
Max: 32 | ||
Max: 52 | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: CountComments. | ||
Metrics/ClassLength: | ||
Max: 124 | ||
|
||
# Offense count: 6 | ||
# Configuration parameters: CountComments, ExcludedMethods. | ||
Metrics/MethodLength: | ||
Max: 33 | ||
Max: 41 | ||
|
||
# Offense count: 1 | ||
Metrics/PerceivedComplexity: | ||
Max: 10 | ||
Max: 9 | ||
|
||
# Offense count: 11 | ||
# Offense count: 12 | ||
# Configuration parameters: EnforcedStyle. | ||
# SupportedStyles: annotated, template, unannotated | ||
Style/FormatStringToken: | ||
Exclude: | ||
- 'exe/deploy-complexity.rb' | ||
- 'lib/deploy_complexity/deploy.rb' | ||
- 'lib/deploy_complexity/output_formatter.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
# Detects and formats changes in dependencies | ||
# This is the parent class - each type of dependency file should implement | ||
# it's own version of this. See changed_javascript_packages.rb for an example. | ||
class ChangedDependencies | ||
def initialize(file:, old:, new:) | ||
@file = file | ||
@old_dependencies = parse_dependencies(old) | ||
@new_dependencies = parse_dependencies(new) | ||
end | ||
module DeployComplexity | ||
# Detects and formats changes in dependencies | ||
# This is the parent class - each type of dependency file should implement | ||
# it's own version of this. See changed_javascript_packages.rb for an example. | ||
class ChangedDependencies | ||
def initialize(file:, old:, new:) | ||
@file = file | ||
@old_dependencies = parse_dependencies(old) | ||
@new_dependencies = parse_dependencies(new) | ||
end | ||
|
||
def changes | ||
[ | ||
format_dependencies("Added", added_dependencies), | ||
format_dependencies("Removed", removed_dependencies), | ||
format_updated_dependencies(updated_dependencies) | ||
].flatten | ||
end | ||
def changes | ||
[ | ||
format_dependencies("Added", added_dependencies), | ||
format_dependencies("Removed", removed_dependencies), | ||
format_updated_dependencies(updated_dependencies) | ||
].flatten | ||
end | ||
|
||
private | ||
private | ||
|
||
# This should be implemented in the child classes | ||
# @param [String] the dependency file to be parsed | ||
# @return [ Object{String => String} ] map of the dependency name to the version | ||
def parse_dependencies(_file) | ||
{} | ||
end | ||
# This should be implemented in the child classes | ||
# @param [String] the dependency file to be parsed | ||
# @return [ Object{String => String} ] map of the dependency name to the version | ||
def parse_dependencies(_file) | ||
{} | ||
end | ||
|
||
def added_dependencies | ||
@new_dependencies.dup.delete_if { |package, _| @old_dependencies.key?(package) } | ||
end | ||
def added_dependencies | ||
@new_dependencies.dup.delete_if { |package, _| @old_dependencies.key?(package) } | ||
end | ||
|
||
def removed_dependencies | ||
@old_dependencies.dup.delete_if { |package, _| @new_dependencies.key?(package) } | ||
end | ||
def removed_dependencies | ||
@old_dependencies.dup.delete_if { |package, _| @new_dependencies.key?(package) } | ||
end | ||
|
||
def updated_dependencies | ||
@new_dependencies.each_with_object({}) do |(package, new_version), changed_dependencies| | ||
next if @old_dependencies[package].nil? | ||
next if @old_dependencies[package] == new_version | ||
def updated_dependencies | ||
@new_dependencies.each_with_object({}) do |(package, new_version), changed_dependencies| | ||
next if @old_dependencies[package].nil? | ||
next if @old_dependencies[package] == new_version | ||
|
||
changed_dependencies[package] = { | ||
old: @old_dependencies[package], | ||
new: new_version | ||
} | ||
changed_dependencies[package] = { | ||
old: @old_dependencies[package], | ||
new: new_version | ||
} | ||
end | ||
end | ||
end | ||
|
||
def format_dependencies(label, dependencies) | ||
dependencies.map do |(package, version)| | ||
"#{label} #{package}: #{version} (#{@file})" | ||
def format_dependencies(label, dependencies) | ||
dependencies.map do |(package, version)| | ||
"#{label} #{package}: #{version} (#{@file})" | ||
end | ||
end | ||
end | ||
|
||
def format_updated_dependencies(dependencies) | ||
dependencies.map do |(package, versions)| | ||
"Updated #{package}: #{versions.fetch(:old)} -> #{versions.fetch(:new)} (#{@file})" | ||
def format_updated_dependencies(dependencies) | ||
dependencies.map do |(package, versions)| | ||
"Updated #{package}: #{versions.fetch(:old)} -> #{versions.fetch(:new)} (#{@file})" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.