calcifer 0.1.1 → 0.4.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: b0c1bdeaf9f49017bb6f2aff22d00c18f7bb68557214065f9ace1eba6c5d2751
4
- data.tar.gz: 0f7feb93dfceeb89a75c507111e283d846f71e1c025e520333511a320b1c33b0
3
+ metadata.gz: c7d116a75730c531b8425c3358f6988fd46c3cf480fa73e6fea53a783ae9db4e
4
+ data.tar.gz: bcd079c57f89dcdedac1c6d3f43d656a09dff5b14a058b6655a218c76ab6a97e
5
5
  SHA512:
6
- metadata.gz: a7f917e7934082a97c5b230dd6b41003cfcd7da2f8e13657dd705bf868497f538c28b27073af41c8fb05cb274d49c60ad669ff3a95e6d5615423fc861ee5ec20
7
- data.tar.gz: a81969f58b5f626d64119bff0f938d11e7d2c1a98d1d759991f54c3b60af205dd63f75013ab9791f7fa49c476ccc194d3e57920924a81ac941d1a8016ae564ef
6
+ metadata.gz: e12138c209b2a7a49aced35daa7c9f181d0b7668a6066a3a565135480781ff1c12ffe6157d35201f0e9892f97fbe9bc4c756ab41a88a0cfaf992578c6fbe67a6
7
+ data.tar.gz: 6f2b9e7ca8fe6392804f9a641559ce4df4998734f81bf3b8cd227172860a4486dd222e2d8f6dea67d85cd3d518b49d72e7323db351927e084193efd4b16cf46a
@@ -0,0 +1,41 @@
1
+ # This is a basic workflow to help you get started with Actions
2
+
3
+ name: CI
4
+
5
+ # Controls when the workflow will run
6
+ on:
7
+ # Triggers the workflow on push or pull request events but only for the main branch
8
+ push:
9
+ branches: [ main ]
10
+ pull_request:
11
+ branches: [ main ]
12
+
13
+ # A workflow run is made up of one or more jobs that can run sequentially or in parallel
14
+ jobs:
15
+ # This workflow contains a single job called "build"
16
+ build:
17
+ # The type of runner that the job will run on
18
+ runs-on: ubuntu-latest
19
+
20
+ steps:
21
+ - name: Checkout code
22
+ uses: actions/checkout@v2
23
+
24
+ - name: Setup Ruby and install gems
25
+ uses: actions/setup-ruby@v1
26
+ with:
27
+ ruby-version: 2.6
28
+
29
+ - name: Build env
30
+ run: |
31
+ sudo apt-get -yqq install libpq-dev
32
+ gem install bundler:1.17.0
33
+ bundle install
34
+
35
+ - name: Run Rspec
36
+ run: bundle exec rspec
37
+ - name: Run Rubocop
38
+ run: bundle exec rubocop
39
+
40
+
41
+
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - 'bin/**/*'
5
+ - calcifer.gemspec
6
+ - spec/fixtures/**
7
+
8
+ Metrics/ModuleLength:
9
+ Exclude:
10
+ - spec/**/*.rb
11
+
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - spec/**/*.rb
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Max: 20
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in calcifer.gemspec
6
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,13 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- calcifer (0.1.1)
4
+ calcifer (0.4.0)
5
+ rgl (~> 0.5.7)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ ast (2.4.2)
9
11
  diff-lcs (1.5.0)
12
+ generator (0.0.1)
13
+ lazy_priority_queue (0.1.1)
14
+ parallel (1.21.0)
15
+ parser (3.1.0.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.1.1)
10
18
  rake (10.5.0)
19
+ regexp_parser (2.2.0)
20
+ rexml (3.2.5)
21
+ rgl (0.5.7)
22
+ lazy_priority_queue (~> 0.1.0)
23
+ stream (~> 0.5.3)
11
24
  rspec (3.10.0)
12
25
  rspec-core (~> 3.10.0)
13
26
  rspec-expectations (~> 3.10.0)
@@ -21,6 +34,21 @@ GEM
21
34
  diff-lcs (>= 1.2.0, < 2.0)
22
35
  rspec-support (~> 3.10.0)
23
36
  rspec-support (3.10.3)
37
+ rubocop (1.25.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 3.1.0.0)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8, < 3.0)
42
+ rexml
43
+ rubocop-ast (>= 1.15.1, < 2.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 3.0)
46
+ rubocop-ast (1.15.1)
47
+ parser (>= 3.0.1.1)
48
+ ruby-progressbar (1.11.0)
49
+ stream (0.5.3)
50
+ generator
51
+ unicode-display_width (2.1.0)
24
52
 
