repo_analyzer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +103 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.editorconfig +24 -0
  5. data/.gitignore +9 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +505 -0
  8. data/.ruby-version +1 -0
  9. data/CHANGELOG.md +7 -0
  10. data/Gemfile +12 -0
  11. data/Gemfile.lock +320 -0
  12. data/Guardfile +12 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +165 -0
  15. data/Rakefile +10 -0
  16. data/app/assets/config/repo_analyzer_manifest.js +1 -0
  17. data/app/assets/images/repo_analyzer/.keep +0 -0
  18. data/app/assets/stylesheets/repo_analyzer/application.css +15 -0
  19. data/app/clients/repo_analyzer/github_client.rb +31 -0
  20. data/app/controllers/repo_analyzer/application_controller.rb +4 -0
  21. data/app/extractors/repo_analyzer/brakeman_extractor.rb +33 -0
  22. data/app/extractors/repo_analyzer/circleci_extractor.rb +46 -0
  23. data/app/extractors/repo_analyzer/github_extractor.rb +64 -0
  24. data/app/extractors/repo_analyzer/power_types_extractor.rb +21 -0
  25. data/app/extractors/repo_analyzer/project_config_extractor.rb +53 -0
  26. data/app/extractors/repo_analyzer/project_info_extractor.rb +20 -0
  27. data/app/extractors/repo_analyzer/project_versions_extractor.rb +80 -0
  28. data/app/extractors/repo_analyzer/rails_best_practices_extractor.rb +36 -0
  29. data/app/extractors/repo_analyzer/rubocop_extractor.rb +74 -0
  30. data/app/extractors/repo_analyzer/tests_info_extractor.rb +87 -0
  31. data/app/helpers/repo_analyzer/application_helper.rb +4 -0
  32. data/app/jobs/repo_analyzer/application_job.rb +4 -0
  33. data/app/jobs/repo_analyzer/extract_project_info_job.rb +35 -0
  34. data/app/jobs/repo_analyzer/post_extracted_info_job.rb +28 -0
  35. data/app/mailers/repo_analyzer/application_mailer.rb +6 -0
  36. data/app/models/repo_analyzer/application_record.rb +5 -0
  37. data/app/utils/output_utils.rb +10 -0
  38. data/app/values/repo_analyzer/project_data_bridge.rb +48 -0
  39. data/app/views/layouts/repo_analyzer/application.html.erb +15 -0
  40. data/bin/rails +25 -0
  41. data/config/routes.rb +2 -0
  42. data/lib/generators/repo_analyzer/install/USAGE +5 -0
  43. data/lib/generators/repo_analyzer/install/install_generator.rb +19 -0
  44. data/lib/generators/repo_analyzer/install/templates/initializer.rb +2 -0
  45. data/lib/repo_analyzer/engine.rb +15 -0
  46. data/lib/repo_analyzer/example_class.rb +7 -0
  47. data/lib/repo_analyzer/version.rb +3 -0
  48. data/lib/repo_analyzer.rb +48 -0
  49. data/lib/tasks/repo_analyzer_tasks.rake +7 -0
  50. data/repo_analyzer.gemspec +42 -0
  51. data/spec/assets/test_project/README.md +1 -0
  52. data/spec/assets/test_project/app/commands/some_comand.rb +0 -0
  53. data/spec/assets/test_project/app/javascript/src/component.spec.js +0 -0
  54. data/spec/assets/test_project/app/javascript/src/components/component.spec.js +0 -0
  55. data/spec/assets/test_project/app/observers/some_observer.rb +0 -0
  56. data/spec/assets/test_project/old_circleci_config.yml +21 -0
  57. data/spec/assets/test_project/spec/commands/command1_spec.rb +0 -0
  58. data/spec/assets/test_project/spec/commands/command2_spec.rb +0 -0
  59. data/spec/assets/test_project/spec/integration/integration1_spec.rb +0 -0
  60. data/spec/assets/test_project/spec/system/system_test_spec.rb +0 -0
  61. data/spec/assets/test_project/valid_circleci_config.yml +152 -0
  62. data/spec/assets/test_project/valid_gem_gemfile_lock +14 -0
  63. data/spec/assets/test_project/valid_gemfile_lock +684 -0
  64. data/spec/assets/test_project/valid_makefile +35 -0
  65. data/spec/assets/test_project/valid_package_json +84 -0
  66. data/spec/assets/test_project/valid_package_json_without_vue +74 -0
  67. data/spec/assets/test_project/valid_rubocop_rules.yml +54 -0
  68. data/spec/dummy/Rakefile +6 -0
  69. data/spec/dummy/app/assets/config/manifest.js +3 -0
  70. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  71. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  72. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  73. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  74. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  75. data/spec/dummy/app/javascript/packs/application.js +15 -0
  76. data/spec/dummy/app/jobs/application_job.rb +7 -0
  77. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  78. data/spec/dummy/app/models/application_record.rb +3 -0
  79. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  80. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  81. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  82. data/spec/dummy/bin/rails +4 -0
  83. data/spec/dummy/bin/rake +4 -0
  84. data/spec/dummy/bin/setup +33 -0
  85. data/spec/dummy/config/application.rb +38 -0
  86. data/spec/dummy/config/boot.rb +5 -0
  87. data/spec/dummy/config/cable.yml +10 -0
  88. data/spec/dummy/config/database.yml +25 -0
  89. data/spec/dummy/config/environment.rb +5 -0
  90. data/spec/dummy/config/environments/development.rb +81 -0
  91. data/spec/dummy/config/environments/production.rb +120 -0
  92. data/spec/dummy/config/environments/test.rb +59 -0
  93. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  94. data/spec/dummy/config/initializers/assets.rb +12 -0
  95. data/spec/dummy/config/initializers/backtrace_silencers.rb +8 -0
  96. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  97. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  98. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  99. data/spec/dummy/config/initializers/inflections.rb +16 -0
  100. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  101. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  102. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  103. data/spec/dummy/config/locales/en.yml +33 -0
  104. data/spec/dummy/config/puma.rb +43 -0
  105. data/spec/dummy/config/routes.rb +3 -0
  106. data/spec/dummy/config/storage.yml +34 -0
  107. data/spec/dummy/config.ru +6 -0
  108. data/spec/dummy/public/404.html +67 -0
  109. data/spec/dummy/public/422.html +67 -0
  110. data/spec/dummy/public/500.html +66 -0
  111. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  112. data/spec/dummy/public/apple-touch-icon.png +0 -0
  113. data/spec/dummy/public/favicon.ico +0 -0
  114. data/spec/extractors/brakeman_extractor_spec.rb +73 -0
  115. data/spec/extractors/circleci_extractor_spec.rb +45 -0
  116. data/spec/extractors/github_extractor_spec.rb +77 -0
  117. data/spec/extractors/power_types_extractor_spec.rb +18 -0
  118. data/spec/extractors/project_config_extractor_spec.rb +52 -0
  119. data/spec/extractors/project_versions_extractor_spec.rb +63 -0
  120. data/spec/extractors/rails_best_practices_extractor_spec.rb +53 -0
  121. data/spec/extractors/rubocop_extractor_spec.rb +113 -0
  122. data/spec/extractors/tests_info_extractor_spec.rb +65 -0
  123. data/spec/fixtures/files/image.png +0 -0
  124. data/spec/fixtures/files/video.mp4 +0 -0
  125. data/spec/jobs/repo_analyzer/extract_project_info_job_spec.rb +50 -0
  126. data/spec/jobs/repo_analyzer/post_extracted_info_job_spec.rb +52 -0
  127. data/spec/rails_helper.rb +42 -0
  128. data/spec/spec_helper.rb +9 -0
  129. data/spec/support/repo_analyzer_helpers.rb +37 -0
  130. metadata +518 -0
