neetob 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +10 -0
  3. data/.env +1 -0
  4. data/.rubocop.yml +596 -0
  5. data/.ruby-version +1 -0
  6. data/.semaphore/semaphore.yml +31 -0
  7. data/CHANGELOG.md +5 -0
  8. data/CODE_OF_CONDUCT.md +84 -0
  9. data/Gemfile +26 -0
  10. data/Gemfile.lock +249 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +381 -0
  13. data/Rakefile +16 -0
  14. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/github_access.rb +29 -0
  15. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/neeto_apps.rb +35 -0
  16. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/neeto_commons.rb +16 -0
  17. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/runner.rb +35 -0
  18. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/skippable.rb +19 -0
  19. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons/sync_bin.rb +32 -0
  20. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons/sync_formatters.rb +35 -0
  21. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons/sync_husky.rb +33 -0
  22. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons/sync_misc.rb +36 -0
  23. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons/sync_test_support.rb +38 -0
  24. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/sync_neeto_commons.rb +36 -0
  25. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/auto_update_prs_with_latest_master_verifier.rb +25 -0
  26. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/base.rb +72 -0
  27. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/bundler_version_verifier.rb +53 -0
  28. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/circleci_config_verifier.rb +25 -0
  29. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/common_gemfile_verifier.rb +25 -0
  30. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/common_initializers_verifier.rb +25 -0
  31. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/cypress_config_verifier.rb +46 -0
  32. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/cypress_plugins_index_verifier.rb +25 -0
  33. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/docker_file_dev_verifier.rb +25 -0
  34. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/environment_config_verifier.rb +38 -0
  35. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/gem_version_verifier.rb +38 -0
  36. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/gems_verifier_base.rb +34 -0
  37. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/gitignore_file_verifier.rb +39 -0
  38. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/jsconfig_verifier.rb +100 -0
  39. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/neeto_auth_gems_verifier.rb +20 -0
  40. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/neeto_commons_sync_verifier.rb +42 -0
  41. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/neeto_gems_version_verifier.rb +24 -0
  42. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/newrelic_verifier.rb +25 -0
  43. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/node_version_verifier.rb +63 -0
  44. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/package_dependencies_version_verifier.rb +62 -0
  45. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/package_json_verifier.rb +39 -0
  46. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/roles_verifier.rb +22 -0
  47. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/ruby_version_verifier.rb +25 -0
  48. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/semaphoreci_config_verifier.rb +162 -0
  49. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sidekiq_queues_verifier.rb +34 -0
  50. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/simplecov_config_verifier.rb +28 -0
  51. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sitemap_config_verifier.rb +29 -0
  52. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/slugignore_file_verifier.rb +25 -0
  53. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/bin_files_verifier.rb +29 -0
  54. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/formatter_files_verifier.rb +29 -0
  55. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/husky_files_verifier.rb +29 -0
  56. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/misc_files_verifier.rb +29 -0
  57. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier/test_support_files_verifier.rb +28 -0
  58. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/sync_neeto_commons_verifier.rb +31 -0
  59. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/webpack_configuration_verifier.rb +44 -0
  60. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers/webpacker_config_verifier.rb +29 -0
  61. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/verifiers_list.rb +61 -0
  62. data/Users/chiragshah/Workspace/bigbinary/neeto/neetob/neeto_compliance/lib/neeto_compliance/version.rb +5 -0
  63. data/data/branch-protection-rules.json +25 -0
  64. data/data/config-vars-audit.json +18 -0
  65. data/data/config-vars-list.json +1 -0
  66. data/data/config-vars-upsert.json +3 -0
  67. data/data/github-labels.json +192 -0
  68. data/env.sample +1 -0
  69. data/exe/neetob +25 -0
  70. data/install.sh +21 -0
  71. data/lib/neetob/cli/base.rb +85 -0
  72. data/lib/neetob/cli/fetchorupdate_repos/execute.rb +53 -0
  73. data/lib/neetob/cli/github/auth.rb +134 -0
  74. data/lib/neetob/cli/github/base.rb +35 -0
  75. data/lib/neetob/cli/github/commands.rb +50 -0
  76. data/lib/neetob/cli/github/issues/commands.rb +51 -0
  77. data/lib/neetob/cli/github/issues/create.rb +42 -0
  78. data/lib/neetob/cli/github/issues/list.rb +94 -0
  79. data/lib/neetob/cli/github/labels/commands.rb +62 -0
  80. data/lib/neetob/cli/github/labels/delete.rb +44 -0
  81. data/lib/neetob/cli/github/labels/delete_all.rb +48 -0
  82. data/lib/neetob/cli/github/labels/list.rb +36 -0
  83. data/lib/neetob/cli/github/labels/show.rb +37 -0
  84. data/lib/neetob/cli/github/labels/update.rb +40 -0
  85. data/lib/neetob/cli/github/labels/upsert.rb +62 -0
  86. data/lib/neetob/cli/github/login.rb +16 -0
  87. data/lib/neetob/cli/github/make_pr/base.rb +72 -0
  88. data/lib/neetob/cli/github/make_pr/commands.rb +37 -0
  89. data/lib/neetob/cli/github/make_pr/compliance_fix.rb +49 -0
  90. data/lib/neetob/cli/github/make_pr/script.rb +55 -0
  91. data/lib/neetob/cli/github/protect_branch.rb +46 -0
  92. data/lib/neetob/cli/github/search.rb +38 -0
  93. data/lib/neetob/cli/heroku/access/add.rb +38 -0
  94. data/lib/neetob/cli/heroku/access/commands.rb +41 -0
  95. data/lib/neetob/cli/heroku/access/list.rb +36 -0
  96. data/lib/neetob/cli/heroku/access/remove.rb +38 -0
  97. data/lib/neetob/cli/heroku/commands.rb +28 -0
  98. data/lib/neetob/cli/heroku/config_vars/audit.rb +64 -0
  99. data/lib/neetob/cli/heroku/config_vars/base.rb +19 -0
  100. data/lib/neetob/cli/heroku/config_vars/commands.rb +49 -0
  101. data/lib/neetob/cli/heroku/config_vars/list.rb +56 -0
  102. data/lib/neetob/cli/heroku/config_vars/remove.rb +39 -0
  103. data/lib/neetob/cli/heroku/config_vars/upsert.rb +80 -0
  104. data/lib/neetob/cli/heroku/execute.rb +37 -0
  105. data/lib/neetob/cli/local/commands.rb +19 -0
  106. data/lib/neetob/cli/local/ls.rb +29 -0
  107. data/lib/neetob/cli/sub_command_base.rb +17 -0
  108. data/lib/neetob/cli/ui.rb +41 -0
  109. data/lib/neetob/cli/users/audit.rb +121 -0
  110. data/lib/neetob/cli/users/commands.rb +28 -0
  111. data/lib/neetob/cli/users/commits.rb +125 -0
  112. data/lib/neetob/cli.rb +40 -0
  113. data/lib/neetob/exception_handler.rb +58 -0
  114. data/lib/neetob/utils.rb +16 -0
  115. data/lib/neetob/version.rb +5 -0
  116. data/lib/neetob.rb +10 -0
  117. data/overcommit.yml +43 -0
  118. data/scripts/delete_unused_assets.rb +67 -0
  119. metadata +235 -0
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "neeto_compliance/github_access"
4
+ require "neeto_compliance/sync_neeto_commons"
5
+ require "fileutils"
6
+
7
+ module NeetoCompliance
8
+ class SyncNeetoCommons
9
+ class SyncTestSupport
10
+ SUPPORT_DIR = "test/support"
11
+
12
+ def self.SUPPORT_FILES
13
+ [
14
+ "test/support/assertion_support.rb"
15
+ ]
16
+ end
17
+
18
+ def self.process
19
+ ensure_test_support_folder_exists
20
+ sync_support_files
21
+ end
22
+
23
+ def self.ensure_test_support_folder_exists
24
+ unless File.directory?(SUPPORT_DIR)
25
+ puts "Creating test support directory..."
26
+ FileUtils.mkdir_p SUPPORT_DIR
27
+ end
28
+ end
29
+
30
+ def self.sync_support_files
31
+ self.SUPPORT_FILES.each do |file|
32
+ print "Copying #{file}...\n"
33
+ system(`cp #{NeetoCompliance::SyncNeetoCommons.neeto_commons_url}#{file} #{file}`)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "neeto_compliance/sync_neeto_commons/sync_bin"
4
+ require "neeto_compliance/sync_neeto_commons/sync_formatters"
5
+ require "neeto_compliance/sync_neeto_commons/sync_husky"
6
+ require "neeto_compliance/sync_neeto_commons/sync_misc"
7
+ require "neeto_compliance/sync_neeto_commons/sync_test_support"
8
+ require "neeto_compliance/neeto_commons"
9
+
10
+ module NeetoCompliance
11
+ class SyncNeetoCommons
12
+ def self.neeto_commons_url
13
+ NeetoCompliance::NeetoCommons.path.join "common_files/"
14
+ end
15
+
16
+ def process
17
+ sync_with_neeto_commons
18
+ end
19
+
20
+ private
21
+
22
+ def sync_with_neeto_commons
23
+ syncers = [
24
+ SyncBin,
25
+ SyncFormatters,
26
+ SyncHusky,
27
+ SyncMisc,
28
+ SyncTestSupport
29
+ ]
30
+
31
+ syncers.each do |syncer|
32
+ syncer.process
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class AutoUpdatePrsWithLatestMasterVerifier < Base
5
+ def local_copy
6
+ ".github/workflows/auto_update_prs_with_latest_master.yml"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "common_files/github/workflows/auto_update_prs_with_latest_master.yml"
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "yaml"
6
+ require "set"
7
+
8
+ module NeetoCompliance
9
+ class Base
10
+ def process
11
+ return true if app_is_exception?
12
+
13
+ # preload the path
14
+ NeetoCompliance::NeetoCommons.path
15
+
16
+ success, errors = audit
17
+
18
+ unless success
19
+ errors.each do |error|
20
+ puts error
21
+ end
22
+ else
23
+ print "[PASS]\n".green
24
+ end
25
+
26
+ success
27
+ end
28
+
29
+ def verifier_name
30
+ self.class.to_s
31
+ end
32
+
33
+ def print_description
34
+ print "%-80s" % [verifier_name]
35
+ end
36
+
37
+ def auto_correct!
38
+ unless valid?
39
+ puts autofix_command
40
+ system autofix_command
41
+ end
42
+ end
43
+
44
+ def autofix_suggestion
45
+ "To fix run: #{autofix_command.yellow}"
46
+ end
47
+
48
+ def error_message
49
+ "[FAIL]".red
50
+ end
51
+
52
+ def audit
53
+ print_description
54
+ errors = []
55
+
56
+ unless valid?
57
+ errors << [error_message, autofix_suggestion, "\n"].join("\n")
58
+ end
59
+
60
+ [errors.length == 0, errors]
61
+ end
62
+
63
+ def app_is_exception?
64
+ current_app = `git config --get remote.origin.url`.split("/").last.strip
65
+ apps_exception_list.include?(current_app)
66
+ end
67
+
68
+ def apps_exception_list
69
+ []
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class BundlerVersionVerifier < Base
5
+ def latest_bundler_version
6
+ @_latest_bundler_version ||= _latest_bundler_version
7
+ end
8
+
9
+ def _latest_bundler_version
10
+ response = Net::HTTP.get(URI("https://rubygems.org/api/v1/versions/bundler.json"))
11
+ JSON.parse(response)[0]["number"]
12
+ end
13
+
14
+ def current_bundler_version
15
+ `tail -n 1 ./Gemfile.lock`.strip
16
+ end
17
+
18
+ def latest_version_being_used?
19
+ latest_bundler_version == current_bundler_version
20
+ end
21
+
22
+ def valid?
23
+ unless latest_version_being_used?
24
+ @error = %{
25
+ Please update the bundler version on your machine to #{latest_bundler_version}
26
+ You can follow the following steps:
27
+
28
+ 1. Install the latest bundler version:
29
+ - gem install bundler
30
+ 2. Open Gemfile.lock of the project:
31
+ - vim ./Gemfile.lock
32
+ 3. Delete the last line that contains the bundler version.
33
+ 4. Run:
34
+ - bundle install
35
+
36
+ You can also watch the following video that contains the same steps:
37
+ - https://youtu.be/vqAUIQehbKw
38
+ }
39
+ return false
40
+ end
41
+
42
+ true
43
+ end
44
+
45
+ def autofix_suggestion
46
+ @error.yellow
47
+ end
48
+
49
+ def autofix_command
50
+ "gem install bundler; perl -p -i -e 's/#{current_bundler_version}(\n*)\\Z/#{latest_bundler_version}\n/m' Gemfile.lock"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class CircleciConfigVerifier < Base
5
+ def local_copy
6
+ ".circleci/config.yml"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join local_copy
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class CommonGemfileVerifier < Base
5
+ def local_copy
6
+ "Gemfile.common.rb"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "gemfiles", local_copy
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class CommonInitializersVerifier < Base
5
+ def local_copy
6
+ "config/initializers/common.rb"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "initializers/common.rb"
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class CypressConfigVerifier < Base
5
+ def cypress_config_files
6
+ @_cypress_config_files ||= {
7
+ "cypress-tests/package.json" => NeetoCompliance::NeetoCommons.path.join("cypress/package.json"),
8
+ "cypress-tests/cypress/jsconfig.json" => NeetoCompliance::NeetoCommons.path.join("cypress/jsconfig.json"),
9
+ "cypress-tests/cypress/webpack.config.js" => NeetoCompliance::NeetoCommons.path.join("cypress/webpack.config.js"),
10
+ "cypress-tests/cypress/config/cypress.review.json" => NeetoCompliance::NeetoCommons.path.join("cypress/cypress.review.json"),
11
+ "cypress-tests/cypress/resolve.js" => NeetoCompliance::NeetoCommons.path.join("cypress/resolve.js")
12
+ }
13
+ end
14
+
15
+ def auto_correct!
16
+ unless valid?
17
+ @autofix_commands.each do |command|
18
+ puts command
19
+ system command
20
+ end
21
+ end
22
+ end
23
+
24
+ def autofix_suggestion
25
+ @autofix_commands.join("\n").yellow
26
+ end
27
+
28
+ def valid?
29
+ @autofix_commands = []
30
+
31
+ cypress_config_files.each_pair do |local_file, common_file|
32
+ unless same_file?(local_file, common_file)
33
+ @autofix_commands << "cp #{common_file.to_s} #{local_file}"
34
+ @autofix_commands << "cd cypress-tests && yarn" if local_file == "cypress-tests/package.json"
35
+ end
36
+ end
37
+
38
+ @autofix_commands.length == 0
39
+ end
40
+
41
+ def same_file?(local_file, common_file)
42
+ File.exist?(local_file) &&
43
+ `diff #{local_file} #{common_file.to_s}`.empty?
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class CypressPluginsIndexVerifier < Base
5
+ def local_copy
6
+ "cypress-tests/cypress/plugins/index.js"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "common_files/cypress-tests/cypress/plugins/index.js"
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class DockerFileDevVerifier < Base
5
+ def local_copy
6
+ "Dockerfile.dev"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "common_files/Dockerfile.dev"
11
+ end
12
+
13
+ def verify_command
14
+ "diff -N #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ `#{verify_command}`.empty?
19
+ end
20
+
21
+ def autofix_command
22
+ "cp #{commons_copy} #{local_copy}"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class EnvironmentConfigVerifier < Base
5
+ def environment_configs
6
+ @_environment_configs ||= {
7
+ "config/environments/development.rb": "NeetoCommonsBackend::Environments.development(config)",
8
+ "config/environments/test.rb": "NeetoCommonsBackend::Environments.test(config)",
9
+ "config/environments/heroku.rb": "NeetoCommonsBackend::Environments.heroku(config)",
10
+ "config/environments/staging.rb": "NeetoCommonsBackend::Environments.staging(config)",
11
+ "config/environments/production.rb": "NeetoCommonsBackend::Environments.production(config)",
12
+ "config/application.rb": "NeetoCommonsBackend::Environments.application(config)"
13
+ }
14
+ end
15
+
16
+ def auto_correct!
17
+ end
18
+
19
+ def valid?
20
+ @errors = []
21
+ environment_configs.each_pair do |file, command|
22
+ unless config_missing?(file, command)
23
+ @errors << "Add #{command} to #{file}"
24
+ end
25
+ end
26
+
27
+ @errors.empty?
28
+ end
29
+
30
+ def config_missing?(file, command)
31
+ system("cat #{file} | grep -q '#{command}'")
32
+ end
33
+
34
+ def autofix_suggestion
35
+ @errors.join("\n").yellow
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class GemVersionVerifier
5
+ attr_reader :gem_name, :repo_name, :latest_version
6
+
7
+ def initialize(gem_name, repo_name, latest_version)
8
+ @gem_name = gem_name
9
+ @repo_name = repo_name
10
+ @latest_version = latest_version
11
+ end
12
+
13
+ def current_version
14
+ bundler_specs.find { |s| s.name == gem_name }.extension_dir.split("-").last rescue nil
15
+ end
16
+
17
+ def bundler_specs
18
+ Bundler.definition.specs
19
+ end
20
+
21
+ # def latest_version
22
+ # uri = "https://api.github.com/repos/#{repo_name}/commits/master"
23
+ # GithubAccess.latest_commit_sha(uri)
24
+ # end
25
+
26
+ def gem_installed?
27
+ !current_version.nil?
28
+ end
29
+
30
+ def latest_version_installed?
31
+ current_version.to_s[0..6] == latest_version.to_s[0..6]
32
+ end
33
+
34
+ def valid?
35
+ gem_installed? && latest_version_installed?
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class GemsVerifierBase < Base
5
+ def gems
6
+ []
7
+ end
8
+
9
+ def latest_versions
10
+ @_latest_versions ||= _latest_versions
11
+ end
12
+
13
+ def _latest_versions
14
+ JSON.parse(Net::HTTP.get_response(URI("https://neeto-library-stable-versions.herokuapp.com/versions")).body)
15
+ end
16
+
17
+ def valid?
18
+ @failed_gems = []
19
+
20
+ gems.map do |gem|
21
+ gv = GemVersionVerifier.new(gem[:name], gem[:repo], latest_versions[gem[:repo]])
22
+ unless gv.valid?
23
+ @failed_gems << gem[:name]
24
+ end
25
+ end
26
+
27
+ @failed_gems.empty?
28
+ end
29
+
30
+ def autofix_command
31
+ "bundle update #{@failed_gems.join(' ')}"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class GitignoreFileVerifier < Base
5
+ def local_copy
6
+ ".gitignore"
7
+ end
8
+
9
+ def commons_copy
10
+ NeetoCompliance::NeetoCommons.path.join "common_files", local_copy
11
+ end
12
+
13
+ def verify_command
14
+ "diff #{commons_copy} #{local_copy}"
15
+ end
16
+
17
+ def valid?
18
+ local_gitignore = process_data File.read(local_copy)
19
+ common_gitignore = process_data File.read(NeetoCompliance::GitignoreFileVerifier.new.commons_copy)
20
+ common_gitignore.map { |line| return false unless local_gitignore.include?(line) }
21
+ true
22
+ end
23
+
24
+ def process_data(gitignore_data)
25
+ gitignore_data.split("\n").map { |line| line.gsub(/^#.*/, "") }
26
+ end
27
+
28
+ def autofix_command
29
+ "cp #{commons_copy} #{local_copy}"
30
+ end
31
+
32
+ def auto_correct!
33
+ end
34
+
35
+ def autofix_suggestion
36
+ "Make sure #{local_copy} contains all lines from #{commons_copy.to_s}".yellow
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hashdiff"
4
+
5
+ module NeetoCompliance
6
+ class JsconfigVerifier < Base
7
+ attr_accessor :diff
8
+
9
+ def initialize
10
+ @diff = []
11
+ end
12
+
13
+ def local_copy
14
+ "app/javascript/jsconfig.json"
15
+ end
16
+
17
+ def commons_copy
18
+ NeetoCompliance::NeetoCommons.path.join "common_files", "app", "javascript", "jsconfig.json"
19
+ end
20
+
21
+ def local_jsconfig_data
22
+ @_local_jsconfig_data ||= JSON.parse(File.read(local_copy))
23
+ end
24
+
25
+ def required_jsconfig_data
26
+ @_required_jsconfig_data ||= JSON.parse(File.read(commons_copy))
27
+ end
28
+
29
+ def verify_command
30
+ self.diff = Hashdiff.best_diff(required_jsconfig_data, local_jsconfig_data)
31
+ removed_symbol = "\-"
32
+ modified_symbol = "\~"
33
+ symbol_index = 0
34
+ self.diff.any? { |p| /#{removed_symbol}|#{modified_symbol}/.match?(p[symbol_index]) }
35
+ end
36
+
37
+ def local_file_exists?
38
+ File.file?(local_copy)
39
+ end
40
+
41
+ def valid?
42
+ return false unless local_file_exists?
43
+
44
+ is_modified_or_removed = verify_command
45
+ !is_modified_or_removed
46
+ end
47
+
48
+ def autofix_command
49
+ "cp #{commons_copy} #{local_copy}"
50
+ end
51
+
52
+ def upstream_copy
53
+ "https://github.com/bigbinary/neeto-commons-backend/blob/stable/lib/neeto-commons-backend/common_files/app/javascript/jsconfig.json"
54
+ end
55
+
56
+ def autofix_suggestion
57
+ base_message = %{
58
+ Your jsconfig.json content doesn't match with the expected neeto-commons content.
59
+
60
+ The following is the recommended jsconfig.json content in neeto ecosystem:
61
+ 1) View #{upstream_copy}
62
+ 2) Or open #{commons_copy}
63
+
64
+ To fix, start by fully replacing app/javascript/jsconfig.json
65
+ of your app with above mentioned content, by running the following:
66
+ #{autofix_command.yellow}
67
+ }
68
+
69
+ # The following is an example diff:
70
+ # [["-", "compilerOptions.moduleResolution", "NodeNext"],
71
+ # ["~", "compilerOptions.module", "ESNext", "ESNex"],
72
+ # ["+", "compilerOptions.paths.neetou", ["../../node_modules/@bigbinary/neetoui/**"]],
73
+ # For the above diff, we only need to get the newly added items marked by "+"
74
+ # and also check whether it's a "path" that has been added.
75
+ capture_addition_into_paths_key = "(?=.*\+)(?=.*compilerOptions.paths)"
76
+ new_paths = self.diff.select { |p| p.join =~ /#{capture_addition_into_paths_key}.*/ }
77
+ if new_paths.empty?
78
+ return base_message
79
+ end
80
+
81
+ custom_paths = Hash.new
82
+ new_paths.each do |path|
83
+ k = path[1].split(".").last
84
+ v = path[2]
85
+ custom_paths[k] = v
86
+ end
87
+
88
+ message = %{
89
+ #{base_message}
90
+ ==================================================
91
+ It seems that you've also added some custom paths in your jsconfig. You can cherry pick and
92
+ append the custom paths to app/javascript/jsconfig.json, if need be, after running above mentioned copy command.
93
+ Refer the comments in #{upstream_copy}
94
+ to see how to add custom paths.
95
+ The following are the custom paths that we have detected in your app/javascript/jsconfig.json:
96
+ #{JSON.pretty_generate(custom_paths).yellow}
97
+ }
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoCompliance
4
+ class NeetoAuthGemsVerifier < GemsVerifierBase
5
+ def gems
6
+ [
7
+ { name: "neeto-commons-backend", repo: "bigbinary/neeto-commons-backend" },
8
+ { name: "neeto-compliance", repo: "bigbinary/neeto-compliance" },
9
+ { name: "neeto-area51-engine", repo: "bigbinary/neeto-area51-engine" },
10
+ { name: "neeto-team-members-engine", repo: "bigbinary/neeto-team-members-engine" },
11
+ { name: "neeto-org-incineration-engine", repo: "bigbinary/neeto-org-incineration-engine" },
12
+ # { name: "neeto-emails", repo: "bigbinary/neeto-emails" },
13
+ { name: "neeto-email-prefixer", repo: "bigbinary/neeto-email-prefixer" },
14
+ { name: "neeto-mail-interceptor", repo: "bigbinary/neeto-mail-interceptor" },
15
+ { name: "neeto-filters-engine", repo: "bigbinary/neeto-filters-engine" },
16
+ { name: "neeto-custom-domains-engine", repo: "bigbinary/neeto-custom-domains-engine" },
17
+ ]
18
+ end
19
+ end
20
+ end