neetob 0.2.7 → 0.3.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: 44fc7447c47930d63937f671b215e6e74de9b913f754df9ad4a591e625d84f0e
4
- data.tar.gz: e0a3ea5d9e64e44545d2f22b0120ee397fdb9235f7c6e60ef3704a18f8d79954
3
+ metadata.gz: 129689cbd6ed773bb8b33aced3e726123662c5cc772c52287a3464bf63fe324b
4
+ data.tar.gz: ea5801918efe691ab99c985315fded011149eab7dc0082481d4c6ce6f41c2594
5
5
  SHA512:
6
- metadata.gz: fd471b240cdab4e99c1dab47bb104c108324613507a5943a3b206785c98949382efef27a980c63d3a7b4c3633f3a62fa911074420176c6e57e3d64a91c608b60
7
- data.tar.gz: 35cd801899082fc2e999a4f5075da10bd22b06d21a1c36252c03c007a70b97a1332d65191f4480b5bd5b1fa44466a844809c78b99fa06d7d16064b60a936bde5
6
+ metadata.gz: 6e933f42dc569195d856c707ac01911e71538057afcd4d447ab50242330a498d2fb31f769f1375a03bd3fbbad0e105dd24094ad642e74ed2cea0fdf751b5c5e4
7
+ data.tar.gz: 8a543540b8974374280c0b2781b99c7819918d34c0248b53dd85d0792d05004b4de407717d5bbd3a87881604672d1c714b11986f6642efb1af360a0952bb34e6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.0](https://www.github.com/bigbinary/neetob/compare/v0.2.7...v0.3.0) (2023-03-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * Added command to audit neeto products db-schema. ([#230](https://www.github.com/bigbinary/neetob/issues/230)) ([1401abc](https://www.github.com/bigbinary/neetob/commit/1401abc77e3dedfbf156266a328de7a3d4fe6bb0))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Enhanced compliance fix command ([#225](https://www.github.com/bigbinary/neetob/issues/225)) ([a41c95c](https://www.github.com/bigbinary/neetob/commit/a41c95c435173f331a2872ca5a9192c38fc04e22))
14
+
3
15
  ### [0.2.7](https://www.github.com/bigbinary/neetob/compare/v0.2.6...v0.2.7) (2023-03-16)
4
16
 
5
17
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neetob (0.2.7)
4
+ neetob (0.3.0)
5
5
  dotenv (~> 2.8.1)
6
6
  launchy (~> 2.5.0)
7
7
  octokit (~> 4.0)
@@ -164,7 +164,7 @@ GEM
164
164
  method_source (~> 1.0)
165
165
  public_suffix (5.0.0)
166
166
  racc (1.6.1)
167
- rack (2.2.6.2)
167
+ rack (2.2.6.4)
168
168
  rack-test (2.0.2)
169
169
  rack (>= 1.3)
170
170
  rails (7.0.4)
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../github/base"
4
+
5
+ module Neetob
6
+ class CLI
7
+ module Code
8
+ class Audit < Github::Base
9
+ attr_accessor :sandbox, :apps
10
+
11
+ def initialize(apps, sandbox = false)
12
+ super()
13
+ @apps = apps
14
+ @sandbox = sandbox
15
+ end
16
+
17
+ def run
18
+ matching_apps = find_all_matching_apps_or_repos(apps, :github, sandbox)
19
+ ui.info("\nListing apps and their tables that doesn't have uuid as primary key type:-")
20
+ has_found_tables_without_uuid = false
21
+ matching_apps.each do |app|
22
+ begin
23
+ db_schema = Base64.decode64(client.contents(app, path: "./db/schema.rb").content)
24
+ tables_without_uuid = find_tables_without_uuid_as_primary_key(db_schema).compact
25
+ if !tables_without_uuid.nil?
26
+ has_found_tables_without_uuid = true
27
+ print_app_and_tables(app, tables_without_uuid)
28
+ end
29
+ rescue Octokit::NotFound
30
+ ui.error("There is no \"db/schema.rb\" file in the \"#{app}\" app.")
31
+ rescue StandardError => e
32
+ ExceptionHandler.new(e).process
33
+ end
34
+ end
35
+ ui.info("No apps found to have tables without uuid as primary key type") if !has_found_tables_without_uuid
36
+ end
37
+
38
+ private
39
+
40
+ def find_tables_without_uuid_as_primary_key(db_schema)
41
+ create_table_regex = /create_table.*?,\s*force:\s*:cascade\s*do\s*\|t\|/
42
+ db_schema.scan(create_table_regex).map do |create_table_line|
43
+ !create_table_line.include?("id: :uuid") ? create_table_line.scan(/"([^"]+)"/).flatten.first : nil
44
+ end
45
+ end
46
+
47
+ def print_app_and_tables(app, tables)
48
+ ui.info("\n#{app}:-")
49
+ tables.each do |table|
50
+ ui.say(" ↳#{table}")
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "audit"
5
+
6
+ module Neetob
7
+ class CLI
8
+ module Code
9
+ class Commands < Thor
10
+ desc "audit", "Audit code base of neeto products to ensure they are properly maintained."
11
+ option :apps, type: :array, aliases: "-a", required: true, desc: "Neeto app names. Can be matched using the '*' wildcard. Example: \"neeto*\" \"neeto-cal-web\", also providing \"all\" as value matches all neeto product apps."
12
+ def audit
13
+ Audit.new(options[:apps], options[:sandbox]).run
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -23,7 +23,7 @@ module Neetob
23
23
  matching_gems.each do |gem|
24
24
  ui.info("\nWorking on #{gem}\n")
25
25
  begin
26
- clone_repo_in_tmp_dir("bigbinary/#{gem}")
26
+ shallow_clone_repo_in_tmp_dir("bigbinary/#{gem}")
27
27
  build_gem(gem)
