Class: GhBbAudit::GithubScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/gh_bb_audit/github_scanner.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_csv_path, keyword_csv_path, output_file_path) ⇒ GithubScanner



3
4
5
6
7
# File 'lib/gh_bb_audit/github_scanner.rb', line 3

def initialize(user_csv_path, keyword_csv_path, output_file_path)
  @user_csv_path = user_csv_path
  @keyword_csv_path = keyword_csv_path
  @output_file_path = output_file_path
end

Instance Method Details

#start_scanObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gh_bb_audit/github_scanner.rb', line 9

def start_scan
  output_writer = ::GhBbAudit::OutputWriter.new(@output_file_path)
  begin
    matcher = ::GhBbAudit::KeywordMatcher.new(::GhBbAudit::KeywordsList.new(@keyword_csv_path).all_keywords)
    all_github_user = ::GhBbAudit::UsersList.new(@user_csv_path).all_users
    
    all_github_user.each do |user|
      ::GhBbAudit::GithubUser.new(user).public_repos.each do |public_repo|
        file_paths = ::GhBbAudit::GithubRepo.new(user,public_repo.name).get_all_file_paths
        if matcher.repo_contains_keyword?(file_paths)
          output_writer.write_red_flag_record(user,public_repo.name)
        end
      end
    end
  rescue StandardError => e
    logger.error "Error in scanning Github ", error: e.inspect
  ensure
    output_writer.close
  end
end