From 1fd341d9bf3355015adecb1397a4fb52c93593d2 Mon Sep 17 00:00:00 2001 From: aih Date: Thu, 22 Sep 2016 18:30:20 -0700 Subject: [PATCH] Add option to show selected labels in the issue line: --issue-line-labels --- .../generator/generator_generation.rb | 14 +++++++++++++- lib/github_changelog_generator/options.rb | 1 + lib/github_changelog_generator/parser.rb | 4 ++++ lib/github_changelog_generator/parser_file.rb | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/github_changelog_generator/generator/generator_generation.rb b/lib/github_changelog_generator/generator/generator_generation.rb index aaa1d2e..c939b7a 100644 --- a/lib/github_changelog_generator/generator/generator_generation.rb +++ b/lib/github_changelog_generator/generator/generator_generation.rb @@ -25,7 +25,7 @@ module GitHubChangelogGenerator end # @param [Array] issues List of issues on sub-section - # @param [String] prefix Nae of sub-section + # @param [String] prefix Name of sub-section # @return [String] Generate ready-to-go sub-section def generate_sub_section(issues, prefix) log = "" @@ -143,11 +143,23 @@ module GitHubChangelogGenerator encapsulated_title = encapsulate_string issue["title"] title_with_number = "#{encapsulated_title} [\\##{issue['number']}](#{issue['html_url']})" + if options[:issue_line_labels].present? + title_with_number = "#{title_with_number}{line_labels_for(issue)}" + end issue_line_with_user(title_with_number, issue) end private + def line_labels_for(issue) + labels = if options[:issue_line_labels] == ["ALL"] + issue["labels"] + else + issue["labels"].select { |label| options[:issue_line_labels].include?(label["name"]) } + end + labels.map { |label| " \[[#{label['name']}](#{label['url'].sub('api.github.com/repos', 'github.com')})\]" }.join("") + end + def issue_line_with_user(line, issue) return line if !options[:author] || issue["pull_request"].nil? diff --git a/lib/github_changelog_generator/options.rb b/lib/github_changelog_generator/options.rb index 9e6d70b..6b456ce 100644 --- a/lib/github_changelog_generator/options.rb +++ b/lib/github_changelog_generator/options.rb @@ -32,6 +32,7 @@ module GitHubChangelogGenerator :http_cache, :include_labels, :issue_prefix, + :issue_line_labels, :issues, :max_issues, :merge_prefix, diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index c62f187..6aab425 100755 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -125,6 +125,9 @@ module GitHubChangelogGenerator opts.on("--enhancement-labels x,y,z", Array, 'Issues with the specified labels will be always added to "Implemented enhancements" section. Default is \'enhancement,Enhancement\'') do |list| options[:enhancement_labels] = list end + opts.on("--issue-line-labels x,y,z", Array, 'The specified labels will be shown in brackets next to each matching issue. Use "ALL" to show all labels. Default is [].') do |list| + options[:issue_line_labels] = list + end opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| options[:between_tags] = list end @@ -205,6 +208,7 @@ module GitHubChangelogGenerator enhancement_labels: %w(enhancement Enhancement), bug_labels: %w(bug Bug), exclude_labels: %w(duplicate question invalid wontfix Duplicate Question Invalid Wontfix), + issue_line_labels: [], max_issues: nil, simple_list: false, verbose: true, diff --git a/lib/github_changelog_generator/parser_file.rb b/lib/github_changelog_generator/parser_file.rb index c13546c..9309a7a 100644 --- a/lib/github_changelog_generator/parser_file.rb +++ b/lib/github_changelog_generator/parser_file.rb @@ -66,7 +66,7 @@ module GitHubChangelogGenerator end KNOWN_ARRAY_KEYS = [:exclude_labels, :include_labels, :bug_labels, - :enhancement_labels, :between_tags, :exclude_tags] + :enhancement_labels, :issue_line_labels, :between_tags, :exclude_tags] KNOWN_INTEGER_KEYS = [:max_issues] def convert_value(value, option_name)