25
53
  PLATFORMS
26
54
  ruby
@@ -30,6 +58,7 @@ DEPENDENCIES
30
58
  calcifer!
31
59
  rake (~> 10.0)
32
60
  rspec (~> 3.0)
61
+ rubocop (~> 1.25)
33
62
 
34
63
  BUNDLED WITH
35
64
  1.17.3
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Calcifer
2
+
3
+ Calcifer helps you find test files that are directly related to the files you changed.
2
4
  ## Installation
3
5
 
4
6
  Add this line to your application's Gemfile:
@@ -17,8 +19,14 @@ Or install it yourself as:
17
19
 
18
20
  ## Usage
19
21
 
20
- `bundle exec calcifer | xargs bundle exec rspec`
22
+ To search for related files using uncommitted changes, just do the following
23
+
24
+ $ bundle exec calcifer | xargs bundle exec rspec
25
+
26
+ To search for related files using the other branch changes as a reference, just do the following
27
+
21
28
 
29
+ $ bundle exec calcifer -b 'branch_name' | xargs bundle exec rspec
22
30
  ## Contributing
23
31
 
24
32
  Bug reports and pull requests are welcome on GitHub at https://github.com/GustavoDuarteM/calcifer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/calcifer.gemspec CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/GustavoDuarteM/calcifer"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.required_ruby_version = '>= 2.6.4'
18
+
17
19
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
20
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
21
  if spec.respond_to?(:metadata)
@@ -37,7 +39,10 @@ Gem::Specification.new do |spec|
37
39
  spec.executables = ['calcifer']
38
40
  spec.require_paths = ["lib"]
39
41
 
42
+ spec.add_dependency 'rgl', "~>0.5.7"
43
+
40
44
  spec.add_development_dependency "bundler", "~> 1.17"
41
45
  spec.add_development_dependency "rake", "~> 10.0"
42
46
  spec.add_development_dependency "rspec", "~> 3.0"
47
+ spec.add_development_dependency "rubocop", "~> 1.25"
43
48
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Buiders
5
+ class RootFileBuilder
6
+ def initialize(file)
7
+ @file = file
8
+ end
9
+
10
+ def build
11
+ return unless @file
12
+
13
+ module_name = Calcifer::Finders::ModuleNameFinder.new(@file).execute
14
+ Calcifer::Graph::RootFile.new(module_name, @file) if module_name
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Factories
5
+ class ListFileFactory
6
+ PARAM_BRANCH = ['-b', '-branch'].freeze
7
+
8
+ def initialize(params)
9
+ @params = params
10
+ end
11
+
12
+ def fabricate
13
+ extract_parameters
14
+
15
+ return Calcifer::Finders::FilesDiffFinder.new if @branch.nil?
16
+
17
+ Calcifer::Finders::FilesBranchDiffFinder.new(@branch)
18
+ end
19
+
20
+ private
21
+
22
+ def extract_parameters
23
+ params_list.each do |param|
24
+ param_branch(param)
25
+ end
26
+ end
27
+
28
+ def params_list
29
+ @params_list = []
30
+ (0..@params.length - 1).step(2) do |num|
31
+ range = 2 + num
32
+ @params_list << @params[num..range]
33
+ end
34
+
35
+ @params_list
36
+ end
37
+
38
+ def param_branch(array_param)
39
+ param, value = array_param
40
+
41
+ return unless PARAM_BRANCH.include?(param)
42
+
43
+ @branch = value
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Finders
5
+ class FileRelatedFinder
6
+ attr_reader :related_spec_files
7
+
8
+ def initialize(module_name)
9
+ @module_name = module_name
10
+ end
11
+
12
+ def execute
13
+ related_files_path.split
14
+ end
15
+
16
+ private
17
+
18
+ def related_files_path
19
+ `grep -Rlw '#{@module_names}' ./app`
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Finders
5
+ class FilesBranchDiffFinder
6
+ def initialize(branch)
7
+ @branch = branch
8
+ end
9
+
10
+ def execute
11
+ @file_list = git_files.split.map(&lambda { |file_path|
12
+ file = File.open(file_path)
13
+ file if file.size.positive? && File.extname(file.path) == '.rb'
14
+ }).compact
15
+ end
16
+
17
+ def git_files
18
+ `git diff --name-only #{@branch}...`
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Finders
5
+ class ModuleNameFinder
6
+ MODULE_REGEX = /^(module)\s\w+/.freeze
7
+ CLASS_REGEX = /^(class)\s\w+/.freeze
8
+ ONE_LINE_CLASS_REGEX = /^(class)\s\w+\s<\s\w+;\s(end)/.freeze
9
+ attr_reader :modules
10
+
11
+ def initialize(file)
12
+ @file = file
13
+ @module_name = []
14
+ end
15
+
16
+ def execute
17
+ return unless @file
18
+
19
+ @file.readlines.each do |line|
20
+ next if one_line_class_definition?(line)
21
+
22
+ if module_definition?(line)
23
+ @module_name << line.gsub('module', '').strip
24
+ elsif class_definition?(line)
25
+ @module_name << line.gsub('class', '').gsub(/<(.*)/, '').strip
26
+ break
27
+ end
28
+ end
29
+
30
+ mount_module_name
31
+ end
32
+
33
+ private
34
+
35
+ def one_line_class_definition?(line)
36
+ line.strip.match(ONE_LINE_CLASS_REGEX)&.length&.positive?
37
+ end
38
+
39
+ def module_definition?(line)
40
+ line.strip.match(MODULE_REGEX)&.length&.positive?
41
+ end
42
+
43
+ def class_definition?(line)
44
+ line.strip.match(CLASS_REGEX)&.length&.positive?
45
+ end
46
+
47
+ def mount_module_name
48
+ return unless @module_name.length.positive?
49
+
50
+ @module_name.join('::')
51
+ end
52
+ end
53
+ end
54
+ end
@@ -5,25 +5,19 @@ module Calcifer
5
5
  class SpecFilesRelatedFinder
