Class: Linterbot::RunnerConfiguration
- Inherits:
-
Object
- Object
- Linterbot::RunnerConfiguration
- Extended by:
- Forwardable
- Defined in:
- lib/linterbot/runner_configuration.rb
Defined Under Namespace
Classes: MissingAttribute
Constant Summary collapse
- DEFAULT_PROJECT_BASE_PATH =
'./'- DEFAULT_CONFIG_FILE_PATH =
'./.linterbot.yml'
Instance Attribute Summary collapse
-
#approver_class ⇒ Object
Returns the value of attribute approver_class.
-
#commenter_class ⇒ Object
Returns the value of attribute commenter_class.
-
#github_client ⇒ Object
Returns the value of attribute github_client.
-
#linter_report_file ⇒ Object
Returns the value of attribute linter_report_file.
-
#project_base_path ⇒ Object
Returns the value of attribute project_base_path.
Class Method Summary collapse
- .configuration!(options) ⇒ Object
- .default_configuration ⇒ Object
- .load_config_file(config_file_path) ⇒ Object
- .missing_github_access_token ⇒ Object
Instance Method Summary collapse
-
#initialize(github_client, options) ⇒ RunnerConfiguration
constructor
A new instance of RunnerConfiguration.
Constructor Details
#initialize(github_client, options) ⇒ RunnerConfiguration
Returns a new instance of RunnerConfiguration.
82 83 84 85 86 87 88 89 |
# File 'lib/linterbot/runner_configuration.rb', line 82 def initialize(github_client, ) @github_client = github_client = @commenter_class = [:commenter_class] @approver_class = [:approver_class] @project_base_path = [:project_base_path] @linter_report_file = [:linter_report_file] end |
Instance Attribute Details
#approver_class ⇒ Object
Returns the value of attribute approver_class.
29 30 31 |
# File 'lib/linterbot/runner_configuration.rb', line 29 def approver_class @approver_class end |
#commenter_class ⇒ Object
Returns the value of attribute commenter_class.
28 29 30 |
# File 'lib/linterbot/runner_configuration.rb', line 28 def commenter_class @commenter_class end |
#github_client ⇒ Object
Returns the value of attribute github_client.
27 28 29 |
# File 'lib/linterbot/runner_configuration.rb', line 27 def github_client @github_client end |
#linter_report_file ⇒ Object
Returns the value of attribute linter_report_file.
31 32 33 |
# File 'lib/linterbot/runner_configuration.rb', line 31 def linter_report_file @linter_report_file end |
#project_base_path ⇒ Object
Returns the value of attribute project_base_path.
30 31 32 |
# File 'lib/linterbot/runner_configuration.rb', line 30 def project_base_path @project_base_path end |
Class Method Details
.configuration!(options) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/linterbot/runner_configuration.rb', line 59 def configuration!() config_file_path = .config_file_path || File.(DEFAULT_CONFIG_FILE_PATH) loaded_config = load_config_file(config_file_path) base_config = default_configuration.merge(loaded_config) github_access_token = ENV["GITHUB_ACCESS_TOKEN"] || base_config[:github_access_token] raise missing_github_access_token unless github_access_token github_client = Octokit::Client.new(access_token: github_access_token) configuration = new(github_client, base_config) configuration.project_base_path = .project_base_path if .project_base_path configuration.linter_report_file = .linter_report_file_path if .linter_report_file_path if .dry_run configuration.commenter_class = TTYPullRequestCommenter configuration.approver_class = TTYApprover end configuration end |
.default_configuration ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/linterbot/runner_configuration.rb', line 50 def default_configuration { project_base_path: File.(DEFAULT_PROJECT_BASE_PATH), linter_report_file: STDIN, commenter_class: GitHubPullRequestCommenter, approver_class: CommitApprover } end |
.load_config_file(config_file_path) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/linterbot/runner_configuration.rb', line 41 def load_config_file(config_file_path) if File.exist?(config_file_path) config = YAML.load(File.read(config_file_path)) Hash[config.each.map { |key, value| [key.to_sym, value] }] else {} end end |
.missing_github_access_token ⇒ Object
35 36 37 38 39 |
# File 'lib/linterbot/runner_configuration.rb', line 35 def missing_github_access_token fix_description = "You must either define the enviromental variable 'GITHUB_ACCESS_TOKEN " + "or the attribute 'github_access_token' in the configuration file.'" MissingAttribute.new("GitHub access token", fix_description) end |