github-changelog-generator/lib/github_changelog_generator/generator.rb

38 lines
864 B
Ruby
Raw Normal View History

module GitHubChangelogGenerator
class Generator
2014-12-03 14:31:43 +00:00
def initialize(options = nil)
@options = options
end
def get_string_for_pull_request(pull_request)
2014-12-03 14:31:43 +00:00
encapsulated_title = self.encapsulate_string pull_request[:title]
2014-12-03 14:08:20 +00:00
2014-12-03 14:31:43 +00:00
merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})"
if @options[:author]
2014-12-22 13:14:01 +00:00
if pull_request.user.nil?
2014-12-15 13:54:11 +00:00
merge += " ({Null user})\n\n"
2014-12-22 13:14:01 +00:00
else
merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n"
2014-12-15 13:54:11 +00:00
end
else
merge += "\n\n"
end
merge
end
2014-12-03 14:31:43 +00:00
def encapsulate_string(string)
string.gsub! '\\', '\\\\'
encpas_chars = %w(> * _ \( \) [ ])
encpas_chars.each{ |char|
string.gsub! char, "\\#{char}"
}
string
end
end
2014-12-03 14:31:43 +00:00
end