neetob 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c24a5c688914c96c2ab4652e673124a9f794e1cdb57ca86e606e61134717b015
4
- data.tar.gz: b66c79be8be99068e154fdd811556fa3a6dc947f9f8ac232fdc82654241236b5
3
+ metadata.gz: dfc6be750f749257d3d3f6a10f00a348dc746c34d69bdb1c9ccb76d44c9d260a
4
+ data.tar.gz: f217db9a99316cec947b70fd74f27b0f5c6285fe127b94fbf627bd6c559b399d
5
5
  SHA512:
6
- metadata.gz: d07b6d3b394a6ce90d6feaa8031c506bb49be5bdcf076761cdc1c55b9e555400cc9fafdb766816de82d4bfbc438e8e8a3784c9c2c94d4ab49a3c66795f5f4da0
7
- data.tar.gz: 8fbfe0585f64116cd3404873d19a7518e034ffe250d789c5775bc6186c808bcf88c1407e10cbca5c73fe1333ef069642095577c3142054ef2fc6260cd90ee33b
6
+ metadata.gz: 1edde424e4ff572f7f56ab45580c92bb5f574c411272f89e35f884e41d6aabdd8fa92d029783d8f7bb63551e29897020e58bef6bb1b427ae030d8f0782daf31c
7
+ data.tar.gz: 6aa6507b68340737f27a8f12910d12d5be7cf60de84796d169afd229fc712623440a0e9828bf42b45df9df8855ef0235062b050862f4050077b213a86c7d3c39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0](https://www.github.com/bigbinary/neetob/compare/v0.3.2...v0.4.0) (2023-04-05)
4
+
5
+
6
+ ### Features
7
+
8
+ * Added command to run brakeman on all neeto-repos ([#234](https://www.github.com/bigbinary/neetob/issues/234)) ([12123b4](https://www.github.com/bigbinary/neetob/commit/12123b48cc0d63ca0dd8a9e894a86a3a44a72d9e))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Fixes protect-branch command to ignore semaphore checks for repos that doesn't have it. ([#231](https://www.github.com/bigbinary/neetob/issues/231)) ([5da7e34](https://www.github.com/bigbinary/neetob/commit/5da7e34365f0f2460e88f35ced241c91200400dc))
14
+ * Updated the neetob.gemspec file to include the chronic gem dependancy ([#242](https://www.github.com/bigbinary/neetob/issues/242)) ([4f375ff](https://www.github.com/bigbinary/neetob/commit/4f375ff3cd6bb2b14c2d046d6c07420adadcf4ff))
15
+
16
+ ### [0.3.2](https://www.github.com/bigbinary/neetob/compare/v0.3.1...v0.3.2) (2023-03-29)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * Added multiline input format logic for issue create command ([#236](https://www.github.com/bigbinary/neetob/issues/236)) ([71f1442](https://www.github.com/bigbinary/neetob/commit/71f1442ff92938bb84661c42853fb6f72bbc8fba))
22
+
3
23
  ### [0.3.1](https://www.github.com/bigbinary/neetob/compare/v0.3.0...v0.3.1) (2023-03-23)
4
24
 
5
25
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neetob (0.3.1)
4
+ neetob (0.4.0)
5
+ brakeman (~> 5.0)
6
+ chronic
5
7
  dotenv (~> 2.8.1)
6
8
  launchy (~> 2.5.0)
7
9
  octokit (~> 4.0)
@@ -88,6 +90,7 @@ GEM
88
90
  public_suffix (>= 2.0.2, < 6.0)
89
91
  ansi (1.5.0)
90
92
  ast (2.4.2)
93
+ brakeman (5.4.1)
91
94
  builder (3.2.4)
92
95
  byebug (11.1.3)
93
96
  childprocess (4.1.0)
@@ -238,5 +238,15 @@
238
238
  "name": "manual-qa-completed",
239
239
  "description": "Manual QA team has finished verifying the changes.",
240
240
  "color": "CCDDCD"
241
- }
241
+ },
242
+ {
243
+ "name": "description-needed",
244
+ "description": "More description is needed for this issue either to work on it or to test the fix.",
245
+ "color": "E54D50"
246
+ },
247
+ {
248
+ "name": "discussion",
249
+ "description": "Further discussion is required to work on this issue. Better we should move it to neetoPlanner's roadmap.",
250
+ "color": "A62F71"
251
+ },
242
252
  ]
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./make_pr/base"
4
+
5
+ module Neetob
6
+ class CLI
7
+ module Github
8
+ class Brakeman < MakePr::Base
9
+ DESCRIPTION = "Fix security vulnerabilities reported by brakeman"
10
+ attr_accessor :repos, :sandbox
11
+
12
+ def initialize(repos, sandbox = false)
13
+ super()
14
+ @repos = repos
15
+ @sandbox = sandbox
16
+ end
17
+
18
+ def run
19
+ matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
20
+ matching_repos.each do |repo|
21
+ begin
22
+ ui.info("\nWorking on repo #{repo}")
23
+ clone_repo_in_tmp_dir(repo)
24
+ bundle_install(repo)
25
+ report = run_brakeman(repo)
26
+ ui.success("Successfully executed brakeman for #{repo}")
27
+ warnings = report.split("\n\n== Warnings ==\n\n").last&.split("\n\n")
28
+ if !report.include?("No warnings found")
29
+ issue = client.create_issue(repo, DESCRIPTION, parse_description(warnings))
30
+ ui.success("Issue created at #{issue.html_url}")
31
+ end
32
+ rescue StandardError => e
33
+ ExceptionHandler.new(e).process
34
+ end
35
+ end
36
+ `rm -rf /tmp/neetob`
37
+ end
38
+
39
+ private
40
+
41
+ def run_brakeman(repo)
42
+ `#{cd_to_repo_in_tmp_dir(repo)} && brakeman`
43
+ end
44
+
45
+ def parse_description(warnings)
46
+ warning_descriptions = warnings.map do |warning|
47
+ code_line = warning.scan(/Code: (.*)\n/).flatten.first
48
+ warning.gsub!(code_line, "`#{code_line}`") if !code_line.nil?
49
+ "```bash #{warning} \n```"
50
+ end
51
+ warning_descriptions.join("\n")
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -8,6 +8,7 @@ require_relative "protect_branch"
8
8
  require_relative "login"
9
9
  require_relative "make_pr/commands"
10
10
  require_relative "gems/commands"
11
+ require_relative "brakeman"
11
12
 
12
13
  module Neetob
13
14
  class CLI
@@ -52,6 +53,15 @@ module Neetob
52
53
  ProtectBranch.new(
53
54
  options[:branch], options[:repos], options[:path], options[:sandbox]).run
54
55
  end
56
+
57
+ desc "brakeman", "Run brakeman on neeto repos & create issues in repos where needed"
58
+ option :repos, type: :array, aliases: "-r",
59
+ desc:
60
+ "Github repo names. Can be matched using the '*' wildcard. Example: \"neeto*\" \"neeto-cal-web\", also providing \"all\" as value matches all neeto repos.",
61
+ required: true
62
+ def brakeman
63
+ Brakeman.new(options[:repos], options[:sandbox]).run
64
+ end
55
65
  end
56
66
  end
57
67
  end
@@ -30,7 +30,7 @@ module Neetob
30
30
  end
31
31
 
32
32
  desc "create", "Create a issue in the Github repos"
33
- option :title, type: :string, required: true, aliases: "-t", desc: "Title of the issue"
33
+ option :title, type: :string, aliases: "-t", desc: "Title of the issue"
34
34
  option :description, type: :string, aliases: "-d", desc: "Description of the issue"
35
35
  option :assignee, type: :string, desc: "Username of the user you want to assign this issue."
36
36
  option :labels, type: :string, desc: "List of comma separated labels you want to add in this issue. Example: \"--labels bug,ui\""
@@ -20,12 +20,13 @@ sandbox = false)
20
20
  @issue_assignee = issue_assignee
21
21
  @issue_labels = issue_labels
22
22
  @sandbox = sandbox
23
+ get_issue_title_or_description_and_confirm_data
23
24
  end
24
25
 
25
26
  def run
26
27
  matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
27
28
  matching_repos.each do |repo|
28
- ui.info("\n Creating issue in \"#{repo}\" \n")
29
+ ui.info("\nCreating issue in \"#{repo}\" \n")
29
30
  begin
30
31
  issue_options = { assignee: issue_assignee, labels: issue_labels }
31
32
  issue = client.create_issue(repo, issue_title, issue_description, issue_options)
@@ -35,6 +36,28 @@ sandbox = false)
35
36
  end
