-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test rubocop #615
Closed
+165
−2
Closed
test rubocop #615
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
Dir.chdir(File.dirname(__dir__)) | ||
|
||
require_relative '../lib/auto_hck' | ||
|
||
module AutoHCK | ||
# rubocop:disable Metrics/BlockLength | ||
run do | ||
# rubocop:enable Metrics/BlockLength | ||
|
||
require 'optparse' | ||
|
||
# command line parser class | ||
# rubocop:disable Lint/ConstantDefinitionInBlock | ||
class CLI | ||
# rubocop:enable Lint/ConstantDefinitionInBlock | ||
|
||
attr_accessor :debug, :input_path, :output_path, :output_format, :action | ||
|
||
def initialize | ||
@parser = create_parser | ||
end | ||
|
||
def parse(args) | ||
@parser.order!(args) | ||
end | ||
|
||
def create_parser | ||
OptionParser.new do |parser| | ||
parser.banner = 'Usage: triggers_check [--help] <options>' | ||
parser.separator '' | ||
define_options(parser) | ||
parser.on_tail('-h', '--help', 'Show this message') do | ||
puts parser | ||
exit | ||
end | ||
end | ||
end | ||
|
||
def define_options(parser) | ||
Check notice Code scanning / Rubocop Avoid methods longer than 10 lines of code. Note
Metrics/MethodLength: Method has too many lines. [21/20]
|
||
parser.on('--debug', TrueClass, | ||
'Printing debug information (optional)', | ||
&method(:debug=)) | ||
|
||
parser.on('--input-path path', String, | ||
'Path to text file containing a list of changed source files', | ||
&method(:input_path=)) | ||
|
||
parser.on('--output-path path', String, | ||
'Path to text file containing a list of changed source files', | ||
&method(:output_path=)) | ||
|
||
parser.on('--output-format <output_format>', String, | ||
'Output format', | ||
&method(:output_format=)) | ||
|
||
parser.on('--action <action>', String, | ||
'List of section to reject from HTML results', | ||
'(use "--reject-report-sections=help" to list sections)') do |action| | ||
if action == 'help' | ||
puts Tests::RESULTS_REPORT_SECTIONS.join("\n") | ||
exit | ||
end | ||
|
||
# extra_keys = action - Tests::RESULTS_REPORT_SECTIONS | ||
|
||
# raise(AutoHCKError, "Unknown report sections: #{extra_keys.join(', ')}.") unless extra_keys.empty? | ||
|
||
@action = action | ||
end | ||
end | ||
end | ||
|
||
cli = CLI.new | ||
cli.parse(ARGV) | ||
|
||
@logger = MonoLogger.new($stderr) | ||
@logger.level = cli.debug ? 'DEBUG' : 'INFO' | ||
|
||
p cli.input_path | ||
|
||
raise(AutoHCKError, 'Input path is not specified.') unless cli.input_path | ||
raise(AutoHCKError, 'Output path is not specified.') unless cli.output_path | ||
|
||
case cli.action | ||
when 'convert' | ||
Check warning Code scanning / Rubocop Checks for `when` branches with empty bodies. Warning
Lint/EmptyWhen: Avoid when branches without a body.
|
||
|
||
when 'split' | ||
@logger.info('Splitting the input file') | ||
|
||
raise(AutoHCKError, 'Output path is not a directory but action = split') unless File.directory?(cli.output_path) | ||
|
||
if File.extname(cli.input_path) == '.json' | ||
@logger.debug("Loading data from JSON file: #{cli.input_path}") | ||
data = JSON.parse(File.read(cli.input_path)) | ||
else | ||
@logger.debug("Loading data from YAML file: #{cli.input_path}") | ||
data = YAML.safe_load_file(cli.input_path) | ||
end | ||
|
||
data.each do |key, value| | ||
file_name = "#{key}.#{cli.output_format}" | ||
@logger.debug("Processing key #{key} -> #{file_name}") | ||
|
||
output_file = File.join(cli.output_path, file_name) | ||
if cli.output_format == 'json' | ||
@logger.info("Writing data to JSON file: #{output_file}") | ||
File.open(output_file, 'w') do |f| | ||
f.write(JSON.pretty_generate(value)) | ||
f.write("\n") # Add a newline at the end of the file | ||
end | ||
else | ||
@logger.info("Writing data to YAML file: #{output_file}") | ||
File.write(output_file, YAML.dump(value)) | ||
end | ||
end | ||
when 'merge' | ||
@logger.info('Merging the input files') | ||
|
||
raise(AutoHCKError, 'Input path is not a directory but action = merge') unless File.directory?(cli.input_path) | ||
|
||
files = Dir.glob(File.join(cli.input_path, '*')) | ||
@logger.info("Found #{files.size} files for merging") | ||
@logger.debug("Files: #{files}") | ||
|
||
merged_data = {} | ||
|
||
files.each do |file| | ||
if File.extname(file) == '.json' | ||
@logger.debug("Processing JSON file: #{file}") | ||
data = JSON.parse(File.read(file)) | ||
else | ||
@logger.debug("Processing YAML file: #{file}") | ||
data = YAML.safe_load_file(file) | ||
end | ||
|
||
merged_data[File.basename(file, '.*')] = data | ||
end | ||
|
||
output_ext = File.extname(cli.output_path) | ||
|
||
unless cli.output_format.nil? || output_ext == ".#{cli.output_format}" | ||
raise(AutoHCKError, | ||
"Output file extension #{output_ext} does not match the output format #{cli.output_format}") | ||
end | ||
|
||
if output_ext == '.json' | ||
@logger.info("Writing merged data to JSON file: #{cli.output_path}") | ||
File.write(cli.output_path, JSON.pretty_generate(merged_data)) | ||
else | ||
@logger.info("Writing merged data to YAML file: #{cli.output_path}") | ||
File.write(cli.output_path, YAML.dump(merged_data)) | ||
end | ||
|
||
else | ||
raise(AutoHCKError, 'Unknown action.') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Rubocop
Gems within groups in the Gemfile should be alphabetically sorted. Note