visualize_packwerk 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbd24c4c7be488fb37b173c00512196884dafe06e1788bbfb9fd3161988f395b
4
- data.tar.gz: 0c4da79eef14eba7759074636a556d03f2e74a1b964b485bba0d7e090c83471b
3
+ metadata.gz: 4425d05708c5fc0d1ccc3e76d991d222e4089e4ed7717bdcc90ebcb7577b8a0d
4
+ data.tar.gz: 2dc5bb9be62bbb7f3251de7a52b538de4c3ed3c1fc9ef1a53615f617da5f8d1b
5
5
  SHA512:
6
- metadata.gz: 38855ce47c28b248a67de636f9e530e850425b5b7823ccc3bd1f13bde14c6bacd5aa32b68b68f54244325b6c75f8050586b36e98d5c5f0f2e90265728594f854
7
- data.tar.gz: 68c24d06b1f0c9ae4d109806d0459b38a58e6d6827a07bc745fe6dafaddf17a15c359f80a9b21e495c386eac8ceeba5e8e66d40162d3ee572544c01b5fc35e10
6
+ metadata.gz: 1934e543832c1b2df2811fdaed60687d223849b190cae86eeb3e67b2127b4e95cb89409f56d4609641c0bf9e99ba4fde7cb57836cfba0daef77ede66d7fde776
7
+ data.tar.gz: a9e3cc970f06aa8a36406fed5e8bff47de3070a9d2b1b0d8f3a3ab5bb4c544da21eb2c92cc158d25871250788d8b10a2f588d08c2851cc2c380916e63ce3b955
data/README.md CHANGED
@@ -3,30 +3,25 @@
3
3
  This gem contains rake tasks to help visualize relationships between packwerk packs.
4
4
 
5
5
  # Usage
6
- ## Building a package graph for a selection of packages (owned by 5 teams max)
7
- ```
8
- bin/rails visualize_packwerk:package_relationships['packs/pack1','packs/pack2']
9
- ```
10
-
11
- # Building a package graph for specific teams (5 teams max)
12
- ```
13
- bin/rails visualize_packwerk:package_relationships_for_teams['Team1','Team2']
14
- ```
15
-
16
- # Building a package graph for all packages (this is slow and produces a huge file)
17
- ```
18
- bin/rails visualize_packwerk:package_relationships
6
+ ## Building a package graph for a selection of packages
7
+ ```ruby
8
+ # Select the packs you want to include
9
+ selected_packs = Packs.all
10
+ selected_packs = Packs.all.select{ |p| ['packs/my_pack_1', 'packs/my_pack_2'].include?(p.name) }
11
+ selected_packs = Packs.all.select{ |p| ['Team 1', 'Team 2'].include?(CodeOwnership.for_package(p)&.name) }
12
+ VisualizePackwerk.package_graph!(selected_packs)
19
13
  ```
20
14
 
21
- # Building a TEAM graph for specific teams
22
- ```
23
- bin/rails visualize_packwerk:team_relationships['Team1','Team2']
15
+ # Building a team graph for specific teams
16
+ ```ruby
17
+ # Select the teams you want to include
18
+ selected_teams = CodeTeams.all
19
+ selected_teams = CodeTeams.all.select{ |t| ['Team 1', 'Team 2'].include?(t.name) }
20
+ VisualizePackwerk.team_graph!(selected_teams)
24
21
  ```
25
22
 