36
37
  end
37
38
  end
39
+
40
+ private
41
+
42
+ def get_issue_title_or_description_and_confirm_data
43
+ until issue_title.present?
44
+ ui.info("Enter the issue title below. Once you are done then just press enter:\n~ ")
45
+ @issue_title = STDIN.gets.chomp
46
+ ui.say("Title can't be blank.") if issue_title.blank?
47
+ end
48
+ if issue_description.blank?
49
+ ui.info(
50
+ "Enter the issue body below. Once you are done then press Ctrl-D: " +
51
+ "(While creating the issue body you can use the enter key to type multiline message)\n")
52
+ @issue_description = STDIN.read.chomp
53
+ end
54
+ ui.info(
55
+ "Please review the issue title & the issue body that you have typed and also check the repos " +
56
+ "for which issues will be created. If everything looks good then type " +
57
+ "\"proceed\" below. Type anything else to cancel the operation.\n~ ")
58
+ proceed = STDIN.gets.chomp
59
+ ui.error("Cancelled creating issue(s)") and exit(true) if proceed.casecmp?("proceed") == false
60
+ end
38
61
  end
39
62
  end
40
63
  end
@@ -19,6 +19,10 @@ module Neetob
19
19
 
20
20
  private
21
21
 
22
+ def bundle_install(repo)
23
+ `#{cd_to_repo_in_tmp_dir(repo)} && bundle install`
24
+ end
25
+
22
26
  def delete_and_create_temp_neetob_dir
