Class: Pronto::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/pronto/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_hash = ConfigFile.new.to_h) ⇒ Config

Returns a new instance of Config.



3
4
5
# File 'lib/pronto/config.rb', line 3

def initialize(config_hash = ConfigFile.new.to_h)
  @config_hash = config_hash
end

Instance Method Details

#bitbucket_hostnameObject



50
51
52
# File 'lib/pronto/config.rb', line 50

def bitbucket_hostname
  URI.parse(bitbucket_web_endpoint).host
end

#consolidate_comments?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/pronto/config.rb', line 14

def consolidate_comments?
  consolidated =
    ENV['PRONTO_CONSOLIDATE_COMMENTS'] ||
    @config_hash.fetch('consolidate_comments', false)
  consolidated
end

#excluded_files(runner) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pronto/config.rb', line 33

def excluded_files(runner)
  files =
    if runner == 'all'
      ENV['PRONTO_EXCLUDE'] || @config_hash['all']['exclude']
    else
      @config_hash.fetch(runner, {})['exclude']
    end

  Array(files)
    .flat_map { |path| Dir[path.to_s] }
    .map { |path| File.expand_path(path) }
end

#github_hostnameObject



46
47
48
# File 'lib/pronto/config.rb', line 46

def github_hostname
  URI.parse(github_web_endpoint).host
end

#github_review_typeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pronto/config.rb', line 21

def github_review_type
  review_type =
    ENV['PRONTO_GITHUB_REVIEW_TYPE'] ||
    @config_hash.fetch('github_review_type', false)

  if review_type == 'request_changes'
    'REQUEST_CHANGES'
  else
    'COMMENT'
  end
end

#loggerObject



71
72
73
74
75
76
# File 'lib/pronto/config.rb', line 71

def logger
  @logger ||= begin
    verbose = ENV['PRONTO_VERBOSE'] || @config_hash['verbose']
    verbose ? Logger.new($stdout) : Logger.silent
  end
end

#max_warningsObject



58
59
60
# File 'lib/pronto/config.rb', line 58

def max_warnings
  ENV['PRONTO_MAX_WARNINGS'] && Integer(ENV['PRONTO_MAX_WARNINGS']) || @config_hash['max_warnings']
end

#message_format(formatter) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/pronto/config.rb', line 62

def message_format(formatter)
  formatter_config = @config_hash[formatter]
  if formatter_config && formatter_config.key?('format')
    formatter_config['format']
  else
    ENV['PRONTO_FORMAT'] || @config_hash['format']
  end
end

#warnings_per_reviewObject



54
55
56
# File 'lib/pronto/config.rb', line 54

def warnings_per_review
  ENV['PRONTO_WARNINGS_PER_REVIEW'] && Integer(ENV['PRONTO_WARNINGS_PER_REVIEW']) || @config_hash['warnings_per_review']
end