Class: RubocopChallenger::Github::PrTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop_challenger/github/pr_template.rb

Overview

To generate Pull Request template as markdown

Constant Summary collapse

'Auto generated by [rubocop_challenger](https://github.com/ryz310/rubocop_challenger)'

Instance Method Summary collapse

Constructor Details

#initialize(rule, template_path = nil) ⇒ PrTemplate

Returns a new instance of PrTemplate.



9
10
11
12
13
# File 'lib/rubocop_challenger/github/pr_template.rb', line 9

def initialize(rule, template_path = nil)
  template_path ||= default_template_path
  @template = File.read(template_path)
  @rule = rule
end

Instance Method Details

#generateObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubocop_challenger/github/pr_template.rb', line 15

def generate
  <<~TEMPLATE
    #{ERB.new(template, trim_mode: '-').result(binding)}
    #{FOOTER_TEXT}
  TEMPLATE
rescue StandardError => e
  error_template = File.read(error_template_path)
  <<~TEMPLATE
    #{ERB.new(error_template, trim_mode: '-').result(binding)}
    #{FOOTER_TEXT}
  TEMPLATE
end