cobra_commander 0.15.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.rubocop.yml +0 -5
- data/Gemfile +7 -0
- data/cobra_commander.gemspec +6 -1
- data/doc/dependency_decisions.yml +9 -0
- data/docs/CHANGELOG.md +19 -2
- data/docs/README.md +3 -129
- data/exe/cobra +5 -0
- data/lib/cobra_commander/affected.rb +19 -51
- data/lib/cobra_commander/cli/filters.rb +1 -3
- data/lib/cobra_commander/{output → cli/output}/ascii_tree.rb +7 -5
- data/lib/cobra_commander/cli/output/change.rb +91 -0
- data/lib/cobra_commander/cli/output/dot_graph.rb +21 -0
- data/lib/cobra_commander/cli.rb +58 -30
- data/lib/cobra_commander/component.rb +6 -10
- data/lib/cobra_commander/executor/command.rb +75 -0
- data/lib/cobra_commander/executor/execution.rb +52 -0
- data/lib/cobra_commander/executor/interactive_printer.rb +53 -0
- data/lib/cobra_commander/executor/job.rb +51 -0
- data/lib/cobra_commander/executor/markdown_printer.rb +21 -0
- data/lib/cobra_commander/executor/package_criteria.rb +21 -0
- data/lib/cobra_commander/executor/script.rb +45 -0
- data/lib/cobra_commander/executor/spinners.rb +40 -0
- data/lib/cobra_commander/executor.rb +37 -6
- data/lib/cobra_commander/git_changed.rb +16 -11
- data/lib/cobra_commander/package.rb +21 -0
- data/lib/cobra_commander/registry.rb +29 -0
- data/lib/cobra_commander/source.rb +37 -0
- data/lib/cobra_commander/umbrella.rb +70 -17
- data/lib/cobra_commander/version.rb +1 -1
- data/lib/cobra_commander.rb +10 -16
- data/mkdocs.yml +1 -1
- metadata +37 -43
- data/.editorconfig +0 -11
- data/.github/workflows/ci.yml +0 -44
- data/.github/workflows/release.yml +0 -20
- data/.rubocop_todo.yml +0 -15
- data/LICENSE.txt +0 -21
- data/_config.yml +0 -1
- data/docs/CODE_OF_CONDUCT.md +0 -74
- data/gemfiles/bundler1.gemfile +0 -7
- data/gemfiles/bundler2.gemfile +0 -7
- data/lib/cobra_commander/change.rb +0 -87
- data/lib/cobra_commander/dependencies/bundler/package.rb +0 -17
- data/lib/cobra_commander/dependencies/bundler.rb +0 -44
- data/lib/cobra_commander/dependencies/yarn/package.rb +0 -21
- data/lib/cobra_commander/dependencies/yarn.rb +0 -40
- data/lib/cobra_commander/dependencies.rb +0 -4
- data/lib/cobra_commander/executor/concurrent.rb +0 -51
- data/lib/cobra_commander/executor/context.rb +0 -49
- data/lib/cobra_commander/output/flat_list.rb +0 -16
- data/lib/cobra_commander/output/graph_viz.rb +0 -27
- data/lib/cobra_commander/output/interactive_printer.rb +0 -53
- data/lib/cobra_commander/output/markdown_printer.rb +0 -24
- data/lib/cobra_commander/output.rb +0 -7
- data/portal.yml +0 -12
- data/renovate.json +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a3895a540b9a0393d9574c2117b0cf84bb2de0109be7dada0f75e7355179d39
|
4
|
+
data.tar.gz: 254aff0eb790d9db8b1cb1f216b4e2a3d964b91dee54250403dac9089b4db944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7825c34b935c88c0f36549bba626bddd3f9d58f6cfd815035b8bba7c2f13d07344b4c01b0666d2540ed53ad7001ddd7ddc40edd385be4e30e23ef9dcb616fb04
|
7
|
+
data.tar.gz: c063f162e6525252c4692a026f36f7e016c335fcf5ac48213f77da487737f9378244b233959abbe42ec738bc877e2e40422ca512fbb3ace997f5daa56cac6d20
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/cobra_commander.gemspec
CHANGED
@@ -26,6 +26,11 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.homepage = "http://tech.powerhrg.com/cobra_commander/"
|
27
27
|
spec.license = "MIT"
|
28
28
|
|
29
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
30
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
31
|
+
spec.metadata["source_code_uri"] = "https://github.com/powerhome/cobra_commander"
|
32
|
+
spec.metadata["changelog_uri"] = "https://github.com/powerhome/cobra_commander/blob/main/cobra_commander/docs/CHANGELOG.md"
|
33
|
+
|
29
34
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
30
35
|
f.match(%r{^(test|spec|features)/})
|
31
36
|
end
|
@@ -35,7 +40,6 @@ Gem::Specification.new do |spec|
|
|
35
40
|
|
36
41
|
spec.add_dependency "bundler"
|
37
42
|
spec.add_dependency "concurrent-ruby", "~> 1.1"
|
38
|
-
spec.add_dependency "ruby-graphviz", "~> 1.2.3"
|
39
43
|
spec.add_dependency "thor", ["< 2.0", ">= 0.18.1"]
|
40
44
|
spec.add_dependency "tty-command", "~> 0.10.0"
|
41
45
|
spec.add_dependency "tty-prompt", "~> 0.23.1"
|
@@ -44,6 +48,7 @@ Gem::Specification.new do |spec|
|
|
44
48
|
spec.add_development_dependency "aruba", "~> 0.14.2"
|
45
49
|
spec.add_development_dependency "bundler"
|
46
50
|
spec.add_development_dependency "guard-rspec"
|
51
|
+
spec.add_development_dependency "license_finder", ">= 7.0"
|
47
52
|
spec.add_development_dependency "pry"
|
48
53
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
49
54
|
spec.add_development_dependency "rspec", "~> 3.5"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
- - :inherit_from
|
3
|
+
- https://raw.githubusercontent.com/powerhome/oss-guide/master/license_rules.yml
|
4
|
+
- - :approve
|
5
|
+
- bundler
|
6
|
+
- :who: Carlos Palhares <carlos.palhares@powerhrg.com>
|
7
|
+
:why: 'Bundler <https://rubygems.org/gems/bundler/versions/1.17.3> is licensed under MIT, but license_finder sometimes fails to resolve that with 1.17.3.'
|
8
|
+
:versions: [1.17.3]
|
9
|
+
:when: 2022-11-02 20:36:55.617698000 Z
|
data/docs/CHANGELOG.md
CHANGED
@@ -2,13 +2,30 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## Version 1.0.0 - 2022-10-15
|
6
|
+
|
7
|
+
* Extract Ruby and Yarn package loading to plugins by @xjunior [#87](https://github.com/powerhome/cobra_commander/pull/87)
|
8
|
+
* Remove unused/broken methods from CobraCommander API by @xjunior [#84](https://github.com/powerhome/cobra_commander/pull/84)
|
9
|
+
* Ruby sources are not hardcoded to "components" anymore by @xjunior [#85](https://github.com/powerhome/cobra_commander/pull/85)
|
10
|
+
* Remove graphviz graph in favor of plain dot graph file by @xjunior [#88](https://github.com/powerhome/cobra_commander/pull/88)
|
11
|
+
* Add license_finder to cobra CI by @xjunior [#89](https://github.com/powerhome/cobra_commander/pull/89)
|
12
|
+
* Umbrella now "depends" on all packages in Yarn AND Ruby by @xjunior [#90](https://github.com/powerhome/cobra_commander/pull/90)
|
13
|
+
* Refactor affected to reuse umbrella#resolve by @xjunior [#91](https://github.com/powerhome/cobra_commander/pull/91)
|
14
|
+
* Umbrella root is not a component by itself anymore by @xjunior [#92](https://github.com/powerhome/cobra_commander/pull/92)
|
15
|
+
* Move output into CLI by @xjunior [#93](https://github.com/powerhome/cobra_commander/pull/93)
|
16
|
+
* Simplify Executor and remove Executor::Concurrent by @xjunior [#94](https://github.com/powerhome/cobra_commander/pull/94)
|
17
|
+
|
18
|
+
## Version 0.15.1 - 2022-08-23
|
19
|
+
|
20
|
+
* Fix `--affected` filter [#82](https://github.com/powerhome/cobra_commander/pull/82)
|
21
|
+
|
5
22
|
## Version 0.15.0 - 2022-08-16
|
6
23
|
|
24
|
+
* Resolve YARN dependencies based on yarn workspaces info workspaceDependencies [#81](https://github.com/powerhome/cobra_commander/pull/81)
|
7
25
|
* Add `--affected` filter to `cobra ls` and `cobra exec`, to target all components affected by changes since given branch [#80](https://github.com/powerhome/cobra_commander/pull/80)
|
8
26
|
* Allows a comma separated list of components on `cobra ls` and `cobra exec` instead of a single component [#79](https://github.com/powerhome/cobra_commander/pull/79)
|
9
|
-
* Resolve YARN dependencies based on yarn workspaces info workspaceDependencies [#81](https://github.com/powerhome/cobra_commander/pull/81)
|
10
|
-
* Fix cbra.info links [#70](https://github.com/powerhome/cobra_commander/pull/70)
|
11
27
|
* Replace standardrb by rubocop-powerhome [#78](https://github.com/powerhome/cobra_commander/pull/78)
|
28
|
+
* Fix cbra.info links [#70](https://github.com/powerhome/cobra_commander/pull/70)
|
12
29
|
|
13
30
|
## Version 0.14.0 - 2021-11-24
|
14
31
|
|
data/docs/README.md
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
# cobra_commander
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/cobra_commander)
|
4
|
-
[](https://rubygems.org/gems/cobra_commander)
|
5
|
-
[](https://github.com/powerhome/cobra_commander/actions/workflows/ci.yml)
|
6
|
-
[](https://codeclimate.com/github/powerhome/cobra_commander/maintainability)
|
7
|
-
|
8
3
|
Tools for working with Component Based Rails Apps (see https://cbra.info). Includes tools for graphing both Ruby and Javascript components in an application and their relationships, as well as selectively testing components based on changes made.
|
9
4
|
|
10
5
|
## Installation
|
@@ -23,138 +18,17 @@ Or install it yourself as:
|
|
23
18
|
|
24
19
|
$ gem install cobra_commander
|
25
20
|
|
26
|
-
## Usage (cobra help)
|
27
|
-
|
28
|
-
```bash
|
29
|
-
Commands:
|
30
|
-
cobra changes [--results=RESULTS] [--branch=BRANCH] # Prints list of changed files
|
31
|
-
cobra exec [components] <command> # Executes the command in the context of a given component or set thereof. Defaults to all components.
|
32
|
-
cobra graph [component] # Outputs a graph of a given component or umbrella
|
33
|
-
cobra help [COMMAND] # Describe available commands or one specific command
|
34
|
-
cobra ls [components] # Lists the components in the context of a given component or umbrella
|
35
|
-
cobra tree [component] # Prints the dependency tree of a given component or umbrella
|
36
|
-
cobra version # Prints version
|
37
|
-
|
38
|
-
Options:
|
39
|
-
-a, [--app=APP]
|
40
|
-
# Default: /Users/me/myapp
|
41
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
42
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
43
|
-
```
|
44
|
-
|
45
|
-
### cobra changes
|
46
|
-
|
47
|
-
```sh
|
48
|
-
Usage:
|
49
|
-
cobra changes [--results=RESULTS] [--branch=BRANCH]
|
50
|
-
|
51
|
-
Options:
|
52
|
-
-r, [--results=RESULTS] # Accepts test, full, name or json
|
53
|
-
# Default: test
|
54
|
-
-b, [--branch=BRANCH] # Specified target to calculate against
|
55
|
-
# Default: master
|
56
|
-
-a, [--app=APP]
|
57
|
-
# Default: /Users/me/myapp
|
58
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
59
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
60
|
-
|
61
|
-
Prints list of changed files
|
62
|
-
```
|
63
|
-
|
64
|
-
### cobra exec
|
65
|
-
|
66
|
-
```sh
|
67
|
-
Usage:
|
68
|
-
cobra exec [components] <command>
|
69
|
-
|
70
|
-
[components] is all components by default, or a comma separated list of component names (no spaces between)
|
71
|
-
|
72
|
-
Options:
|
73
|
-
[--affected=AFFECTED] # Components affected since given branch [default: main]
|
74
|
-
-d, [--dependencies], [--no-dependencies] # Run the command on each dependency of a given component
|
75
|
-
-D, [--dependents], [--no-dependents] # Run the command on each dependent of a given component
|
76
|
-
[--self], [--no-self] # Include the own component
|
77
|
-
# Default: true
|
78
|
-
-c, [--concurrency=N] # Max number of jobs to run concurrently
|
79
|
-
# Default: 5
|
80
|
-
-i, [--interactive], [--no-interactive] # Runs in interactive mode to allow the user to inspect the output of each component
|
81
|
-
# Default: true
|
82
|
-
-a, [--app=APP]
|
83
|
-
# Default: /Users/me/myapp
|
84
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
85
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
86
|
-
|
87
|
-
Executes the command in the context of a given component or set thereof. Defaults to all components.
|
88
|
-
```
|
89
|
-
|
90
|
-
### cobra graph
|
91
|
-
|
92
|
-
```sh
|
93
|
-
Usage:
|
94
|
-
cobra graph [component]
|
95
|
-
|
96
|
-
Options:
|
97
|
-
-o, [--output=OUTPUT] # Output file, accepts .png or .dot
|
98
|
-
# Default: /Users/me/myapp/output.png
|
99
|
-
-a, [--app=APP]
|
100
|
-
# Default: /Users/me/myapp
|
101
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
102
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
103
|
-
|
104
|
-
Outputs a graph of a given component or umbrella
|
105
|
-
```
|
106
|
-
|
107
|
-
### cobra ls
|
108
|
-
|
109
|
-
```sh
|
110
|
-
Usage:
|
111
|
-
cobra ls [components]
|
112
|
-
|
113
|
-
[components] is all components by default, or a comma separated list of component names (no spaces between)
|
114
|
-
|
115
|
-
Options:
|
116
|
-
[--affected=AFFECTED] # Components affected since given branch [default: main]
|
117
|
-
-d, [--dependencies], [--no-dependencies] # Lists all dependencies of a given component
|
118
|
-
-D, [--dependents], [--no-dependents] # Lists all dependents of a given component
|
119
|
-
[--self], [--no-self] # Include the own component
|
120
|
-
# Default: true
|
121
|
-
-t, [--total], [--no-total] # Prints the total count of components
|
122
|
-
-a, [--app=APP]
|
123
|
-
# Default: /Users/me/myapp
|
124
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
125
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
126
|
-
|
127
|
-
Lists the components in the context of a given component or umbrella
|
128
|
-
```
|
129
|
-
|
130
|
-
### cobra tree
|
131
|
-
|
132
|
-
```sh
|
133
|
-
Usage:
|
134
|
-
cobra tree [component]
|
135
|
-
|
136
|
-
Options:
|
137
|
-
-a, [--app=APP]
|
138
|
-
# Default: /Users/me/myapp
|
139
|
-
[--js], [--no-js] # Consider only the JS dependency graph
|
140
|
-
[--ruby], [--no-ruby] # Consider only the Ruby dependency graph
|
141
|
-
|
142
|
-
Prints the dependency tree of a given component or umbrella
|
143
|
-
```
|
144
|
-
|
145
21
|
## Development
|
146
22
|
|
147
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
148
|
-
|
149
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
150
24
|
|
151
25
|
### Bundled App
|
152
26
|
|
153
|
-
In order to maintain the features around umbrella apps and specially `changes`, a bundled [`umbrella app repo`](spec/fixtures/app.tgz) is included in this repository. This repo is compacted by `tar`/`gzip` in order to keep isolation, the format was chosen to avoid issues described in https://github.com/swcarpentry/git-novice/issues/272. To avoid the same issues, the workflow for this fixture app is the following:
|
27
|
+
In order to maintain the features around umbrella apps and specially `changes`, a bundled [`umbrella app repo`](spec/fixtures/modified-app.tgz) is included in this repository. This repo is compacted by `tar`/`gzip` in order to keep isolation, the format was chosen to avoid issues described in https://github.com/swcarpentry/git-novice/issues/272. To avoid the same issues, the workflow for this fixture modified-app is the following:
|
154
28
|
|
155
29
|
1. unpack it somewhere outside your repo
|
156
30
|
1. do your changes and commit (locally only, it doesn't have a remote)
|
157
|
-
1. from within the app run `tar cfz path/to/cobra/spec/fixtures/app.tgz .`
|
31
|
+
1. from within the app run `tar cfz path/to/cobra/spec/fixtures/modified-app.tgz .`
|
158
32
|
|
159
33
|
## Contributing
|
160
34
|
|
data/exe/cobra
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "json"
|
4
|
+
|
3
5
|
module CobraCommander
|
4
6
|
# Calculates directly & transitively affected components
|
5
7
|
class Affected
|
6
8
|
def initialize(umbrella, changes)
|
7
9
|
@umbrella = umbrella
|
8
10
|
@changes = changes
|
9
|
-
run!
|
10
11
|
end
|
11
12
|
|
12
13
|
def names
|
13
|
-
@names ||=
|
14
|
+
@names ||= all.map(&:name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def all
|
18
|
+
@all ||= (directly | transitively).sort_by(&:name)
|
14
19
|
end
|
15
20
|
|
16
21
|
def scripts
|
@@ -18,79 +23,42 @@ module CobraCommander
|
|
18
23
|
end
|
19
24
|
|
20
25
|
def directly
|
21
|
-
@directly.
|
26
|
+
@directly ||= @changes.filter_map { |path| @umbrella.resolve(path) }
|
27
|
+
.uniq.sort_by(&:name)
|
22
28
|
end
|
23
29
|
|
24
30
|
def transitively
|
25
|
-
@transitively.
|
31
|
+
@transitively ||= directly.flat_map(&:deep_dependents)
|
32
|
+
.uniq.sort_by(&:name)
|
26
33
|
end
|
27
34
|
|
28
|
-
def
|
35
|
+
def to_json(*_args)
|
29
36
|
{
|
30
37
|
changed_files: @changes,
|
31
|
-
directly_affected_components: directly,
|
32
|
-
transitively_affected_components: transitively,
|
38
|
+
directly_affected_components: directly.map { |c| affected_component(c) },
|
39
|
+
transitively_affected_components: transitively.map { |c| affected_component(c) },
|
33
40
|
test_scripts: scripts,
|
34
41
|
component_names: names,
|
35
|
-
languages:
|
42
|
+
languages: all_affected_packages,
|
36
43
|
}.to_json
|
37
44
|
end
|
38
45
|
|
39
46
|
private
|
40
47
|
|
41
|
-
def run!
|
42
|
-
@transitively = Set.new
|
43
|
-
@directly = Set.new
|
44
|
-
@umbrella.components.each(&method(:add_if_changed))
|
45
|
-
@transitively = @transitively.sort_by(&:name)
|
46
|
-
@directly = @directly.sort_by(&:name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def component_changed?(component)
|
50
|
-
component.root_paths.any? do |component_path|
|
51
|
-
@changes.any? do |file_path|
|
52
|
-
file_path.start_with?(component_path)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_if_changed(component)
|
58
|
-
return unless component_changed?(component)
|
59
|
-
|
60
|
-
@directly << component
|
61
|
-
@transitively.merge(component.deep_dependents)
|
62
|
-
end
|
63
|
-
|
64
48
|
def affected_component(component)
|
65
49
|
{
|
66
50
|
name: component.name,
|
67
|
-
path: component.root_paths,
|
68
|
-
type: component.packages.
|
51
|
+
path: component.root_paths.map(&:to_s),
|
52
|
+
type: component.packages.map(&:key).map(&:to_s),
|
69
53
|
}
|
70
54
|
end
|
71
55
|
|
72
|
-
def all_affected
|
73
|
-
@all_affected ||= (@directly | @transitively).sort_by(&:name)
|
74
|
-
end
|
75
|
-
|
76
56
|
def paths
|
77
|
-
@paths ||=
|
57
|
+
@paths ||= all.map(&:root_paths).flatten
|
78
58
|
end
|
79
59
|
|
80
60
|
def all_affected_packages
|
81
|
-
|
82
|
-
.map(&:packages)
|
83
|
-
.map(&:keys)
|
84
|
-
.flatten
|
85
|
-
.uniq
|
86
|
-
end
|
87
|
-
|
88
|
-
def contains_ruby?
|
89
|
-
all_affected_packages.include?(:bundler)
|
90
|
-
end
|
91
|
-
|
92
|
-
def contains_js?
|
93
|
-
all_affected_packages.include?(:yarn)
|
61
|
+
all.flat_map(&:packages).map(&:key).uniq
|
94
62
|
end
|
95
63
|
end
|
96
64
|
end
|
@@ -13,8 +13,6 @@ module CobraCommander
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def find_component(name)
|
16
|
-
return umbrella.root unless name
|
17
|
-
|
18
16
|
umbrella.find(name) || error("Component #{name} not found, maybe #{suggestion(name)}") || exit(1)
|
19
17
|
end
|
20
18
|
|
@@ -31,7 +29,7 @@ module CobraCommander
|
|
31
29
|
|
32
30
|
def affected_by_changes(origin_branch)
|
33
31
|
changes = GitChanged.new(umbrella.path, origin_branch)
|
34
|
-
Affected.new(umbrella, changes).
|
32
|
+
Affected.new(umbrella, changes).all
|
35
33
|
end
|
36
34
|
|
37
35
|
def filter_component(component_name)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "stringio"
|
4
4
|
|
5
5
|
module CobraCommander
|
6
|
-
module Output
|
6
|
+
module CLI::Output
|
7
7
|
# Prints the tree in a nice tree form
|
8
8
|
class AsciiTree
|
9
9
|
SPACE = " "
|
@@ -11,14 +11,16 @@ module CobraCommander
|
|
11
11
|
TEE = "├── "
|
12
12
|
CORNER = "└── "
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@
|
14
|
+
def initialize(components)
|
15
|
+
@components = components.sort_by(&:name)
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_s
|
19
19
|
StringIO.new.tap do |io|
|
20
|
-
|
21
|
-
|
20
|
+
@components.each do |component|
|
21
|
+
io.puts component.name
|
22
|
+
list_dependencies(io, component)
|
23
|
+
end
|
22
24
|
end.string
|
23
25
|
end
|
24
26
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cobra_commander/git_changed"
|
4
|
+
require "cobra_commander/affected"
|
5
|
+
|
6
|
+
module CobraCommander
|
7
|
+
class CLI
|
8
|
+
module Output
|
9
|
+
# Calculates and prints affected components & files
|
10
|
+
class Change
|
11
|
+
InvalidSelectionError = Class.new(StandardError)
|
12
|
+
|
13
|
+
def initialize(umbrella, oformat, branch, changes: nil)
|
14
|
+
@format = oformat
|
15
|
+
@branch = branch
|
16
|
+
@umbrella = umbrella
|
17
|
+
@changes = changes || GitChanged.new(umbrella.path, branch)
|
18
|
+
end
|
19
|
+
|
20
|
+
def run!
|
21
|
+
assert_valid_result_choice
|
22
|
+
if selected_format?("json")
|
23
|
+
puts affected.to_json
|
24
|
+
else
|
25
|
+
show_full if selected_format?("full")
|
26
|
+
tests_to_run
|
27
|
+
end
|
28
|
+
rescue GitChanged::InvalidSelectionError => e
|
29
|
+
puts e.message
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def affected
|
35
|
+
@affected ||= Affected.new(@umbrella, @changes)
|
36
|
+
end
|
37
|
+
|
38
|
+
def show_full
|
39
|
+
changes_since_last_commit
|
40
|
+
directly_affected_components
|
41
|
+
transitively_affected_components
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_valid_result_choice
|
45
|
+
return if %w[test full name json].include?(@format)
|
46
|
+
|
47
|
+
raise InvalidSelectionError, "--results must be 'test', 'full', 'name' or 'json'"
|
48
|
+
end
|
49
|
+
|
50
|
+
def selected_format?(result)
|
51
|
+
@format == result
|
52
|
+
end
|
53
|
+
|
54
|
+
def changes_since_last_commit
|
55
|
+
puts "<<< Changes since last commit on #{@branch} >>>"
|
56
|
+
puts(*@changes) if @changes.any?
|
57
|
+
puts blank_line
|
58
|
+
end
|
59
|
+
|
60
|
+
def directly_affected_components
|
61
|
+
puts "<<< Directly affected components >>>"
|
62
|
+
affected.directly.each { |component| puts display(component) }
|
63
|
+
puts blank_line
|
64
|
+
end
|
65
|
+
|
66
|
+
def transitively_affected_components
|
67
|
+
puts "<<< Transitively affected components >>>"
|
68
|
+
affected.transitively.each { |component| puts display(component) }
|
69
|
+
puts blank_line
|
70
|
+
end
|
71
|
+
|
72
|
+
def tests_to_run
|
73
|
+
puts "<<< Test scripts to run >>>" if selected_format?("full")
|
74
|
+
if selected_format?("name")
|
75
|
+
affected.names.each { |component_name| puts component_name }
|
76
|
+
else
|
77
|
+
affected.scripts.each { |component_script| puts component_script }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def display(component)
|
82
|
+
"#{component.name} - #{component.packages.map(&:key).map(&:to_s).map(&:capitalize).join(' & ')}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def blank_line
|
86
|
+
""
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CobraCommander
|
4
|
+
class CLI
|
5
|
+
module Output
|
6
|
+
# Generates graphs of components
|
7
|
+
module DotGraph
|
8
|
+
def self.generate(components, output)
|
9
|
+
output << "digraph G {\n"
|
10
|
+
[*components, *components.flat_map(&:deep_dependencies)].uniq.each do |comp|
|
11
|
+
output << "\t#{comp.name};\n"
|
12
|
+
comp.dependencies.each do |dep|
|
13
|
+
output << "\t#{comp.name} -> #{dep.name};\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
output << "}\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|