@@ -0,0 +1,73 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::BrakemanExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:file) do
6
+ instance_double(
7
+ "Brakeman::FilePath",
8
+ relative: "app/controllers/api/base_controller.rb"
9
+ )
10
+ end
11
+
12
+ let(:warning) do
13
+ instance_double(
14
+ "Brakeman::Warning",
15
+ warning_type: "Basic Auth",
16
+ check: "Brakeman::CheckBasicAuth",
17
+ message: "Basic authentication password stored in source code",
18
+ file: file,
19
+ link: "https://bla.com",
20
+ line: 14,
21
+ confidence: 0,
22
+ format_code: "where(bla: 1)"
23
+ )
24
+ end
25
+
26
+ let(:warnings) do
27
+ [
28
+ warning
29
+ ]
30
+ end
31
+
32
+ let(:checks) do
33
+ instance_double(
34
+ "Brakeman::Checks",
35
+ warnings: warnings
36
+ )
37
+ end
38
+
39
+ let(:tracker) do
40
+ instance_double(
41
+ "Brakeman::Tracker",
42
+ checks: checks
43
+ )
44
+ end
45
+
46
+ let(:expected) do
47
+ {
48
+ "warning_type" => "Basic Auth",
49
+ "check" => "Brakeman::CheckBasicAuth",
50
+ "message" => "Basic authentication password stored in source code",
51
+ "file_path" => "app/controllers/api/base_controller.rb",
52
+ "link" => "https://bla.com",
53
+ "line" => 14,
54
+ "confidence" => "High",
55
+ "code" => "where(bla: 1)"
56
+ }
57
+ end
58
+
59
+ before do
60
+ allow(Brakeman).to receive(:run).and_return(tracker)
61
+ end
62
+
63
+ it { expect(extract[:brakeman_extractor]["warnings"].first).to eq(expected) }
64
+
65
+ context "without warnings" do
66
+ let(:warnings) do
67
+ []
68
+ end
69
+
70
+ it { expect(extract[:brakeman_extractor]["warnings"].count).to eq(0) }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::CircleciExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:expected) do
6
+ {
7
+ "code_coverage" => true,
8
+ "jest" => true,
9
+ "rspec" => true,
10
+ "system_tests" => true,
11
+ "eslint" => true,
12
+ "rubocop" => true,
13
+ "stylelint" => true,
14
+ "platanus_compose" => false
15
+ }
16
+ end
17
+
18
+ before do
19
+ mock_file_content(".circleci/config.yml", "valid_circleci_config.yml")
20
+ end
21
+
22
+ it { expect(extract).to eq(circleci_extractor: expected) }
23
+
24
+ context "with old config" do
25
+ let(:expected) do
26
+ {
27
+ "code_coverage" => false,
28
+ "jest" => true,
29
+ "rspec" => true,
30
+ "system_tests" => false,
31
+ "eslint" => false,
32
+ "rubocop" => false,
33
+ "stylelint" => false,
34
+ "platanus_compose" => true
35
+ }
36
+ end
37
+
38
+ before do
39
+ mock_file_content(".circleci/config.yml", "old_circleci_config.yml")
40
+ end
41
+
42
+ it { expect(extract).to eq(circleci_extractor: expected) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,77 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::GithubExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:commits) do
6
+ [
7
+ {
8
+ commit: {
9
+ author: {
10
+ date: "1984-04-06"
11
+ }
12
+ },
13
+ author: {
14
+ login: "lean"
15
+ }
16
+ },
17
+ {
18
+ commit: {
19
+ author: {
20
+ date: "1983-03-02"
21
+ }
22
+ },
23
+ author: {
24
+ login: "lean"
25
+ }
26
+ },
27
+ {
28
+ commit: {
29
+ author: {
30
+ date: "1982-03-01"
31
+ }
32
+ },
33
+ author: {
34
+ login: "santi"
35
+ }
36
+ }
37
+ ]
38
+ end
39
+
40
+ let(:contributors) do
41
+ [
42
+ {
43
+ login: "lean",
44
+ avatar_url: "http://lean@github.com",
45
+ contributions: 200
46
+ },
47
+ {
48
+ login: "matias",
49
+ avatar_url: "http://mati@github.com",
50
+ contributions: 100
51
+ },
52
+ {
53
+ login: "santi",
54
+ avatar_url: "http://santi@github.com",
55
+ contributions: 700
56
+ }
57
+ ]
58
+ end
59
+
60
+ before do
61
+ allow(project_data_bridge).to receive(:commits).and_return(commits)
62
+ allow(project_data_bridge).to receive(:contributors).and_return(contributors)
63
+ end
64
+
65
+ def last_contributors_logins
66
+ extract[:github_extractor][:last_contributors].map { |contributor| contributor[:login] }
67
+ end
68
+
69
+ def contributors_logins
70
+ extract[:github_extractor][:contributors].map { |contributor| contributor[:login] }
71
+ end
72
+
73
+ it { expect(extract[:github_extractor][:last_commit_date]).to eq("1984-04-06") }
74
+ it { expect(contributors_logins).to contain_exactly("lean", "matias", "santi") }
75
+ it { expect(last_contributors_logins).to contain_exactly("lean", "santi") }
76
+ end
77
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::PowerTypesExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:expected) do
6
+ {
7
+ "clients" => false,
8
+ "commands" => true,
9
+ "observers" => true,
10
+ "services" => false,
11
+ "utils" => false,
12
+ "values" => false
13
+ }
14
+ end
15
+
16
+ it { expect(extract).to eq(power_types_extractor: expected) }
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::ProjectConfigExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:expected) do
6
+ {
7
+ "simplecov" => false,
8
+ "makefile_commands" => [],
9
+ "rubocop_rules" => []
10
+ }
11
+ end
12
+
13
+ it { expect(extract).to eq(project_config_extractor: expected) }
14
+
15
+ context "with existent config files" do
16
+ let(:expected) do
17
+ {
18
+ "simplecov" => true,
19
+ "makefile_commands" => [
20
+ "backup-production",
21
+ "backup-staging",
22
+ "restore-from-production",
23
+ "restore-from-staging",
24
+ "services-port"
25
+ ],
26
+ "rubocop_rules" => [
27
+ "AllCops",
28
+ "Layout/ParameterAlignment",
29
+ "Lint/StructNewOverride",
30
+ "Metrics/BlockLength",
31
+ "Performance",
32
+ "Performance/RedundantBlockCall",
33
+ "RSpec/MultipleExpectations",
34
+ "Rails",
35
+ "Rails/Delegate",
36
+ "Style/ClassAndModuleChildren",
37
+ "Style/FormatString",
38
+ "Style/FrozenStringLiteralComment"
39
+ ]
40
+ }
41
+ end
42
+
43
+ before do
44
+ mock_file_content("Makefile", "valid_makefile")
45
+ mock_file_content(".rubocop.yml", "valid_rubocop_rules.yml")
46
+ mock_file_existance("spec/simplecov_config.rb")
47
+ end
48
+
49
+ it { expect(extract).to eq(project_config_extractor: expected) }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,63 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::ProjectVersionsExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:expected) do
6
+ {
7
+ "circleci_version" => nil,
8
+ "eslint_version" => nil,
9
+ "node_version" => nil,
10
+ "paperclip_version" => nil,
11
+ "rails_version" => nil,
12
+ "rubocop_version" => nil,
13
+ "shrine_version" => nil,
14
+ "sidekiq_version" => nil,
15
+ "stylelint_version" => nil,
16
+ "tailwind_version" => nil,
17
+ "typescript_version" => nil,
18
+ "vue_router_version" => nil,
19
+ "vue_version" => nil
20
+ }
21
+ end
22
+
23
+ it { expect(extract).to eq(project_versions_extractor: expected) }
24
+
25
+ context "with valid files" do
26
+ let(:expected) do
27
+ {
28
+ "circleci_version" => "2",
29
+ "eslint_version" => "7.29.0",
30
+ "node_version" => "12",
31
+ "paperclip_version" => "5.0.0",
32
+ "rails_version" => "6.0.4",
33
+ "rubocop_version" => "1.18.0",
34
+ "shrine_version" => "3.4.0",
35
+ "sidekiq_version" => "6.2.2",
36
+ "stylelint_version" => "13.13.1",
37
+ "tailwind_version" => "2",
38
+ "typescript_version" => "4.5.5",
39
+ "vue_router_version" => "3.0.7",
40
+ "vue_version" => "2.6.14"
41
+ }
42
+ end
43
+
44
+ before do
45
+ mock_file_content("package.json", "valid_package_json")
46
+ mock_file_content("Gemfile.lock", "valid_gemfile_lock")
47
+ mock_file_content(".circleci/config.yml", "valid_circleci_config.yml")
48
+ end
49
+
50
+ it { expect(extract).to eq(project_versions_extractor: expected) }
51
+ end
52
+
53
+ context "with invalid files" do
54
+ before do
55
+ mock_file_content("package.json", "valid_gem_gemfile_lock")
56
+ mock_file_content("Gemfile.lock", "valid_gem_gemfile_lock")
57
+ mock_file_content(".circleci/config.yml", "valid_gem_gemfile_lock")
58
+ end
59
+
60
+ it { expect(extract).to eq(project_versions_extractor: expected) }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,53 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::RailsBestPracticesExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:error) do
6
+ instance_double(
7
+ "RailsBestPractices::Core::Error",
8
+ filename: "spec/assets/test_project/app/controllers/team_controller.rb",
9
+ line_number: "4",
10
+ message: "move model logic into model (@team use_count > 4)",
11
+ type: "RailsBestPractices::Reviews::MoveModelLogicIntoModelReview",
12
+ url: "https://rails-bestpractices.com/posts/2010/07/21/move-model-logic-into-the-model/"
13
+ )
14
+ end
15
+
16
+ let(:errors) do
17
+ [
18
+ error
19
+ ]
20
+ end
21
+
22
+ let(:analyzer) do
23
+ instance_double(
24
+ "RailsBestPractices::Analyzer",
25
+ analyze: true,
26
+ errors: errors
27
+ )
28
+ end
29
+
30
+ let(:expected) do
31
+ {
32
+ "file_path" => "app/controllers/team_controller.rb:4",
33
+ "message" => "move model logic into model (@team use_count > 4)",
34
+ "type" => "Reviews::MoveModelLogicIntoModelReview",
35
+ "url" => "https://rails-bestpractices.com/posts/2010/07/21/move-model-logic-into-the-model/"
36
+ }
37
+ end
38
+
39
+ before do
40
+ allow(RailsBestPractices::Analyzer).to receive(:new).and_return(analyzer)
41
+ end
42
+
43
+ it { expect(extract[:rails_best_practices_extractor]["errors"].first).to eq(expected) }
44
+
45
+ context "without errors" do
46
+ let(:errors) do
47
+ []
48
+ end
49
+
50
+ it { expect(extract[:rails_best_practices_extractor]["errors"].count).to eq(0) }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,113 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::RubocopExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:rubocop_result_content) do
6
+ {
7
+ "files" => [
8
+ {
9
+ "path" => "file1.rb",
10
+ "offenses" => [
11
+ {
12
+ "cop_name" => "Lint/UnderscorePrefixedVariableName",
13
+ "message" => "m1",
14
+ "severity" => "warning",
15
+ "location" => {
16
+ "line" => 78,
17
+ "column" => 33
18
+ }
19
+ },
20
+ {
21
+ "cop_name" => "Lint/UnderscorePrefixedVariableName",
22
+ "message" => "m2",
23
+ "severity" => "warning",
24
+ "location" => {
25
+ "line" => 22,
26
+ "column" => 1
27
+ }
28
+ }
29
+ ]
30
+ },
31
+ {
32
+ "path" => "file2.rb",
33
+ "offenses" => [
34
+ {
35
+ "cop_name" => "Lint/UnderscorePrefixedVariableName",
36
+ "message" => "m3",
37
+ "severity" => "warning",
38
+ "location" => {
39
+ "line" => 60,
40
+ "column" => 2
41
+ }
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "path" => "file3.rb",
47
+ "offenses" => [
48
+ {
49
+ "cop_name" => "Style/FrozenStringLiteralComment",
50
+ "message" => "Style/FrozenStringLiteralComment: m4",
51
+ "severity" => "convention",
52
+ "location" => {
53
+ "line" => 66,
54
+ "column" => 4
55
+ }
56
+ }
57
+ ]
58
+ }
59
+ ]
60
+ }.to_json
61
+ end
62
+
63
+ let(:runner) do
64
+ instance_double(
65
+ "RuboCop::Runner",
66
+ run: rubocop_result_content
67
+ )
68
+ end
69
+
70
+ let(:expected) do
71
+ {
72
+ "convention" => {
73
+ "Style/FrozenStringLiteralComment" => [
74
+ {
75
+ "message" => "m4",
76
+ "path" => "file3.rb:66:4"
77
+ }
78
+ ]
79
+ },
80
+ "warning" => {
81
+ "Lint/UnderscorePrefixedVariableName" => [
82
+ {
83
+ "message" => "m1",
84
+ "path" => "file1.rb:78:33"
85
+ },
86
+ {
87
+ "message" => "m2",
88
+ "path" => "file1.rb:22:1"
89
+ }, {
90
+ "message" => "m3",
91
+ "path" => "file2.rb:60:2"
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ end
97
+
98
+ before do
99
+ allow(RuboCop::Runner).to receive(:new).and_return(runner)
100
+ allow(OutputUtils).to receive(:with_captured_stdout).and_return(rubocop_result_content)
101
+ end
102
+
103
+ it { expect(extract[:rubocop_extractor]["offenses"]).to eq(expected) }
104
+
105
+ context "with rubocop errors" do
106
+ before do
107
+ allow(RuboCop::Runner).to receive(:new).and_raise(RuboCop::Error)
108
+ end
109
+
110
+ it { expect(extract[:rubocop_extractor]["offenses"]).to eq({}) }
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,65 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::TestsInfoExtractor, repo_analyzer_extractor_helpers: true do
4
+ describe "#extract" do
5
+ let(:expected) do
6
+ {
7
+ "swagger_tests_count" => 1,
8
+ "system_tests_count" => 1,
9
+ "jest_tests_count" => 2,
10
+ "rails_code_coverage" => {
11
+ "controllers" => {
12
+ "files_count" => 0,
13
+ "tests_count" => 0
14
+ },
15
+ "mailers" => {
16
+ "files_count" => 0,
17
+ "tests_count" => 0
18
+ },
19
+ "models" => {
20
+ "files_count" => 0,
21
+ "tests_count" => 0
22
+ },
23
+ "jobs" => {
24
+ "files_count" => 0,
25
+ "tests_count" => 0
26
+ },
27
+ "policies" => {
28
+ "files_count" => 0,
29
+ "tests_count" => 0
30
+ },
31
+ "commands" => {
32
+ "files_count" => 1,
33
+ "tests_count" => 2
34
+ },
35
+ "services" => {
36
+ "files_count" => 0,
37
+ "tests_count" => 0
38
+ },
39
+ "observers" => {
40
+ "files_count" => 1,
41
+ "tests_count" => 0
42
+ },
43
+ "values" => {
44
+ "files_count" => 0,
45
+ "tests_count" => 0
46
+ },
47
+ "utils" => {
48
+ "files_count" => 0,
49
+ "tests_count" => 0
50
+ },
51
+ "clients" => {
52
+ "files_count" => 0,
53
+ "tests_count" => 0
54
+ },
55
+ "total" => {
56
+ "files_count" => 2,
57
+ "tests_count" => 2
58
+ }
59
+ }
60
+ }
61
+ end
62
+
63
+ it { expect(extract).to eq(tests_info_extractor: expected) }
64
+ end
65
+ end
Binary file
Binary file
@@ -0,0 +1,50 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::ExtractProjectInfoJob, type: :job do
4
+ let(:repo_name) { "platanus/alisur-formulator" }
5
+
6
+ let(:files_list) do
7
+ "app/extractors/repo_analyzer/project_versions_extractor.rb"
8
+ end
9
+
10
+ let(:bridge) do
11
+ instance_double(
12
+ "RepoAnalyzer::ProjectDataBridge"
13
+ )
14
+ end
15
+
16
+ let(:extracted_data) do
17
+ {
18
+ project_versions_extractor: {
19
+ rails_version: "6.0"
20
+ }
21
+ }
22
+ end
23
+
24
+ let(:extractor) do
25
+ instance_double(
26
+ "RepoAnalyzer::ProjectVersionsExtractor",
27
+ extract: extracted_data
28
+ )
29
+ end
30
+
31
+ let(:engine_root) { instance_double("Pathname", join: files_list) }
32
+
33
+ def perform_now
34
+ described_class.perform_now(repo_name)
35
+ end
36
+
37
+ before do
38
+ allow(RepoAnalyzer::Engine).to receive(:root).and_return(engine_root)
39
+ allow(RepoAnalyzer::ProjectDataBridge).to receive(:new).and_return(bridge)
40
+ allow(RepoAnalyzer::ProjectVersionsExtractor).to receive(:new).and_return(extractor)
41
+ end
42
+
43
+ it { expect(perform_now).to eq(extracted_data) }
44
+
45
+ it do
46
+ perform_now
47
+ expect(RepoAnalyzer::ProjectDataBridge).to have_received(:new).with(repo_name).once
48
+ expect(RepoAnalyzer::ProjectVersionsExtractor).to have_received(:new).with(bridge).once
49
+ end
50
+ end
@@ -0,0 +1,52 @@
1
+ require 'rails_helper'
2
+
3
+ describe RepoAnalyzer::PostExtractedInfoJob, type: :job do
4
+ let(:project_info) do
5
+ {
6
+ "extracted" => "info"
7
+ }
8
+ end
9
+
10
+ let(:condition_result) { double }
11
+
12
+ let(:response) do
13
+ instance_double(
14
+ "Net::HTTPCreated",
15
+ is_a?: condition_result
16
+ )
17
+ end
18
+
19
+ let(:repo_name) { "hay-gas" }
20
+
21
+ let(:expected_post_data) do
22
+ {
23
+ repo_name: repo_name,
24
+ project_info: "eJyrVkqtKClKTC5JTVGyUsrMS8tXqgUATWwHKw==\n"
25
+ }.to_json
26
+ end
27
+
28
+ let(:nest_url) do
29
+ "https://platan.us/api/v1/repo_analyzer/project_info"
30
+ end
31
+
32
+ def perform_now
33
+ described_class.perform_now(repo_name, project_info)
34
+ end
35
+
36
+ before do
37
+ allow(Net::HTTP).to receive(:post).and_return(response)
38
+ allow(ENV).to receive(:[])
39
+ .with("REPO_ANALYZER_URL")
40
+ .and_return(nest_url)
41
+ end
42
+
43
+ it do
44
+ expect(perform_now).to eq(condition_result)
45
+ expect(Net::HTTP).to have_received(:post).with(
46
+ URI(nest_url),
47
+ expected_post_data,
48
+ "Content-Type" => "application/json"
49
+ ).once
50
+ expect(response).to have_received(:is_a?).with(Net::HTTPCreated).once
51
+ end
52
+ end