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
data/Gemfile.lock ADDED
@@ -0,0 +1,320 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ repo_analyzer (1.0.0)
5
+ brakeman
6
+ octokit (~> 4.0)
7
+ rails (>= 6.0)
8
+ rails_best_practices
9
+ rubocop (~> 1.9)
10
+ rubocop-performance
11
+ rubocop-platanus (~> 0.2)
12
+ rubocop-rails
13
+ rubocop-rspec (~> 2.2)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ actioncable (6.1.7)
19
+ actionpack (= 6.1.7)
20
+ activesupport (= 6.1.7)
21
+ nio4r (~> 2.0)
22
+ websocket-driver (>= 0.6.1)
23
+ actionmailbox (6.1.7)
24
+ actionpack (= 6.1.7)
25
+ activejob (= 6.1.7)
26
+ activerecord (= 6.1.7)
27
+ activestorage (= 6.1.7)
28
+ activesupport (= 6.1.7)
29
+ mail (>= 2.7.1)
30
+ actionmailer (6.1.7)
31
+ actionpack (= 6.1.7)
32
+ actionview (= 6.1.7)
33
+ activejob (= 6.1.7)
34
+ activesupport (= 6.1.7)
35
+ mail (~> 2.5, >= 2.5.4)
36
+ rails-dom-testing (~> 2.0)
37
+ actionpack (6.1.7)
38
+ actionview (= 6.1.7)
39
+ activesupport (= 6.1.7)
40
+ rack (~> 2.0, >= 2.0.9)
41
+ rack-test (>= 0.6.3)
42
+ rails-dom-testing (~> 2.0)
43
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
+ actiontext (6.1.7)
45
+ actionpack (= 6.1.7)
46
+ activerecord (= 6.1.7)
47
+ activestorage (= 6.1.7)
48
+ activesupport (= 6.1.7)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (6.1.7)
51
+ activesupport (= 6.1.7)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (6.1.7)
57
+ activesupport (= 6.1.7)
58
+ globalid (>= 0.3.6)
59
+ activemodel (6.1.7)
60
+ activesupport (= 6.1.7)
61
+ activerecord (6.1.7)
62
+ activemodel (= 6.1.7)
63
+ activesupport (= 6.1.7)
64
+ activestorage (6.1.7)
65
+ actionpack (= 6.1.7)
66
+ activejob (= 6.1.7)
67
+ activerecord (= 6.1.7)
68
+ activesupport (= 6.1.7)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (6.1.7)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ zeitwerk (~> 2.3)
77
+ addressable (2.8.1)
78
+ public_suffix (>= 2.0.2, < 6.0)
79
+ ast (2.4.2)
80
+ brakeman (5.3.1)
81
+ builder (3.2.4)
82
+ code_analyzer (0.5.5)
83
+ sexp_processor
84
+ coderay (1.1.3)
85
+ concurrent-ruby (1.1.10)
86
+ coveralls (0.8.23)
87
+ json (>= 1.8, < 3)
88
+ simplecov (~> 0.16.1)
89
+ term-ansicolor (~> 1.3)
90
+ thor (>= 0.19.4, < 2.0)
91
+ tins (~> 1.6)
92
+ crass (1.0.6)
93
+ date (3.3.1)
94
+ diff-lcs (1.5.0)
95
+ docile (1.4.0)
96
+ erubi (1.11.0)
97
+ erubis (2.7.0)
98
+ factory_bot (6.2.1)
99
+ activesupport (>= 5.0.0)
100
+ factory_bot_rails (6.2.0)
101
+ factory_bot (~> 6.2.0)
102
+ railties (>= 5.0.0)
103
+ faraday (2.7.1)
104
+ faraday-net_http (>= 2.0, < 3.1)
105
+ ruby2_keywords (>= 0.0.4)
106
+ faraday-net_http (3.0.2)
107
+ ffi (1.15.5)
108
+ formatador (1.1.0)
109
+ globalid (1.0.0)
110
+ activesupport (>= 5.0)
111
+ guard (2.18.0)
112
+ formatador (>= 0.2.4)
113
+ listen (>= 2.7, < 4.0)
114
+ lumberjack (>= 1.0.12, < 2.0)
115
+ nenv (~> 0.1)
116
+ notiffany (~> 0.0)
117
+ pry (>= 0.13.0)
118
+ shellany (~> 0.0)
119
+ thor (>= 0.18.1)
120
+ guard-compat (1.2.1)
121
+ guard-rspec (4.7.3)
122
+ guard (~> 2.1)
123
+ guard-compat (~> 1.1)
124
+ rspec (>= 2.99.0, < 4.0)
125
+ i18n (1.12.0)
126
+ concurrent-ruby (~> 1.0)
127
+ json (2.6.3)
128
+ listen (3.7.1)
129
+ rb-fsevent (~> 0.10, >= 0.10.3)
130
+ rb-inotify (~> 0.9, >= 0.9.10)
131
+ loofah (2.19.0)
132
+ crass (~> 1.0.2)
133
+ nokogiri (>= 1.5.9)
134
+ lumberjack (1.2.8)
135
+ mail (2.8.0)
136
+ mini_mime (>= 0.1.1)
137
+ net-imap
138
+ net-pop
139
+ net-smtp
140
+ marcel (1.0.2)
141
+ method_source (1.0.0)
142
+ mini_mime (1.1.2)
143
+ minitest (5.16.3)
144
+ nenv (0.3.0)
145
+ net-imap (0.3.2)
146
+ date
147
+ net-protocol
148
+ net-pop (0.1.2)
149
+ net-protocol
150
+ net-protocol (0.2.1)
151
+ timeout
152
+ net-smtp (0.3.3)
153
+ net-protocol
154
+ nio4r (2.5.8)
155
+ nokogiri (1.13.10-x86_64-darwin)
156
+ racc (~> 1.4)
157
+ nokogiri (1.13.10-x86_64-linux)
158
+ racc (~> 1.4)
159
+ notiffany (0.1.3)
160
+ nenv (~> 0.1)
161
+ shellany (~> 0.0)
162
+ octokit (4.25.1)
163
+ faraday (>= 1, < 3)
164
+ sawyer (~> 0.9)
165
+ parallel (1.22.1)
166
+ parser (3.1.3.0)
167
+ ast (~> 2.4.1)
168
+ pry (0.14.1)
169
+ coderay (~> 1.1)
170
+ method_source (~> 1.0)
171
+ pry-rails (0.3.9)
172
+ pry (>= 0.10.4)
173
+ public_suffix (5.0.1)
174
+ racc (1.6.1)
175
+ rack (2.2.4)
176
+ rack-test (2.0.2)
177
+ rack (>= 1.3)
178
+ rails (6.1.7)
179
+ actioncable (= 6.1.7)
180
+ actionmailbox (= 6.1.7)
181
+ actionmailer (= 6.1.7)
182
+ actionpack (= 6.1.7)
183
+ actiontext (= 6.1.7)
184
+ actionview (= 6.1.7)
185
+ activejob (= 6.1.7)
186
+ activemodel (= 6.1.7)
187
+ activerecord (= 6.1.7)
188
+ activestorage (= 6.1.7)
189
+ activesupport (= 6.1.7)
190
+ bundler (>= 1.15.0)
191
+ railties (= 6.1.7)
192
+ sprockets-rails (>= 2.0.0)
193
+ rails-dom-testing (2.0.3)
194
+ activesupport (>= 4.2.0)
195
+ nokogiri (>= 1.6)
196
+ rails-html-sanitizer (1.4.3)
197
+ loofah (~> 2.3)
198
+ rails_best_practices (1.23.2)
199
+ activesupport
200
+ code_analyzer (~> 0.5.5)
201
+ erubis
202
+ i18n
203
+ json
204
+ require_all (~> 3.0)
205
+ ruby-progressbar
206
+ railties (6.1.7)
207
+ actionpack (= 6.1.7)
208
+ activesupport (= 6.1.7)
209
+ method_source
210
+ rake (>= 12.2)
211
+ thor (~> 1.0)
212
+ rainbow (3.1.1)
213
+ rake (13.0.6)
214
+ rb-fsevent (0.11.2)
215
+ rb-inotify (0.10.1)
216
+ ffi (~> 1.0)
217
+ regexp_parser (2.6.1)
218
+ require_all (3.0.0)
219
+ rexml (3.2.5)
220
+ rspec (3.12.0)
221
+ rspec-core (~> 3.12.0)
222
+ rspec-expectations (~> 3.12.0)
223
+ rspec-mocks (~> 3.12.0)
224
+ rspec-core (3.12.0)
225
+ rspec-support (~> 3.12.0)
226
+ rspec-expectations (3.12.0)
227
+ diff-lcs (>= 1.2.0, < 2.0)
228
+ rspec-support (~> 3.12.0)
229
+ rspec-mocks (3.12.1)
230
+ diff-lcs (>= 1.2.0, < 2.0)
231
+ rspec-support (~> 3.12.0)
232
+ rspec-rails (6.0.1)
233
+ actionpack (>= 6.1)
234
+ activesupport (>= 6.1)
235
+ railties (>= 6.1)
236
+ rspec-core (~> 3.11)
237
+ rspec-expectations (~> 3.11)
238
+ rspec-mocks (~> 3.11)
239
+ rspec-support (~> 3.11)
240
+ rspec-support (3.12.0)
241
+ rspec_junit_formatter (0.6.0)
242
+ rspec-core (>= 2, < 4, != 2.12.0)
243
+ rubocop (1.40.0)
244
+ json (~> 2.3)
245
+ parallel (~> 1.10)
246
+ parser (>= 3.1.2.1)
247
+ rainbow (>= 2.2.2, < 4.0)
248
+ regexp_parser (>= 1.8, < 3.0)
249
+ rexml (>= 3.2.5, < 4.0)
250
+ rubocop-ast (>= 1.23.0, < 2.0)
251
+ ruby-progressbar (~> 1.7)
252
+ unicode-display_width (>= 1.4.0, < 3.0)
253
+ rubocop-ast (1.24.0)
254
+ parser (>= 3.1.1.0)
255
+ rubocop-performance (1.15.1)
256
+ rubocop (>= 1.7.0, < 2.0)
257
+ rubocop-ast (>= 0.4.0)
258
+ rubocop-platanus (0.2.0)
259
+ rubocop (>= 0.89.0)
260
+ rubocop-rails (2.17.3)
261
+ activesupport (>= 4.2.0)
262
+ rack (>= 1.1)
263
+ rubocop (>= 1.33.0, < 2.0)
264
+ rubocop-rspec (2.15.0)
265
+ rubocop (~> 1.33)
266
+ ruby-progressbar (1.11.0)
267
+ ruby2_keywords (0.0.5)
268
+ sawyer (0.9.2)
269
+ addressable (>= 2.3.5)
270
+ faraday (>= 0.17.3, < 3)
271
+ sexp_processor (4.16.1)
272
+ shellany (0.0.1)
273
+ simplecov (0.16.1)
274
+ docile (~> 1.1)
275
+ json (>= 1.8, < 3)
276
+ simplecov-html (~> 0.10.0)
277
+ simplecov-html (0.10.2)
278
+ sprockets (4.1.1)
279
+ concurrent-ruby (~> 1.0)
280
+ rack (> 1, < 3)
281
+ sprockets-rails (3.4.2)
282
+ actionpack (>= 5.2)
283
+ activesupport (>= 5.2)
284
+ sprockets (>= 3.0.0)
285
+ sqlite3 (1.4.2)
286
+ sync (0.5.0)
287
+ term-ansicolor (1.7.1)
288
+ tins (~> 1.0)
289
+ thor (1.2.1)
290
+ timeout (0.3.1)
291
+ tins (1.31.0)
292
+ sync
293
+ tzinfo (2.0.5)
294
+ concurrent-ruby (~> 1.0)
295
+ unicode-display_width (2.3.0)
296
+ websocket-driver (0.7.5)
297
+ websocket-extensions (>= 0.1.0)
298
+ websocket-extensions (0.1.5)
299
+ zeitwerk (2.6.6)
300
+
301
+ PLATFORMS
302
+ x86_64-darwin-20
303
+ x86_64-linux
304
+
305
+ DEPENDENCIES
306
+ bundler (~> 2.4.3)
307
+ coveralls
308
+ factory_bot_rails
309
+ guard-rspec
310
+ pry
311
+ pry-rails
312
+ repo_analyzer!
313
+ rspec-rails
314
+ rspec_junit_formatter
315
+ rubocop (~> 1.9)
316
+ rubocop-rails
317
+ sqlite3
318
+
319
+ BUNDLED WITH
320
+ 2.4.3
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ spec_dic = "spec"
3
+ # RSpec files
4
+ watch("spec/spec_helper.rb") { spec_dic }
5
+ watch("spec/rails_helper.rb") { spec_dic }
6
+ watch(%r{^spec/support/(.+)\.rb$}) { spec_dic }
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ # Engine files
9
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2023 Platanus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # Repo Analyzer
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/repo_analyzer.svg)](https://badge.fury.io/rb/repo_analyzer)
4
+ [![CircleCI](https://circleci.com/gh/platanus/repo_analyzer.svg?style=shield)](https://app.circleci.com/pipelines/github/platanus/repo_analyzer)
5
+
6
+ Rails engine to extract useful information about the project.
7
+
8
+ ## Installation
9
+
10
+ Add to your Gemfile:
11
+
12
+ ```ruby
13
+ gem "repo_analyzer"
14
+ ```
15
+
16
+ ```bash
17
+ bundle install
18
+ ```
19
+
20
+ Run the installer:
21
+
22
+ ```bash
23
+ rails generate repo_analyzer:install
24
+ ```
25
+
26
+ Then, configure ENV vars:
27
+
28
+ - `GITHUB_PERSONAL_TOKEN`: to extract commits info.
29
+ - `REPO_ANALYZER_URL`: POST endpoint where you want to process extracted info.
30
+
31
+ ## Usage
32
+
33
+ In order to extract the information you can execute:
34
+
35
+ ```ruby
36
+ RepoAnalyzer::ExtractProjectInfoJob.perform_now("github-repo-name")
37
+ ```
38
+
39
+ Example:
40
+
41
+ ```ruby
42
+ project_info = RepoAnalyzer::ExtractProjectInfoJob.perform_now("platanus/example-project")
43
+ ```
44
+
45
+ You will get something like this:
46
+
47
+ ```ruby
48
+ {
49
+ circleci_extractor: {
50
+ "platanus_compose" => false,
51
+ "jest" => true,
52
+ "rspec" => true,
53
+ "system_tests" => true,
54
+ "code_coverage" => true,
55
+ "rubocop" => true,
56
+ "eslint" => true,
57
+ "stylelint" => true
58
+ },
59
+ github_extractor: {
60
+ "last_commit_date" => "2023-01-25",
61
+ "last_contributors" => [
62
+ {
63
+ "login" => "flouMicaza",
64
+ "avatar_url" => "https://avatars.githubusercontent.com/u/24324363?v=4",
65
+ "contributions" => 316
66
+ },
67
+ {
68
+ "login" => "ankaph",
69
+ "avatar_url" => "https://avatars.githubusercontent.com/u/1688697?v=4",
70
+ "contributions" => 207
71
+ }
72
+ ],
73
+ "contributors" => [
74
+ {
75
+ "login" => "flouMicaza",
76
+ "avatar_url" => "https://avatars.githubusercontent.com/u/24324363?v=4",
77
+ "contributions" => 316
78
+ },
79
+ {
80
+ "login" => "ankaph",
81
+ "avatar_url" => "https://avatars.githubusercontent.com/u/1688697?v=4",
82
+ "contributions" => 207
83
+ }
84
+ ]
85
+ },
86
+ power_types_extractor: {
87
+ "commands" => false,
88
+ "services" => false,
89
+ "observers" => true,
90
+ "values" => false,
91
+ "utils" => true,
92
+ "clients" => true
93
+ },
94
+ # ...
95
+ }
96
+ ```
97
+
98
+ Each key (`circleci_extractor`, `github_extractor`, `power_types_extractor`, etc) contains useful information about the project that you can use whatever you want.
99
+ Extractors live here: https://github.com/platanus/repo_analyzer/tree/master/app/extractors/repo_analyzer
100
+
101
+ Then, the extracted information can be posted to some endpoint defined on this ENV var `REPO_ANALYZER_URL` executing:
102
+
103
+ ```ruby
104
+ RepoAnalyzer::PostExtractedInfoJob.perform_now("platanus/example-project", project_info)
105
+ ```
106
+
107
+ ### Script
108
+
109
+ You can extract and POST the info using the following rake task:
110
+
111
+ ```bash
112
+ bin/rake "repo_analyzer:analyze[github-repo-name]"
113
+ ```
114
+
115
+ Example:
116
+
117
+ ```bash
118
+ `bin/rake "repo_analyzer:analyze[platanus/example-project]"`
119
+ ```
120
+
121
+ ## Development
122
+
123
+ You can add a new extractor here: https://github.com/platanus/repo_analyzer/tree/master/app/extractors/repo_analyzer
124
+ This one must implement methods defined on this base class: https://github.com/platanus/repo_analyzer/blob/master/app/extractors/repo_analyzer/project_info_extractor.rb#L14
125
+
126
+ ## Testing
127
+
128
+ To run the specs you need to execute, in the root path of the engine, the following command:
129
+
130
+ ```bash
131
+ bundle exec guard
132
+ ```
133
+
134
+ You need to put **all your tests** in the `/repo_analyzer/spec` directory.
135
+
136
+ ## Publishing
137
+
138
+ On master/main branch...
139
+
140
+ 1. Change `VERSION` in `lib/repo_analyzer/version.rb`.
141
+ 2. Change `Unreleased` title to current version in `CHANGELOG.md`.
142
+ 3. Run `bundle install`.
143
+ 4. Commit new release. For example: `Releasing v0.1.0`.
144
+ 5. Create tag. For example: `git tag v0.1.0`.
145
+ 6. Push tag. For example: `git push origin v0.1.0`.
146
+
147
+ ## Contributing
148
+
149
+ 1. Fork it
150
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
151
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
152
+ 4. Push to the branch (`git push origin my-new-feature`)
153
+ 5. Create new Pull Request
154
+
155
+ ## Credits
156
+
157
+ Thank you [contributors](https://github.com/platanus/repo_analyzer/graphs/contributors)!
158
+
159
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
160
+
161
+ Repo Analyzer is maintained by [platanus](http://platan.us).
162
+
163
+ ## License
164
+
165
+ Repo Analyzer is © 2023 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ begin
2
+ require "bundler/setup"
3
+ rescue LoadError
4
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load "rails/tasks/engine.rake"
9
+ load "rails/tasks/statistics.rake"
10
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1 @@
1
+ //= link_directory ../stylesheets/repo_analyzer .css
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,31 @@
1
+ module RepoAnalyzer
2
+ class GithubClient
3
+ def initialize(personal_token)
4
+ @personal_token = personal_token
5
+ end
6
+
7
+ def contributors(repo_name)
8
+ client.contributors(repo_name, true)
9
+ end
10
+
11
+ def commits(repo_name, from_date: nil, to_date: nil)
12
+ from_date ||= Date.current - 2.years
13
+ to_date ||= Date.tomorrow
14
+ client.commits_between(repo_name, from_date.to_s, to_date.to_s)
15
+ end
16
+
17
+ def file_content(repo_name, file_path)
18
+ Base64.decode64(client.content(repo_name, path: file_path)[:content])
19
+ rescue Octokit::NotFound
20
+ ""
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :personal_token
26
+
27
+ def client
28
+ @client ||= Octokit::Client.new(access_token: personal_token, per_page: 10000)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module RepoAnalyzer
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,33 @@
1
+ module RepoAnalyzer
2
+ class BrakemanExtractor < ProjectInfoExtractor
3
+ CONFIDENCE = {
4
+ 0 => "High",
5
+ 1 => "Medium",
6
+ 2 => "Weak"
7
+ }
8
+
9
+ private
10
+
11
+ def extracted_info
12
+ { warnings: brakeman_info }
13
+ end
14
+
15
+ def brakeman_info
16
+ @brakeman_info ||= begin
17
+ tracker = Brakeman.run(app_path: project_data_bridge.project_path)
18
+ tracker.checks.warnings.map do |warning|
19
+ {
20
+ warning_type: warning.warning_type,
21
+ check: warning.check,
22
+ message: warning.message.to_s,
23
+ file_path: warning.file.relative,
24
+ link: warning.link,
25
+ line: warning.line,
26
+ confidence: CONFIDENCE[warning.confidence],
27
+ code: warning.format_code
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ module RepoAnalyzer
2
+ class CircleciExtractor < ProjectInfoExtractor
3
+ COVERAGE_REGEXP = /(coverage)/
4
+ RUBOCOP_REGEXP = /(rubocop)/
5
+ ESLINT_REGEXP = /(eslint)/
6
+ STYLELINT_REGEXP = /(stylelint)/
7
+ JEST_REGEXP = /(yarn\srun\stest)/
8
+ JEST_REGEXP_ALT = /(cibuild\sjs_tests)/
9
+ RSPEC_REGEXP = /(rspec\.xml)/
10
+ RSPEC_REGEXP_ALT = /(cibuild\stests)/
11
+ SYSTEM_REGEXP = /(rspec-system\.xml)/
12
+ PLATANUS_COMPOSE_REGEXP = %r{(platanus/compose)}
13
+
14
+ private
15
+
16
+ def extracted_info
17
+ {
18
+ platanus_compose: content_by_regexp?(PLATANUS_COMPOSE_REGEXP),
19
+ jest: content_by_regexp?(JEST_REGEXP, JEST_REGEXP_ALT),
20
+ rspec: content_by_regexp?(RSPEC_REGEXP, RSPEC_REGEXP_ALT),
21
+ system_tests: content_by_regexp?(SYSTEM_REGEXP),
22
+ code_coverage: content_by_regexp?(COVERAGE_REGEXP),
23
+ rubocop: content_by_regexp?(RUBOCOP_REGEXP),
24
+ eslint: content_by_regexp?(ESLINT_REGEXP),
25
+ stylelint: content_by_regexp?(STYLELINT_REGEXP)
26
+ }
27
+ end
28
+
29
+ def content_by_regexp?(*regexps)
30
+ !!content_by_regexp(regexps)
31
+ end
32
+
33
+ def content_by_regexp(regexps)
34
+ regexps.each do |regexp|
35
+ is_valid = config_content&.match(regexp)&.captures&.first
36
+ return true if is_valid
37
+ end
38
+
39
+ false
40
+ end
41
+
42
+ def config_content
43
+ @config_content ||= project_data_bridge.file_content(".circleci/config.yml")
44
+ end
45
+ end
46
+ end