26
- # Building a TEAM graph for all teams (this is slow and produces a huge file)
27
- ```
28
- bin/rails visualize_packwerk:team_relationships
29
- ```
23
+ ## bin/packs
24
+ For simpler use, use `bin/packs` in `use_packwerk` (https://github.com/rubyatscale/use_packwerk)
30
25
 
31
26
  # Want to change something or add a feature?
32
27
  Submit a PR or post an issue!
@@ -22,18 +22,26 @@ module VisualizePackwerk
22
22
  sig { returns(PackageGraph) }
23
23
  def self.construct
24
24
  package_nodes = Set.new
25
- ParsePackwerk.all.each do |p|
26
- # We could consider ignoring the root!
27
- # We would also need to ignore it when parsing PackageNodes.
28
- # next if p.name == ParsePackwerk::ROOT_PACKAGE_NAME
25
+ Packs.all.each do |p|
29
26
  owner = CodeOwnership.for_package(p)
30
- violations_by_package = p.violations.group_by(&:to_package_name).transform_values(&:count)
27
+
28
+ # Here we need to load the package violations and dependencies,
29
+ # so we need to use ParsePackwerk to parse that information.
30
+ package_info = ParsePackwerk.find(p.name)
31
+ next unless package_info # This should not happen unless packs/parse_packwerk change implementation
32
+
33
+ violations = package_info.violations
34
+ violations_by_package = violations.group_by(&:to_package_name).transform_values(&:count)
35
+ violations_by_package.delete('.') # remove root package violations
36
+
37
+ dependencies = package_info.dependencies
38
+ dependencies.delete('.') # remove root package dependencies
31
39
 
32
40
  package_nodes << PackageNode.new(
33
41
  name: p.name,
34
42
  team_name: owner&.name || 'Unknown',
35
43
  violations_by_package: violations_by_package,
36
- dependencies: Set.new(p.dependencies)
44
+ dependencies: Set.new(dependencies)
37
45
  )
38
46
  end
39
47
 
@@ -8,7 +8,7 @@ module VisualizePackwerk
8
8
 
9
9
  sig { params(teams: T::Array[CodeTeams::Team]).void }
10
10
  def create_package_graph_for_teams!(teams)
11
- packages = ParsePackwerk.all.select do |package|
11
+ packages = Packs.all.select do |package|
12
12
  teams.map(&:name).include?(CodeOwnership.for_package(package)&.name)
13
13
  end
14
14
 
@@ -24,14 +24,14 @@ module VisualizePackwerk
24
24
  draw_graph!(team_graph, node_names, show_all_nodes: show_all_teams)
25
25
  end
26
26
 
27
- sig { params(packages: T::Array[ParsePackwerk::Package]).void }
27
+ sig { params(packages: T::Array[Packs::Pack]).void }
28
28
  def create_package_graph!(packages)
29
29
  graph = PackageGraph.construct
30
30
  node_names = packages.map(&:name)
31
31
  draw_graph!(graph, node_names)
32
32
  end
33
33
 
34
- sig { params(packages: T::Array[ParsePackwerk::Package], show_all_nodes: T::Boolean).void }
34
+ sig { params(packages: T::Array[Packs::Pack], show_all_nodes: T::Boolean).void }
35
35
  def create_graph!(packages, show_all_nodes: false)
36
36
  graph = PackageGraph.construct
37
37
  node_names = packages.map(&:name)
@@ -1,16 +1,29 @@
1
1
  # typed: strict
2
2
 
3
+ require 'packs'
4
+ require 'parse_packwerk'
5
+ require 'code_ownership'
6
+ require 'graphviz'
7
+ require 'sorbet-runtime'
8
+
9
+ require 'visualize_packwerk/node_interface'
10
+ require 'visualize_packwerk/graph_interface'
11
+ require 'visualize_packwerk/team_node'
12
+ require 'visualize_packwerk/package_node'
13
+ require 'visualize_packwerk/team_graph'
14
+ require 'visualize_packwerk/package_graph'
15
+ require 'visualize_packwerk/package_relationships'
16
+
3
17
  module VisualizePackwerk
4
- require 'visualize_packwerk/railtie' if defined?(Rails)
5
- require 'parse_packwerk'
6
- require 'code_ownership'
7
- require 'graphviz'
18
+ extend T::Sig
19
+
20
+ sig { params(packages: T::Array[Packs::Pack]).void }
21
+ def self.package_graph!(packages)
22
+ PackageRelationships.new.create_package_graph!(packages)
23
+ end
8
24
 
9
- require 'visualize_packwerk/node_interface'
10
- require 'visualize_packwerk/graph_interface'
11
- require 'visualize_packwerk/team_node'
12
- require 'visualize_packwerk/package_node'
13
- require 'visualize_packwerk/team_graph'
14
- require 'visualize_packwerk/package_graph'
15
- require 'visualize_packwerk/package_relationships'
25
+ sig { params(teams: T::Array[CodeTeams::Team]).void }
26
+ def self.team_graph!(teams)
27
+ PackageRelationships.new.create_team_graph!(teams)
28
+ end
16
29
  end