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 contributors on own line option #1004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions lib/github_changelog_generator/argv_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def parser
opts.on("--[no-]verbose", "Run verbosely. Default is true.") do |v|
options[:verbose] = v
end
opts.on("--contributors-on-own-line", "Place contributors on their own line in italics. Default is false.") do |v|
options[:verbose] = v
end
opts.on("-v", "--version", "Print version number.") do |_v|
puts "Version: #{GitHubChangelogGenerator::VERSION}"
exit
Expand Down
17 changes: 11 additions & 6 deletions lib/github_changelog_generator/generator/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def generate_content
merge_string = get_string_for_issue(issue)
content += "- " unless @body_only
content += "#{merge_string}\n"
content += "\n" if @options[:contributors_on_own_line] && issue["pull_request"] && issue != @issues.last
end
content += "\n"
end
Expand Down Expand Up @@ -97,14 +98,18 @@ def body_till_first_break(body)
def issue_line_with_user(line, issue)
return line if !@options[:author] || issue["pull_request"].nil?

user = issue["user"]
user = user(issue["user"])
return "#{line} ({Null user})" unless user
Copy link

Choose a reason for hiding this comment

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

GitHubChangelogGenerator::Section#user seems to only return String as far as I see, so I think this line is no longer needed.

Suggested change
return "#{line} ({Null user})" unless user


if @options[:usernames_as_github_logins]
"#{line} (@#{user['login']})"
else
"#{line} ([#{user['login']}](#{user['html_url']}))"
end
return "#{line} (#{user})" unless @options[:contributors_on_own_line]

"#{line}\n\n *#{user}*"
end

def user(user)
return "{Null user}" unless user

@options[:usernames_as_github_logins] ? "@#{user['login']}" : "[#{user['login']}](#{user['html_url']})"
end

ENCAPSULATED_CHARACTERS = %w(< > * _ \( \) [ ] #)
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 @@ -28,6 +28,7 @@ class Options < SimpleDelegator
config_file
compare_link
configure_sections
contributors_on_own_line
date_format
deprecated_labels
deprecated_prefix
Expand Down
3 changes: 2 additions & 1 deletion lib/github_changelog_generator/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def default_options
security_prefix: "**Security fixes:**",
http_cache: true,
require: [],
config_file: ".github_changelog_generator"
config_file: ".github_changelog_generator",
contributors_on_own_line: false
)
end
end
Expand Down
101 changes: 101 additions & 0 deletions spec/unit/generator/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,107 @@ def default_sections
end

subject { described_class.new(options) }

describe "contributors on own line" do
let(:options) do
Parser.default_options.merge(
user: "owner",
project: "repo",
breaking_labels: ["breaking"],
enhancement_labels: ["enhancement"],
bug_labels: ["bug"],
deprecated_labels: ["deprecated"],
removed_labels: ["removed"],
security_labels: ["security"],
verbose: false,
contributors_on_own_line: true
)
end

it "generates a header and body" do
changelog = <<-CHANGELOG.gsub(/^ {10}/, "")
## [1.0.1](https://github.com/owner/repo/tree/1.0.1) (2017-12-04)

[Full Changelog](https://github.com/owner/repo/compare/1.0.0...1.0.1)

**Breaking changes:**

- issue breaking [\\#8](https://github.com/owner/repo/issue/8)
- issue all the labels [\\#9](https://github.com/owner/repo/issue/9)
- issue all the labels different order [\\#10](https://github.com/owner/repo/issue/10)
- pr breaking [\\#23](https://github.com/owner/repo/pull/23)

*[user5](https://github.com/user5)*

- pr all the labels [\\#24](https://github.com/owner/repo/pull/24)

*[user5](https://github.com/user5)*

- pr all the labels different order [\\#25](https://github.com/owner/repo/pull/25)

*[user5](https://github.com/user5)*

**Implemented enhancements:**

- issue enhancement [\\#6](https://github.com/owner/repo/issue/6)
- pr enhancement [\\#21](https://github.com/owner/repo/pull/21)

*[user5](https://github.com/user5)*

**Fixed bugs:**

- issue bug [\\#7](https://github.com/owner/repo/issue/7)
- issue some unmapped labels [\\#11](https://github.com/owner/repo/issue/11)
- pr bug [\\#22](https://github.com/owner/repo/pull/22)

*[user5](https://github.com/user5)*

- pr some unmapped labels [\\#26](https://github.com/owner/repo/pull/26)

*[user5](https://github.com/user5)*

**Deprecated:**

- issue deprecated [\\#13](https://github.com/owner/repo/issue/13)
- pr deprecated [\\#28](https://github.com/owner/repo/pull/28)

*[user5](https://github.com/user5)*

**Removed:**

- issue removed [\\#14](https://github.com/owner/repo/issue/14)
- pr removed [\\#29](https://github.com/owner/repo/pull/29)

*[user2](https://github.com/user2)*

**Security fixes:**

- issue security [\\#15](https://github.com/owner/repo/issue/15)
- pr security [\\#30](https://github.com/owner/repo/pull/30)

*[user5](https://github.com/user5)*

**Closed issues:**

- issue no labels [\\#5](https://github.com/owner/repo/issue/5)
- issue no mapped labels [\\#12](https://github.com/owner/repo/issue/12)

**Merged pull requests:**

- pr no labels [\\#20](https://github.com/owner/repo/pull/20)

*[user1](https://github.com/user1)*

- pr no mapped labels [\\#27](https://github.com/owner/repo/pull/27)

*[user5](https://github.com/user5)*

CHANGELOG

expect(subject.generate_entry_for_tag(pull_requests, issues, "1.0.1", "1.0.1", Time.new(2017, 12, 4, 12, 0, 0, "+00:00").utc, "1.0.0")).to eq(changelog)
end
end

describe "include issues without labels" do
let(:options) do
Parser.default_options.merge(
Expand Down