31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/routes/scripts_sonar.rb', line 31
def run_sonar
space_inserted = false
file_found_to_scan = false
results = []
changed_files = @git.get_changed_files(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
changed_files[0].split("\n").each do |changed_file|
if changed_file =~ /\Abrightpearl\/private\/library\/Lib\/(.*)/i
file_found_to_scan = true
unless space_inserted
puts
space_inserted = true
end
App::Terminal::output("Scanning: #{App::Terminal::format_directory(changed_file)}")
command = "phpcs --report=full --standard=#{App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)}/brightpearl/private/tests/phpcs/phpcs.xml #{App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)}/#{changed_file}"
results << App::Terminal::command_capture(command, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE), false, false)
end
end
unless file_found_to_scan
if changed_files[0] == '' && changed_files[1].nil?
App::Terminal::info("No files to scan. #{App::Terminal::format_highlight('No files changed')} in #{App::Terminal::format_directory("#{@git.get_repo_shorthand(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE))}/brightpearl/private/library/Lib")} between #{App::Terminal::format_branch(@git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} and #{App::Terminal::format_branch("origin/#{App::Git::MASTER}")}")
else
App::Terminal::info("No files to scan. #{App::Terminal::format_highlight('The only files changed')} between #{App::Terminal::format_branch(@git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} and #{App::Terminal::format_branch("origin/#{App::Git::MASTER}")} are:", changed_files[0].split("\n"))
end
exit
end
found_results = false
found_warnings = false
results_output = []
results.each do |result|
if result.any?
unless result[0] == ''
result[0].split("\n").each do |line|
if line =~ /\AFILE:\s(.*).\w{3,5}/i
found_results = true
results_output << "\x1B[38;5;196m#{line}\x1B[0m"
elsif line =~ /fatal error: (.*) on line \d+/i || line =~ /warning: (.*) on line \d+/i
found_warnings = true
results_output << "\x1B[38;5;250m#{line}\x1B[0m"
else
results_output << "\x1B[38;5;250m#{line}\x1B[0m"
end
end
end
end
end
if found_results
App::Terminal::error('Found errors!', results_output)
elsif found_warnings
App::Terminal::warning('Found warnings!', results_output)
else
App::Terminal::success('No errors found.', nil, file_found_to_scan ? true : false)
end
end
|