23
27
  `rm -rf /tmp/neetob`
24
28
  `mkdir /tmp/neetob`
@@ -47,10 +47,6 @@ module Neetob
47
47
 
48
48
  private
49
49
 
50
- def bundle_install(repo)
51
- `#{cd_to_repo_in_tmp_dir(repo)} && bundle install`
52
- end
53
-
54
50
  def fix_neeto_audit(repo)
55
51
  `#{cd_to_repo_in_tmp_dir(repo)} && bundle exec neeto-audit -a`
56
52
  end
@@ -6,7 +6,7 @@ module Neetob
6
6
  class CLI
7
7
  module Github
8
8
  class ProtectBranch < Base
9
- attr_accessor :branch_name, :required_rules_json_file_path, :repos, :sandbox
9
+ attr_accessor :branch_name, :required_rules_json_file_path, :repos, :repos_integrated_with_semaphore, :sandbox
10
10
 
11
11
  def initialize(branch_name, repos, required_rules_json_file_path = "", sandbox = false)
12
12
  super()
@@ -14,6 +14,7 @@ module Neetob
14
14
  @required_rules_json_file_path = required_rules_json_file_path
15
15
  @repos = repos
16
16
  @sandbox = sandbox
17
+ @repos_integrated_with_semaphore = build_repos_integrated_with_semaphore_list.compact
17
18
  end
18
19
 
19
20
  def run
@@ -22,7 +23,9 @@ module Neetob
22
23
  matching_repos.each do |repo|
23
24
  ui.info("\n Working on \"#{repo}\" repo")
24
25
  ui.info(" Updating \"#{branch_name}\" branch protection rules")
26
+ has_semaphore_integrated = repos_integrated_with_semaphore.include?(repo)
25
27
  rules = read_json_file(required_rules_json_file_path || default_rules_file_path)
28
+ rules.dig("required_status_checks", "contexts")&.clear if !has_semaphore_integrated
26
29
  rules_with_symbol_keys = rules.transform_keys(&:to_sym)
27
30
  client.protect_branch(repo, branch_name, rules_with_symbol_keys)
28
31
  ui.success("Branch protection rules updated successfully")
@@ -40,6 +43,14 @@ module Neetob
40
43
  ui.info("Updating protection rules from the \"neetob/data/branch-protection-rules.json\" file")
41
44
  end
42
45
  end
46
+
47
+ def build_repos_integrated_with_semaphore_list
48
+ all_repos = NeetoCompliance::NeetoRepos.repos.values.flatten
49
+ all_repos.map! do |repo_config|
50
+ repo_config.is_a?(Hash) ? repo_config.to_a.map { |values| { values[0] => values[1] } } : repo_config
51
+ end
52
+ all_repos.flatten.map { |repo| (repo.is_a?(Hash) && repo.values[0].dig("semaphore")) ? "bigbinary/#{repo.keys[0]}" : nil }
53
+ end
43
54
  end
44
55
  end
45
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Neetob
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
data/neetob.gemspec CHANGED
@@ -35,6 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "terminal-table", "~> 3.0.2" # for building cli table
36
36
  spec.add_dependency "launchy", "~> 2.5.0" # for opening in browser
37
37
  spec.add_dependency "dotenv", "~> 2.8.1" # for loading env variables
38
+ spec.add_dependency "chronic" # for natural language date and time parsing
39
+ spec.add_dependency "brakeman", "~> 5.0" # for running brakeman commands
38
40
 
39
41
  # To add the files from submodules
40
42
  `git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
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.3.1
4
+ version: 0.4.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-23 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: chronic
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: brakeman
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
83
111
  description: This gem gives different commands for interacting with Github and Heroku
84
112
  instances of existing neeto repos.
85
113
  email:
@@ -119,6 +147,7 @@ files:
119
147
  - lib/neetob/cli/fetchorupdate_repos/execute.rb
120
148
  - lib/neetob/cli/github/auth.rb
121
149
  - lib/neetob/cli/github/base.rb
150
+ - lib/neetob/cli/github/brakeman.rb
122
151
  - lib/neetob/cli/github/commands.rb
123
152
  - lib/neetob/cli/github/gems/commands.rb
124
153
  - lib/neetob/cli/github/gems/release.rb