6
6
  attr_reader :related_spec_files
7
7
 
8
- def initialize(modules)
9
- @modules = modules
8
+ def initialize(related_files_path)
9
+ @related_files_path = related_files_path
10
10
  end
11
11
 
12
12
  def execute
13
13
  @related_spec_files = specs_to_related_files.join(' ').strip
14
14
  end
15
15
 
16
- private
17
-
18
- def related_files_path
19
- module_names = @modules.join('\\|')
20
- `grep -Rlw '#{module_names}' ./app`
21
- end
22
-
23
16
  def specs_to_related_files
24
- related_files_path.split.map(&lambda { |file_path|
25
- file_path.gsub('./app', './spec').gsub('.rb', '_spec.rb')
26
- }).select { |file_path_spec| File.file?(file_path_spec) }
17
+ @related_files_path.map(&lambda { |file_path|
18
+ spec_file_path = file_path.gsub('./app', './spec').gsub('.rb', '_spec.rb')
19
+ File.file?(spec_file_path) ? spec_file_path : nil
20
+ }).compact
27
21
  end
28
22
  end
29
23
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Graph
5
+ class GraphListFile
6
+ def initialize(file_list)
7
+ @file_list = file_list
8
+ end
9
+
10
+ def execute
11
+ graph_list_file = @file_list.map(&->(file) { Calcifer::Buiders::RootFileBuilder.new(file).build }).compact
12
+
13
+ graph_list_file.each do |graph|
14
+ related_files = Calcifer::Finders::FileRelatedFinder.new(graph.module_name).execute
15
+ graph_vertices = related_files.map { |related_file| [graph.file_path, related_file] }
16
+ graph.graph_root.add_edges(*graph_vertices)
17
+ end
18
+
19
+ graph_list_file
20
+ end
21
+
22
+ def file_list
23
+ Calcifer::Finders::FilesDiffFinder.new.execute
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calcifer
4
+ module Graph
5
+ class RootFile
6
+ attr :graph_root, :module_name, :file_path
7
+
8
+ def initialize(module_name, file)
9
+ @module_name = module_name
10
+ @file = file
11
+ @file_path = file.path
12
+ build_graph_root
13
+ end
14
+
15
+ def add_related_file_path(file_path)
16
+ @graph_root.add_edge(@file.path, file_path)
17
+ end
18
+
19
+ def related_files_paths
20
+ @graph_root.vertices - [@file.path]
21
+ end
22
+
23
+ private
24
+
25
+ def build_graph_root
26
+ @graph_root = RGL::DirectedAdjacencyGraph.new
27
+ @graph_root.add_vertex(@file.path)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Calcifer
2
- VERSION = "0.1.1"
4
+ VERSION = '0.4.0'
3
5
  end
data/lib/calcifer.rb CHANGED
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'calcifer/version'
4
- require 'calcifer/finders/modules_finder'
5
- require 'calcifer/finders/files_diff_finder'
6
- require 'calcifer/finders/spec_files_related_finder'
3
+ Dir["#{File.dirname(__FILE__)}/calcifer/**/*.rb"].sort.each { |file| require file }
4
+ require 'rgl/adjacency'
7
5
 
