Merge branch 'release/1.2.2'

This commit is contained in:
Petr Korolev 2014-12-10 12:18:58 +02:00
commit 7be5021685
3 changed files with 46 additions and 16 deletions

View File

@ -4,6 +4,7 @@ require 'github_api'
require 'json' require 'json'
require 'colorize' require 'colorize'
require_relative 'github_changelog_generator/parser' require_relative 'github_changelog_generator/parser'
require_relative 'github_changelog_generator/generator'
require_relative 'github_changelog_generator/version' require_relative 'github_changelog_generator/version'
module GitHubChangelogGenerator module GitHubChangelogGenerator
@ -29,6 +30,8 @@ module GitHubChangelogGenerator
@github = Github.new oauth_token: @github_token @github = Github.new oauth_token: @github_token
end end
@generator = Generator.new(@options)
@all_tags = self.get_all_tags @all_tags = self.get_all_tags
@pull_requests = self.get_all_closed_pull_requests @pull_requests = self.get_all_closed_pull_requests
if @options[:issues] if @options[:issues]
@ -139,7 +142,7 @@ module GitHubChangelogGenerator
output_filename = "#{@options[:output]}" output_filename = "#{@options[:output]}"
File.open(output_filename, 'w') { |file| file.write(log) } File.open(output_filename, 'w') { |file| file.write(log) }
puts "Done! Generated log placed in #{output_filename}" puts "Done! Generated log placed in #{`pwd`.strip!}/#{output_filename}"
end end
@ -264,20 +267,11 @@ module GitHubChangelogGenerator
if @options[:pulls] if @options[:pulls]
# Generate pull requests: # Generate pull requests:
if pull_requests pull_requests.each { |pull_request|
if @options[:author] merge = @generator.get_string_for_pull_request(pull_request)
pull_requests.each { |dict|
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url}) ([#{dict.user.login}](#{dict.user.html_url}))\n\n"
log += "- #{merge}" log += "- #{merge}"
}
else
pull_requests.each { |dict|
merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})\n\n"
log += "- #{merge}"
}
end
end } if pull_requests
end end
if @options[:issues] if @options[:issues]
@ -320,7 +314,9 @@ module GitHubChangelogGenerator
intro = 'Implemented enhancement' intro = 'Implemented enhancement'
end end
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}" log += "- #{merge}"
} }
end end

View File

@ -0,0 +1,34 @@
module GitHubChangelogGenerator
class Generator
def initialize(options = nil)
@options = options
end
def get_string_for_pull_request(pull_request)
encapsulated_title = self.encapsulate_string pull_request[:title]
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
merge += "\n\n"
end
merge
end
def encapsulate_string(string)
string.gsub! '\\', '\\\\'
encpas_chars = %w(> * _ \( \) [ ])
encpas_chars.each{ |char|
string.gsub! char, "\\#{char}"
}
string
end
end
end

View File

@ -1,3 +1,3 @@
module GitHubChangelogGenerator module GitHubChangelogGenerator
VERSION = '1.2.1' VERSION = '1.2.2'
end end