Skip to content
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

add breaking-changes section to changelog #530

Merged
merged 6 commits into from Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 24 additions & 10 deletions lib/github_changelog_generator/generator/generator.rb
Expand Up @@ -96,60 +96,74 @@ def create_log_for_tag(pull_requests, issues, newer_tag, older_tag = nil)
# @return [String] generated log for issues
def issues_to_log(issues, pull_requests)
log = ""
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests)
bugs_a, enhancement_a, breaking_a, issues_a = parse_by_sections(issues, pull_requests)

log += generate_sub_section(breaking_a, options[:breaking_prefix])
log += generate_sub_section(enhancement_a, options[:enhancement_prefix])
log += generate_sub_section(bugs_a, options[:bug_prefix])
log += generate_sub_section(issues_a, options[:issue_prefix])
log
end

# rubocop:disable Metrics/CyclomaticComplexity
# This method sort issues by types
# (bugs, features, or just closed issues) by labels
#
# @param [Array] issues
# @param [Array] pull_requests
# @return [Array] tuple of filtered arrays: (Bugs, Enhancements Issues)
# @return [Array] tuple of filtered arrays: (Bugs, Enhancements, Breaking stuff, Issues)
def parse_by_sections(issues, pull_requests)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm looking at the code and I'm want some verification: is the goal that an issue is always in 1 section, preferably by a label but otherwise in the container "issues". For Pull requests it should be in 1 section but if it's not, it remains in the pull_requests array (that's modified in place). Correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

At the moment, the breaking change appears in multiple sections. See https://github.com/voxpupuli/puppet-rabbitmq/blob/33bc9ef7f69155d602f1cdd5abf5a794d1d8a27c/CHANGELOG.md#v700-2017-09-14 for example of where this branch was recently used.
@hunner has suggested this actually might not be the best behaviour. #530 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

ekohl@f5cb492 is my attempt at a cleanup and has tests. I kept current code if multiple labels match but maybe breaking should be at the top.

issues_a = []
enhancement_a = []
bugs_a = []
breaking_a = []

issues.each do |dict|
added = false
dict["labels"].each do |label|
if options[:bug_labels].include?(label["name"])
bugs_a.push(dict)
bugs_a << dict
added = true
next
end
if options[:enhancement_labels].include?(label["name"])
enhancement_a.push(dict)
enhancement_a << dict
added = true
next
end
if options[:breaking_labels].include?(label["name"])
breaking_a << dict
added = true
next
end
end
issues_a.push(dict) unless added
issues_a << dict unless added
end
# rubocop:enable Metrics/CyclomaticComplexity

added_pull_requests = []
pull_requests.each do |pr|
pr["labels"].each do |label|
if options[:bug_labels].include?(label["name"])
bugs_a.push(pr)
added_pull_requests.push(pr)
bugs_a << pr
added_pull_requests << pr
next
end
if options[:enhancement_labels].include?(label["name"])
enhancement_a.push(pr)
added_pull_requests.push(pr)
enhancement_a << pr
added_pull_requests << pr
next
end
if options[:breaking_labels].include?(label["name"])
breaking_a << pr
added_pull_requests << pr
next
end
end
end
added_pull_requests.each { |p| pull_requests.delete(p) }

[bugs_a, enhancement_a, issues_a]
[bugs_a, enhancement_a, breaking_a, issues_a]
end
end
end
2 changes: 2 additions & 0 deletions lib/github_changelog_generator/options.rb
Expand Up @@ -20,6 +20,8 @@ class Options < SimpleDelegator
due_tag
enhancement_labels
enhancement_prefix
breaking_labels
breaking_prefix
exclude_labels
exclude_tags
exclude_tags_regex
Expand Down
8 changes: 8 additions & 0 deletions lib/github_changelog_generator/parser.rb
Expand Up @@ -72,6 +72,9 @@ def self.setup_parser(options)
opts.on("--enhancement-label [LABEL]", "Setup custom label for enhancements section. Default is \"**Implemented enhancements:**\"") do |v|
options[:enhancement_prefix] = v
end
opts.on("--breaking-label [LABEL]", "Setup custom label for the breaking changes section. Default is \"**Breaking changes:**\"") do |v|
options[:breaking_prefix] = v
end
opts.on("--issues-label [LABEL]", "Setup custom label for closed-issues section. Default is \"**Closed issues:**\"") do |v|
options[:issue_prefix] = v
end
Expand Down Expand Up @@ -129,6 +132,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("--breaking-labels x,y,z", Array, 'Issues with these labels will be added to a new section, called "Breaking Changes". Default is \'backwards-incompatible\'') do |list|
options[:breaking_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
Expand Down Expand Up @@ -210,6 +216,7 @@ def self.default_options
enhancement_labels: ["enhancement", "Enhancement", "Type: Enhancement"],
bug_labels: ["bug", "Bug", "Type: Bug"],
exclude_labels: ["duplicate", "question", "invalid", "wontfix", "Duplicate", "Question", "Invalid", "Wontfix", "Meta: Exclude From Changelog"],
breaking_labels: %w[backwards-incompatible breaking],
issue_line_labels: [],
max_issues: nil,
simple_list: false,
Expand All @@ -220,6 +227,7 @@ def self.default_options
issue_prefix: "**Closed issues:**",
bug_prefix: "**Fixed bugs:**",
enhancement_prefix: "**Implemented enhancements:**",
breaking_prefix: "**Breaking changes:**",
git_remote: "origin",
http_cache: true
)
Expand Down
3 changes: 2 additions & 1 deletion lib/github_changelog_generator/parser_file.rb
Expand Up @@ -67,7 +67,7 @@ def extract_pair(line)
end

KNOWN_ARRAY_KEYS = %i[exclude_labels include_labels bug_labels
enhancement_labels issue_line_labels between_tags exclude_tags]
enhancement_labels breaking_labels issue_line_labels between_tags exclude_tags]
KNOWN_INTEGER_KEYS = [:max_issues]

def convert_value(value, option_name)
Expand All @@ -91,6 +91,7 @@ def convert_value(value, option_name)
header_label: :header,
front_matter: :frontmatter,
pr_label: :merge_prefix,
breaking_label: :breaking_prefix,
issues_wo_labels: :add_issues_wo_labels,
pr_wo_labels: :add_pr_wo_labels,
pull_requests: :pulls,
Expand Down