From 9aa156a02b5083abc67d1c5e5bbcbabdb601d65c Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 3 Dec 2014 16:31:43 +0200 Subject: [PATCH] improve script --- lib/github_changelog_generator.rb | 7 +++---- lib/github_changelog_generator/generator.rb | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 8017f8b..9bccf74 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -314,10 +314,9 @@ module GitHubChangelogGenerator intro = 'Implemented enhancement' end - dict[:title].gsub! '>', '\>' - dict[:title].gsub! '*', '\*' - dict[:title].gsub! '_', '\_' - merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n" + enc_string = @generator.encapsulate_string dict[:title] + + merge = "*#{intro}:* #{enc_string} [\\##{dict[:number]}](#{dict.html_url})\n\n" log += "- #{merge}" } end diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb index 1fa7cda..6918db8 100644 --- a/lib/github_changelog_generator/generator.rb +++ b/lib/github_changelog_generator/generator.rb @@ -1,16 +1,14 @@ module GitHubChangelogGenerator class Generator - def initialize(options) + def initialize(options = nil) @options = options end def get_string_for_pull_request(pull_request) - pull_request[:title].gsub! '>', '\>' - pull_request[:title].gsub! '*', '\*' - pull_request[:title].gsub! '_', '\_' + encapsulated_title = self.encapsulate_string pull_request[:title] - merge = "#{@options[:merge_prefix]}#{pull_request[:title]} [\\##{pull_request[:number]}](#{pull_request.html_url})" + merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})" if @options[:author] merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" else @@ -19,5 +17,18 @@ module GitHubChangelogGenerator merge end + def encapsulate_string(string) + + string.gsub! '\\', '\\\\' + + encpas_chars = %w(> * _ \( \) [ ]) + encpas_chars.each{ |char| + string.gsub! char, "\\#{char}" + } + + string + end + end + end \ No newline at end of file