8
6
  module Calcifer
9
7
  class Error < StandardError; end
8
+ class << self
9
+ def execute
10
+ file_list_finder = Calcifer::Factories::ListFileFactory.new(ARGV).fabricate
11
+ file_list = file_list_finder.execute
12
+ graph_list_file = Calcifer::Graph::GraphListFile.new(file_list).execute
13
+ spec_files_path = graph_list_file.map(&:related_files_paths).flatten
14
+ spec_files_path_list = Calcifer::Finders::SpecFilesRelatedFinder.new(spec_files_path).execute
10
15
 
11
- def self.execute
12
- file_list = Calcifer::Finders::FilesDiffFinder.new.execute
13
- module_list = Calcifer::Finders::ModulesFinder.new(file_list).execute
14
- spec_files_path_list = Calcifer::Finders::SpecFilesRelatedFinder.new(module_list).execute
15
-
16
- printf %x[echo #{spec_files_path_list}]
16
+ printf `echo #{spec_files_path_list}`
17
+ end
17
18
  end
18
19
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calcifer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Duarte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-29 00:00:00.000000000 Z
11
+ date: 2022-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rgl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.7
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.25'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.25'
55
83
  description:
56
84
  email:
57
85
  - gustavo_dmuniz@yahoo.com.br
@@ -60,8 +88,10 @@ executables:
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
91
+ - ".github/workflows/main.yml"
63
92
  - ".gitignore"
64
93
  - ".rspec"
94
+ - ".rubocop.yml"
65
95
  - ".travis.yml"
66
96
  - CODE_OF_CONDUCT.md
67
97
  - Gemfile
@@ -74,9 +104,15 @@ files:
74
104
  - bin/setup
75
105
  - calcifer.gemspec
76
106
  - lib/calcifer.rb
107
+ - lib/calcifer/builders/root_file_builder.rb
108
+ - lib/calcifer/factories/list_file_factory.rb
109
+ - lib/calcifer/finders/file_related_finder.rb
110
+ - lib/calcifer/finders/files_branch_diff_finder.rb
77
111
  - lib/calcifer/finders/files_diff_finder.rb
78
- - lib/calcifer/finders/modules_finder.rb
112
+ - lib/calcifer/finders/module_name_finder.rb
79
113
  - lib/calcifer/finders/spec_files_related_finder.rb
114
+ - lib/calcifer/graph/graph_list_file.rb
115
+ - lib/calcifer/graph/root_file.rb
80
116
  - lib/calcifer/version.rb
81
117
  homepage: https://github.com/GustavoDuarteM/calcifer
82
118
  licenses:
@@ -92,14 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
128
  requirements:
93
129
  - - ">="
94
130
  - !ruby/object:Gem::Version
95
- version: '0'
131
+ version: 2.6.4
96
132
  required_rubygems_version: !ruby/object:Gem::Requirement
97
133
  requirements:
98
134
  - - ">="
99
135
  - !ruby/object:Gem::Version
100
136
  version: '0'
101
137
  requirements: []
102
- rubygems_version: 3.0.8
138
+ rubygems_version: 3.1.6
103
139
  signing_key:
104
140
  specification_version: 4
105
141
  summary: This gem helps to find class test files related to pending changes in git.
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Calcifer
4
- module Finders
5
- class ModulesFinder
6
- MODULE_REGEX = /^(module)\s\w+/.freeze
7
- CLASS_REGEX = /^(class)\s\w+/.freeze
8
- attr_reader :modules
9
-
10
- def initialize(file_list)
11
- @file_list = file_list
12
- @modules = []
13
- end
14
-
15
- def execute
16
- @file_list.each do |file|
17
- module_name = build_module_name(file)
18
- @modules << module_name if module_name.length.positive?
19
- end
20
- @modules
21
- end
22
-
23
- private
24
-
25
- def build_module_name(file)
26
- # TODO add clause to one line defnition as "class Error < StandardError; end"
27
- module_name = ''
28
- file.readlines.each do |line|
29
- if line.strip.match(MODULE_REGEX)&.length&.positive?
30
- module_name += "#{line.gsub('module', '').strip}::"
31
- elsif line.strip.match(CLASS_REGEX)&.length&.positive?
32
- module_name += line.gsub('class', '').gsub(/<(.*)/, '').strip
33
- break
34
- end
35
- end
36
- module_name
37
- end
38
- end
39
- end
40
- end