28
28
  release_gem(gem)
29
29
  if $?.success?
@@ -28,8 +28,8 @@ module Neetob
28
28
  repo.split("/").last
29
29
  end
30
30
 
31
- def clone_repo_in_tmp_dir(repo)
32
- `git clone --quiet git@github.com:#{repo}.git /tmp/neetob/#{repo_name_without_org_suffix(repo)}`
31
+ def shallow_clone_repo_in_tmp_dir(repo)
32
+ `git clone --quiet --depth 1 git@github.com:#{repo}.git /tmp/neetob/#{repo_name_without_org_suffix(repo)}`
33
33
  end
34
34
 
35
35
  def add_commmit_and_push_changes(repo)
@@ -16,28 +16,32 @@ module Neetob
16
16
  @repos = repos
17
17
  @sandbox = sandbox
18
18
  @should_fix_nanos = should_fix_nanos
19
+ @failed_repos = []
19
20
  end
20
21
 
21
22
  def run
22
23
  matching_repos = should_fix_nanos ?
23
24
  add_org_suffix(find_all_matching_gems) :
24
25
  find_all_matching_apps_or_repos(repos, :github, sandbox)
26
+ @failed_repos = matching_repos
25
27
  delete_and_create_temp_neetob_dir
26
28
  matching_repos.each do |repo|
27
29
  ui.info("\nWorking on #{repo}\n")
28
30
  begin
29
- clone_repo_in_tmp_dir(repo)
31
+ shallow_clone_repo_in_tmp_dir(repo)
30
32
  check_and_delete_remote_branch(repo)
31
33
  bundle_install(repo)
32
34
  fix_neeto_audit(repo)
33
35
  ui.info(add_commmit_and_push_changes(repo))
34
36
  delete_local_feature_branch(repo)
35
- res = client.create_pull_request(repo, "main", BRANCH_NAME, PR_TITLE)
37
+ pull_request = client.create_pull_request(repo, "main", BRANCH_NAME, PR_TITLE)
36
38
  ui.success("PR created in \"#{repo}\" project successfully.")
39
+ @failed_repos.delete(repo)
37
40
  rescue StandardError => e
38
41
  ExceptionHandler.new(e).process
39
42
  end
40
43
  end
44
+ print_failed_repos if @failed_repos.length > 0
41
45
  `rm -rf /tmp/neetob`
42
46
  end
43
47
 
@@ -50,6 +54,13 @@ module Neetob
50
54
  def fix_neeto_audit(repo)
51
55
  `#{cd_to_repo_in_tmp_dir(repo)} && bundle exec neeto-audit -a`
52
56
  end
57
+
58
+ def print_failed_repos
59
+ ui.info("\nCompliance fix failed for repos:-")
60
+ @failed_repos.each do |repo|
61
+ ui.error(repo)
62
+ end
63
+ end
53
64
  end
54
65
  end
55
66
  end
@@ -29,7 +29,7 @@ module Neetob
29
29
  matching_repos.each do |repo|
30
30
  ui.info("\n Working on #{repo} \n")
31
31
  begin
32
- clone_repo_in_tmp_dir(repo)
32
+ shallow_clone_repo_in_tmp_dir(repo)
33
33
  check_and_delete_remote_branch(repo)
34
34
  update_script_file_permissions
35
35
  execute_script(repo)
@@ -14,7 +14,7 @@ module Neetob
14
14
  end
15
15
 
16
16
  desc "commits", "List the commits of a user across the neeto apps"
17
- option :apps, type: :array, aliases: "-a", default: ["*"], desc: "Github app names. Can be matched using the '*' wildcard. Example: \"neeto*\" \"neeto-cal-web\", also providing \"all\" as value matches all neeto repos."
17
+ option :apps, type: :array, aliases: "-a", default: ["*"], desc: "Github app names. Can be matched using the '*' wildcard. Example: \"neeto*\" \"neeto-cal-web\", also providing \"all\" as value matches all neeto apps."
18
18
  option :author, type: :string, required: true, desc: "Github username of the person whose commits you want to list"
19
19
  option :duration, type: :string, required: true, desc: "Duration for which you want to list the commits. Example: \"6.months\" \"10.days\""
20
20
  def commits
data/lib/neetob/cli.rb CHANGED
@@ -9,6 +9,7 @@ module Neetob
9
9
  require_relative "cli/users/commands"
10
10
  require_relative "cli/fetchorupdate_repos/execute"
11
11
  require_relative "cli/local/commands"
12
+ require_relative "cli/code/commands"
12
13
 
13
14
  class_option :sandbox,
14
15
  {
@@ -32,6 +33,9 @@ module Neetob
32
33
  desc "local", "Interact with the local neeto repos"
33
34
  subcommand "local", Local::Commands
34
35
 
36
+ desc "code", "Interact with code base of neeto products"
37
+ subcommand "code", Code::Commands
38
+
35
39
  desc "make_repos_uptodate", "Uptodate all neeto repos"
36
40
  def make_repos_uptodate
37
41
  FetchorupdateRepos::Execute.new(options[:sandbox]).run
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Neetob
4
- VERSION = "0.2.7"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neetob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Udai Gupta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-16 00:00:00.000000000 Z
11
+ date: 2023-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -112,6 +112,8 @@ files:
112
112
  - lib/neetob.rb
113
113
  - lib/neetob/cli.rb
114
114
  - lib/neetob/cli/base.rb
115
+ - lib/neetob/cli/code/audit.rb
116
+ - lib/neetob/cli/code/commands.rb
115
117
  - lib/neetob/cli/fetchorupdate_repos/execute.rb
116
118
  - lib/neetob/cli/github/auth.rb
117
119
  - lib/neetob/cli/github/base.rb