class PimpMyChangelog::Pimper
Constants
- CONTRIBUTOR_REGEXP
- ISSUE_NUMBER_REGEXP
The following regexp ensure that the issue or contributor is not wrapped between brackets (aka: is a link)
- SEPARATOR
Attributes
changelog[R]
project[R]
user[R]
Public Class Methods
new(user, project, changelog)
click to toggle source
@param user [String] Github user of this changelog @param project [String] Github project of this changelog @param changelog [String] The changelog
# File lib/pimpmychangelog/pimper.rb, line 11 def initialize(user, project, changelog) @user = user @project = project @changelog = changelog end
Public Instance Methods
better_changelog()
click to toggle source
@return [String] The changelog with contributors and issues as link
# File lib/pimpmychangelog/pimper.rb, line 18 def better_changelog parsed_changelog = Parser.new(changelog) # If the file doesn't have an extra newline at the end the separator gets rendered # as part of the changelog. So add an extra newline in that case. extra_newline_if_required = parsed_changelog.content.match(/\n\n\Z/) ? "" : "\n" linkify_changelog(parsed_changelog.content) + extra_newline_if_required + links_definitions(parsed_changelog.issues, parsed_changelog.contributors) end
Protected Instance Methods
linkify_changelog(changelog)
click to toggle source
@param [String] changelog @return [String] The changelog with users and issues linkified.
Example: "@pcreux closes issue #123" # => "[@pcreux][] closes issue [#123][]"
# File lib/pimpmychangelog/pimper.rb, line 36 def linkify_changelog(changelog) changelog. gsub(ISSUE_NUMBER_REGEXP, '\1[#\2][]\3'). gsub(CONTRIBUTOR_REGEXP, '\1[@\2][]\3') end
links_definitions(issues, contributors)
click to toggle source
@param [Array] issues An array of issue numbers @param [Array] contributors An array of contributors github ids
@return [String] A list of link definitions
# File lib/pimpmychangelog/pimper.rb, line 51 def links_definitions(issues, contributors) return '' if issues.empty? && contributors.empty? issues_list = issues.map do |issue| "[##{issue}]: https://github.com/#{user}/#{project}/issues/#{issue}" end contributors_list = contributors.map do |contributor| "[@#{contributor}]: https://github.com/#{contributor}" end ([SEPARATOR] + issues_list + contributors_list).join("\n") end