From 057fb488d59a9878e2ad77284c29bfcd93e0dad8 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 3 Dec 2014 15:38:05 +0200 Subject: [PATCH] create class and implement encapsulation. This fix #34 --- lib/github_changelog_generator.rb | 19 +++++++------------ lib/github_changelog_generator/generator.rb | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 lib/github_changelog_generator/generator.rb diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 77e0ed0..4e9bb83 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -4,6 +4,7 @@ require 'github_api' require 'json' require 'colorize' require_relative 'github_changelog_generator/parser' +require_relative 'github_changelog_generator/generator' require_relative 'github_changelog_generator/version' module GitHubChangelogGenerator @@ -29,6 +30,8 @@ module GitHubChangelogGenerator @github = Github.new oauth_token: @github_token end + generator = Generator.new(@options) + @all_tags = self.get_all_tags @pull_requests = self.get_all_closed_pull_requests if @options[:issues] @@ -264,19 +267,11 @@ module GitHubChangelogGenerator if @options[:pulls] # Generate pull requests: - if pull_requests + pull_requests.each { |pull_request| + merge = generator.get_string_for_pull_request(pull_request) + log += "- #{merge}" - pull_requests.each { |dict| - merge = "#{@options[:merge_prefix]}#{dict[:title]} [\\##{dict[:number]}](#{dict.html_url})" - if @options[:author] - merge += " ([#{dict.user.login}](#{dict.user.html_url}))\n\n" - else - merge += "\n\n" - end - log += "- #{merge}" - } - - end + } if pull_requests end if @options[:issues] diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb new file mode 100644 index 0000000..68c314f --- /dev/null +++ b/lib/github_changelog_generator/generator.rb @@ -0,0 +1,20 @@ +module GitHubChangelogGenerator + class Generator + + def initialize(options) + @options = options + end + + def get_string_for_pull_request(pull_request) + trimmed_title = pull_request[:title].gsub '>', '/>' + merge = "#{@options[:merge_prefix]}#{trimmed_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 + + end +end \ No newline at end of file