From 4c737c93739fdbe57f8328e0c1358aecad5c9f30 Mon Sep 17 00:00:00 2001 From: phase Date: Sun, 25 Oct 2015 11:12:16 -0700 Subject: [PATCH] Extract username tagging --- .../generator/generator_generation.rb | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_generation.rb b/lib/github_changelog_generator/generator/generator_generation.rb index 7f595dd..ef0022e 100644 --- a/lib/github_changelog_generator/generator/generator_generation.rb +++ b/lib/github_changelog_generator/generator/generator_generation.rb @@ -160,7 +160,7 @@ module GitHubChangelogGenerator # 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)) + # - Add coveralls integration [\#223](https://github.com/skywinder/github-changelog-generator/pull/223) (@skywinder) # # @param [Hash] issue Fetched issue from GitHub # @return [String] Markdown-formatted single issue @@ -168,21 +168,22 @@ module GitHubChangelogGenerator encapsulated_title = encapsulate_string issue[:title] title_with_number = "#{encapsulated_title} [\\##{issue[:number]}](#{issue.html_url})" - - unless issue.pull_request.nil? - if @options[:author] - if issue.user.nil? - title_with_number += " ({Null user})" - else - if issue.user.html_url.exclude? "github.com" - title_with_number += " ([#{issue.user.login}](#{issue.user.html_url}))" - else - title_with_number += " (@#{issue.user.login})" - end - end - end + issue_line_with_user(title_with_number, issue) + end + + private + + def issue_line_with_user(line, issue) + return line if !@options[:author] || issue.pull_request.nil? + + user = issue.user + return "#{line} ({Null user})" unless user + + if user.html_url.include?("github.com") + "#{line} (@#{user.login})" + else + "#{line} ([#{user.login}](#{user.html_url}))" end - title_with_number end end end