Skip to content

Add option to show selected labels in the issue line #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/github_changelog_generator/generator/generator_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def compound_changelog
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 = ""
Expand Down Expand Up @@ -143,11 +143,23 @@ def get_string_for_issue(issue)
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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aih can you add tests to covers cases with new method?

def issue_line_with_user(line, issue)
return line if !options[:author] || issue["pull_request"].nil?

Expand Down
1 change: 1 addition & 0 deletions lib/github_changelog_generator/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Options < SimpleDelegator
:http_cache,
:include_labels,
:issue_prefix,
:issue_line_labels,
:issues,
:max_issues,
:merge_prefix,
Expand Down
4 changes: 4 additions & 0 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def self.setup_parser(options)
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
Expand Down Expand Up @@ -205,6 +208,7 @@ def self.default_options
enhancement_labels: %w(enhancement Enhancement),
bug_labels: %w(bug Bug),
exclude_labels: %w(duplicate question invalid wontfix Duplicate Question Invalid Wontfix),
issue_line_labels: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_issues: nil,
simple_list: false,
verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/github_changelog_generator/parser_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def extract_pair(line)
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)
Expand Down