Class: Neetob::CLI::Github::Brakeman

Inherits:
MakePr::Base show all
Defined in:
lib/neetob/cli/github/brakeman.rb

Constant Summary collapse

DESCRIPTION =
"Fix security vulnerabilities reported by brakeman"

Constants inherited from MakePr::Base

MakePr::Base::BRANCH_NAME, MakePr::Base::PR_TITLE, MakePr::Base::REPO_SPECIFIC_COMMANDS_BEFORE_BUNDLE_INSTALL

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from MakePr::Base

#branch_name, #pr_title

Attributes inherited from Base

#access_token, #client

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(repos, sandbox = false) ⇒ Brakeman

Returns a new instance of Brakeman.



12
13
14
15
16
# File 'lib/neetob/cli/github/brakeman.rb', line 12

def initialize(repos, sandbox = false)
  super()
  @repos = repos
  @sandbox = sandbox
end

Instance Attribute Details

#reposObject

Returns the value of attribute repos.



10
11
12
# File 'lib/neetob/cli/github/brakeman.rb', line 10

def repos
  @repos
end

#sandboxObject

Returns the value of attribute sandbox.



10
11
12
# File 'lib/neetob/cli/github/brakeman.rb', line 10

def sandbox
  @sandbox
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neetob/cli/github/brakeman.rb', line 18

def run
  matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
  report = nil
  matching_repos.each do |repo|
    begin
      ui.info("\nWorking on repo #{repo}", print_to_audit_log: false)
      clone_repo_in_tmp_dir(repo)
      bundle_install!(repo)
      report = run_brakeman(repo)
      ui.success("Successfully executed brakeman for #{repo}", print_to_audit_log: false)
      warnings = report.split("\n\n== Warnings ==\n\n").last&.split("\n\n")
      if !report.include?("No warnings found") && !report.blank? && !Thread.current[:audit_mode]
        issue = client.create_issue(repo, DESCRIPTION, parse_description(warnings))
        ui.success("Issue created at #{issue.html_url}")
      end
    rescue StandardError => e
      ExceptionHandler.new(e).process
    end
  end
  `rm -rf /tmp/neetob` unless Thread.current[:audit_mode]
  if Thread.current[:audit_mode]
    report
  end
end