Skip to content

Commit

Permalink
Add release summary section (github-changelog-generator#654)
Browse files Browse the repository at this point in the history
* Add release summary section

* Add label option for release summary section

* 'issue_line_body' option is unnecessary to add release summary section

* Change default option for 'summary-labels'

* Add man page for release summary options
  • Loading branch information
mob-sakai authored and olleolleolle committed Sep 20, 2018
1 parent a92b913 commit 05de5ec
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/github_changelog_generator/generator/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def generate_body(pull_requests, issues)
# @return [Array] Section objects.
def default_sections
[
Section.new(name: "summary", prefix: @options[:summary_prefix], labels: @options[:summary_labels], options: @options, body_only:true),
Section.new(name: "breaking", prefix: @options[:breaking_prefix], labels: @options[:breaking_labels], options: @options),
Section.new(name: "enhancements", prefix: @options[:enhancement_prefix], labels: @options[:enhancement_labels], options: @options),
Section.new(name: "bugs", prefix: @options[:bug_prefix], labels: @options[:bug_labels], options: @options),
Expand Down
9 changes: 6 additions & 3 deletions lib/github_changelog_generator/generator/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ module GitHubChangelogGenerator
#
# @see GitHubChangelogGenerator::Entry
class Section
attr_accessor :name, :prefix, :issues, :labels
attr_accessor :name, :prefix, :issues, :labels, :body_only

def initialize(opts = {})
@name = opts[:name]
@prefix = opts[:prefix]
@labels = opts[:labels] || []
@issues = opts[:issues] || []
@options = opts[:options] || Options.new({})
@body_only = opts[:body_only] || false
end

# Returns the content of a section.
Expand All @@ -22,10 +23,11 @@ def generate_content
content = ""

if @issues.any?
content += "#{@prefix}\n\n" unless @options[:simple_list]
content += "#{@prefix}\n\n" unless @options[:simple_list] || @prefix.blank?
@issues.each do |issue|
merge_string = get_string_for_issue(issue)
content += "- #{merge_string}\n"
content += "- " unless @body_only
content += "#{merge_string}\n"
end
content += "\n"
end
Expand Down Expand Up @@ -53,6 +55,7 @@ def get_string_for_issue(issue)
end

def issue_line_with_body(line, issue)
return issue["body"] if @body_only && issue["body"].present?
return line if !@options[:issue_line_body] || issue["body"].blank?
# get issue body till first line break
body_paragraph = body_till_first_break(issue["body"])
Expand Down
2 changes: 2 additions & 0 deletions lib/github_changelog_generator/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Options < SimpleDelegator
simple_list
since_tag
ssl_ca_file
summary_labels
summary_prefix
token
unreleased
unreleased_label
Expand Down
8 changes: 8 additions & 0 deletions lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def self.setup_parser(options)
opts.on("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last|
options[:base] = last
end
opts.on("--summary-label [LABEL]", "Set up custom label for the release summary section. Default is \"\".") do |v|
options[:summary_prefix] = v
end
opts.on("--breaking-label [LABEL]", "Set up custom label for the breaking changes section. Default is \"**Breaking changes:**\".") do |v|
options[:breaking_prefix] = v
end
Expand Down Expand Up @@ -131,6 +134,9 @@ def self.setup_parser(options)
opts.on("--exclude-labels x,y,z", Array, "Issues with the specified labels will be excluded from changelog. Default is 'duplicate,question,invalid,wontfix'.") do |list|
options[:exclude_labels] = list
end
opts.on("--summary-labels x,y,z", Array, 'Issues with these labels will be added to a new section, called "Release Summary". The section display only body of issues. Default is \'release-summary,summary\'.') do |list|
options[:summary_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,breaking\'.') do |list|
options[:breaking_labels] = list
end
Expand Down Expand Up @@ -230,6 +236,7 @@ def self.default_options
unreleased_label: "Unreleased",
compare_link: true,
exclude_labels: ["duplicate", "question", "invalid", "wontfix", "Duplicate", "Question", "Invalid", "Wontfix", "Meta: Exclude From Changelog"],
summary_labels: ["Release summary", "release-summary", "Summary", "summary"],
breaking_labels: ["backwards-incompatible", "Backwards incompatible", "breaking"],
enhancement_labels: ["enhancement", "Enhancement", "Type: Enhancement"],
bug_labels: ["bug", "Bug", "Type: Bug"],
Expand All @@ -246,6 +253,7 @@ def self.default_options
header: "# Changelog",
merge_prefix: "**Merged pull requests:**",
issue_prefix: "**Closed issues:**",
summary_prefix: "",
breaking_prefix: "**Breaking changes:**",
enhancement_prefix: "**Implemented enhancements:**",
bug_prefix: "**Fixed bugs:**",
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 @@ -67,7 +67,7 @@ def extract_pair(line)
end

KNOWN_ARRAY_KEYS = %i[exclude_labels include_labels
breaking_labels enhancement_labels bug_labels
summary_labels breaking_labels enhancement_labels bug_labels
deprecated_labels removed_labels security_labels
issue_line_labels between_tags exclude_tags]
KNOWN_INTEGER_KEYS = [:max_issues]
Expand Down
14 changes: 13 additions & 1 deletion man/git-generate-changelog.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-GENERATE\-CHANGELOG" "1" "April 2018" "" ""
.TH "GIT\-GENERATE\-CHANGELOG" "1" "May 2018" "" ""
.
.SH "NAME"
\fBgit\-generate\-changelog\fR \- Generate changelog from GitHub
Expand Down Expand Up @@ -49,6 +49,12 @@ Output file\. To print to STDOUT instead, use blank as path\. Default is CHANGEL
Optional base file to append generated changes to\.
.
.P
\-\-summary\-label [LABEL]
.
.P
Set up custom label for the release summary section\. Default is ""\.
.
.P
\-\-breaking\-label [LABEL]
.
.P
Expand Down Expand Up @@ -199,6 +205,12 @@ Of the labeled issues, only include the ones with the specified labels\.
Issues with the specified labels will be excluded from changelog\. Default is \'duplicate,question,invalid,wontfix\'\.
.
.P
\-\-summary\-labels x,y,z
.
.P
Issues with these labels will be added to a new section, called "Release Summary"\. The section display only body of issues\. Default is \'Release summary,release\-summary,Summary,summary\'\.
.
.P
\-\-breaking\-labels x,y,z
.
.P
Expand Down
10 changes: 9 additions & 1 deletion man/git-generate-changelog.1.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/git-generate-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Automatically generate changelog from your tags, issues, labels and pull request

Optional base file to append generated changes to.

--summary-label [LABEL]

Set up custom label for the release summary section. Default is "".

--breaking-label [LABEL]

Set up custom label for breaking changes section. Default is "**Breaking changes:**".
Expand Down Expand Up @@ -135,6 +139,10 @@ Automatically generate changelog from your tags, issues, labels and pull request

Issues with the specified labels will be excluded from changelog. Default is 'duplicate,question,invalid,wontfix'.

--summary-labels x,y,z

Issues with these labels will be added to a new section, called "Release Summary". The section display only body of issues. Default is 'Release summary,release-summary,Summary,summary'.

--breaking-labels x,y,z

Issues with these labels will be added to a new section, called "Breaking changes". Default is 'backwards-incompatible,breaking'.
Expand Down

0 comments on commit 05de5ec

Please sign in to comment.