class Pronto::Flow
Constants
- CONFIG_FILE
- CONFIG_KEYS
Attributes
cli_options[W]
flow_executable[W]
Public Class Methods
new(patches, commit = nil)
click to toggle source
Calls superclass method
# File lib/pronto/flow.rb, line 11 def initialize(patches, commit = nil) super(patches, commit) read_config end
Public Instance Methods
cli_options()
click to toggle source
# File lib/pronto/flow.rb, line 20 def cli_options "#{@cli_options} --json".strip end
description_for_error(data, first_line_error_in_patch)
click to toggle source
# File lib/pronto/flow.rb, line 72 def description_for_error(data, first_line_error_in_patch) description = data.map do |item| item[:descr] end.join(" ") see_file_paths = data.map do |item| next if item[:path].nil? || item[:path].empty? file_path = item[:path].sub(git_repo_path.to_s , "") next if file_path == first_line_error_in_patch.patch.delta.new_file[:path] "\nSee: #{file_path}:#{item[:line]}" end description = description + see_file_paths.join("") end
files()
click to toggle source
# File lib/pronto/flow.rb, line 24 def files return [] if @patches.nil? @files ||= begin @patches .select { |patch| patch.additions > 0 } .map(&:new_file_full_path) .compact end end
flow_executable()
click to toggle source
# File lib/pronto/flow.rb, line 16 def flow_executable @flow_executable || 'flow'.freeze end
git_repo_path()
click to toggle source
# File lib/pronto/flow.rb, line 115 def git_repo_path @git_repo_path ||= Rugged::Repository.discover(File.expand_path(Dir.pwd)).workdir end
messages(json_output)
click to toggle source
# File lib/pronto/flow.rb, line 90 def messages(json_output) json_output["errors"].map do |error| first_patch_with_error = nil files_associated_with_error = [] data = error["message"].map do |context| data = { descr: context["descr"], path: context["path"], line: context["line"] } end first_line_error_in_patch = data.map do |item| patch_line_for_offence(item[:path], item[:line]) end.compact.first next if first_line_error_in_patch.nil? description = description_for_error(data, first_line_error_in_patch) path = first_line_error_in_patch.patch.delta.new_file[:path] level = error["level"].to_sym Message.new(path, first_line_error_in_patch, level, description, nil, self.class) end end
patch_line_for_offence(path, lineno)
click to toggle source
# File lib/pronto/flow.rb, line 35 def patch_line_for_offence(path, lineno) patch_node = @patches.find do |patch| patch.new_file_full_path.to_s == path end return if patch_node.nil? patch_node.added_lines.find do |patch_line| patch_line.new_lineno == lineno end end
read_config()
click to toggle source
# File lib/pronto/flow.rb, line 47 def read_config config_file = File.join(git_repo_path, CONFIG_FILE) return unless File.exist?(config_file) config = YAML.load_file(config_file) CONFIG_KEYS.each do |config_key| next unless config[config_key] send("#{config_key}=", config[config_key]) end end
run()
click to toggle source
# File lib/pronto/flow.rb, line 58 def run if files.any? messages(run_flow) else [] end end
run_flow()
click to toggle source
# File lib/pronto/flow.rb, line 66 def run_flow Dir.chdir(git_repo_path) do return JSON.parse(`#{flow_executable} --json`) end end