Class: Rwm::AffectedDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rwm/affected_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workspace, graph, committed_only: false, base_branch: nil) ⇒ AffectedDetector

Returns a new instance of AffectedDetector.



9
10
11
12
13
14
# File 'lib/rwm/affected_detector.rb', line 9

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
end

Instance Attribute Details

#base_branchObject (readonly)

Returns the value of attribute base_branch.



7
8
9
# File 'lib/rwm/affected_detector.rb', line 7

def base_branch
  @base_branch
end

#graphObject (readonly)

Returns the value of attribute graph.



7
8
9
# File 'lib/rwm/affected_detector.rb', line 7

def graph
  @graph
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



7
8
9
# File 'lib/rwm/affected_detector.rb', line 7

def workspace
  @workspace
end

Instance Method Details

#affected_packagesObject

Returns packages directly changed + their transitive dependents



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rwm/affected_detector.rb', line 17

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) }
  unless root_files.empty?
    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_packagesObject

Just the directly changed packages (no dependents)



37
38
39
40
# File 'lib/rwm/affected_detector.rb', line 37

def directly_changed_packages
  changed_files = detect_changed_files
  map_files_to_packages(changed_files)
end