Class: GhBbAudit::GithubScanner

Inherits:
Object
  • Object
show all
Includes:
SemanticLogger::Loggable
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, github_user = nil, github_password = nil) ⇒ GithubScanner

Returns a new instance of GithubScanner.



6
7
8
9
10
11
# File 'lib/gh_bb_audit/github_scanner.rb', line 6

def initialize(user_csv_path, keyword_csv_path, output_file_path, github_user =nil, github_password =nil)
  @user_csv_path = user_csv_path
  @keyword_csv_path = keyword_csv_path
  @output_file_path = output_file_path
  GithubApi.set_user_name_pwd(github_user, github_password) if github_user && github_password
end

Instance Method Details

#start_scanObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gh_bb_audit/github_scanner.rb', line 13

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|
      logger.info("Scanning for User:: #{user}")
      ::GhBbAudit::GithubUser.new(user).public_repos.each do |public_repo|
        logger.info("Scanning Repo:: #{public_repo.name} for User:: #{user}")
        if matcher.repo_contains_keyword?([public_repo.name])
          output_writer.repo_name_matched(public_repo.name,user)
        end
        
        file_paths = ::GhBbAudit::GithubRepo.new(user,public_repo.name).get_all_file_paths

        if matcher.repo_contains_keyword?(file_paths)
          output_writer.file_paths_matched_in_repo(matcher.matched_file_paths(file_paths),public_repo.name, user)
        end
      end
    end
  rescue StandardError => e
    logger.error "Error in scanning Github ", error: e.inspect
  ensure
    output_writer.close
  end
end