2014-12-03 13:38:05 +00:00
|
|
|
module GitHubChangelogGenerator
|
|
|
|
class Generator
|
2014-12-03 14:31:43 +00:00
|
|
|
def initialize(options = nil)
|
2014-12-03 13:38:05 +00:00
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
2015-03-27 15:15:08 +00:00
|
|
|
# Parse issue and generate single line formatted issue line.
|
|
|
|
#
|
|
|
|
# Example output:
|
|
|
|
# - Add coveralls integration [\#223](https://github.com/skywinder/github-changelog-generator/pull/223) ([skywinder](https://github.com/skywinder))
|
|
|
|
#
|
|
|
|
# @param [Hash] issue Fetched issue from GitHub
|
|
|
|
# @return [String] Markdown-formatted single issue
|
2015-02-25 17:02:41 +00:00
|
|
|
def get_string_for_issue(issue)
|
2015-03-26 13:43:47 +00:00
|
|
|
encapsulated_title = encapsulate_string issue[:title]
|
2015-02-25 17:02:41 +00:00
|
|
|
|
2015-02-27 12:53:21 +00:00
|
|
|
title_with_number = "#{encapsulated_title} [\\##{issue[:number]}](#{issue.html_url})"
|
|
|
|
|
2015-02-25 17:02:41 +00:00
|
|
|
unless issue.pull_request.nil?
|
|
|
|
if @options[:author]
|
|
|
|
if issue.user.nil?
|
2015-04-02 09:05:26 +00:00
|
|
|
title_with_number += " ({Null user})"
|
2015-02-25 17:02:41 +00:00
|
|
|
else
|
2015-02-27 12:53:21 +00:00
|
|
|
title_with_number += " ([#{issue.user.login}](#{issue.user.html_url}))"
|
2015-02-25 17:02:41 +00:00
|
|
|
end
|
2014-12-15 13:54:11 +00:00
|
|
|
end
|
2014-12-03 13:38:05 +00:00
|
|
|
end
|
2015-02-27 12:53:21 +00:00
|
|
|
title_with_number
|
2014-12-03 13:38:05 +00:00
|
|
|
end
|
|
|
|
|
2015-05-22 10:37:06 +00:00
|
|
|
# Encapsulate characters to make markdown look as expected.
|
|
|
|
#
|
|
|
|
# @param [String] string
|
|
|
|
# @return [String] encapsulated input string
|
2014-12-03 14:31:43 +00:00
|
|
|
def encapsulate_string(string)
|
|
|
|
string.gsub! '\\', '\\\\'
|
|
|
|
|
2015-03-03 15:33:51 +00:00
|
|
|
encpas_chars = %w(> * _ \( \) [ ] #)
|
2015-03-26 13:43:47 +00:00
|
|
|
encpas_chars.each do |char|
|
2014-12-03 14:31:43 +00:00
|
|
|
string.gsub! char, "\\#{char}"
|
2015-03-26 13:43:47 +00:00
|
|
|
end
|
2014-12-03 14:31:43 +00:00
|
|
|
|
|
|
|
string
|
|
|
|
end
|
2014-12-03 13:38:05 +00:00
|
|
|
end
|
2015-03-26 13:43:47 +00:00
|
|
|
end
|