Class: Rwm::AffectedDetector
- Inherits:
-
Object
- Object
- Rwm::AffectedDetector
- Defined in:
- lib/rwm/affected_detector.rb
Constant Summary collapse
- IGNORED_ROOT_PATTERNS =
[ "*.md", "LICENSE*", "CHANGELOG*", ".github/**", ".vscode/**", ".idea/**", "docs/**", ".rwm/**", ].freeze
- IGNORE_FILE =
"affected_ignore"
Instance Attribute Summary collapse
-
#base_branch ⇒ Object
readonly
Returns the value of attribute base_branch.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
-
#affected_packages ⇒ Object
Returns packages directly changed + their transitive dependents.
-
#directly_changed_packages ⇒ Object
Just the directly changed packages (no dependents).
-
#initialize(workspace, graph, committed_only: false, base_branch: nil) ⇒ AffectedDetector
constructor
A new instance of AffectedDetector.
Constructor Details
#initialize(workspace, graph, committed_only: false, base_branch: nil) ⇒ AffectedDetector
Returns a new instance of AffectedDetector.
22 23 24 25 26 27 28 |
# File 'lib/rwm/affected_detector.rb', line 22 def initialize(workspace, graph, committed_only: false, base_branch: nil) @workspace = workspace @graph = graph @committed_only = committed_only @base_branch = base_branch || detect_base_branch validate_base_branch! if base_branch end |
Instance Attribute Details
#base_branch ⇒ Object (readonly)
Returns the value of attribute base_branch.
20 21 22 |
# File 'lib/rwm/affected_detector.rb', line 20 def base_branch @base_branch end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
20 21 22 |
# File 'lib/rwm/affected_detector.rb', line 20 def graph @graph end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
20 21 22 |
# File 'lib/rwm/affected_detector.rb', line 20 def workspace @workspace end |
Instance Method Details
#affected_packages ⇒ Object
Returns packages directly changed + their transitive dependents
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rwm/affected_detector.rb', line 31 def affected_packages changed_files = detect_changed_files directly_changed = map_files_to_packages(changed_files) # If root-level files changed (outside any package), all packages are affected root_files = changed_files.reject { |f| file_in_any_package?(f) } significant_root_files = root_files.reject { |f| ignored_root_file?(f) } unless significant_root_files.empty? Rwm.debug("affected: significant root files changed: #{significant_root_files.join(', ')}") return workspace.packages end # Collect transitive dependents of directly changed packages all_affected = Set.new(directly_changed.map(&:name)) directly_changed.each do |pkg| graph.transitive_dependents(pkg.name).each { |name| all_affected << name } end workspace.packages.select { |pkg| all_affected.include?(pkg.name) } end |
#directly_changed_packages ⇒ Object
Just the directly changed packages (no dependents)
54 55 56 57 |
# File 'lib/rwm/affected_detector.rb', line 54 def directly_changed_packages changed_files = detect_changed_files map_files_to_packages(changed_files) end |