# frozen_string_literal: true require_relative "./make_pr/base" require "pry" module Neetob class CLI module Github class YarnAudit < MakePr::Base DESCRIPTION = "Fix security vulnerabilities reported by yarn audit" attr_accessor :repos, :sandbox def initialize(repos, sandbox = false) super() @repos = repos @sandbox = sandbox end 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) yarn_install!(repo) report = run_yarn_audit(repo) ui.success("Successfully executed yarn audit for #{repo}", print_to_audit_log: false) 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 private def run_yarn_audit(repo) `#{cd_to_repo(repo)} && yarn audit` end end end end end