Compare commits

..

3 Commits

Author SHA1 Message Date
Petr Korolev
8941eb8280 Merge branch 'master' into abonas-fixComparingPRByMergedAtField 2015-08-24 12:57:59 +03:00
Petr Korolev
905a04fb75 update changelog 2015-08-24 12:57:33 +03:00
Alissa Bonas
30b7f39c40 Fix comparing pull requests between tags by merged_at field instead of actual_date field 2015-08-23 18:08:07 +03:00
14 changed files with 244 additions and 394 deletions

View File

@@ -2,28 +2,13 @@
## [Unreleased](https://github.com/skywinder/github-changelog-generator/tree/HEAD) ## [Unreleased](https://github.com/skywinder/github-changelog-generator/tree/HEAD)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.8.0...HEAD) [Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.7.0...HEAD)
**Merged pull requests:** **Merged pull requests:**
- Fix issue with missing events \(in case of events for issue \>30\) [\#268](https://github.com/skywinder/github-changelog-generator/pull/268) ([skywinder](https://github.com/skywinder))
- Use since\_tag as default for older\_tag [\#267](https://github.com/skywinder/github-changelog-generator/pull/267) ([raphink](https://github.com/raphink))
## [1.8.0](https://github.com/skywinder/github-changelog-generator/tree/1.8.0) (2015-08-24)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.7.0...1.8.0)
**Implemented enhancements:**
- Generate change log since/due specific tag [\#254](https://github.com/skywinder/github-changelog-generator/issues/254)
**Merged pull requests:**
- Add `--due-tag` option [\#265](https://github.com/skywinder/github-changelog-generator/pull/265) ([skywinder](https://github.com/skywinder))
- Add release\_url to rake task options [\#264](https://github.com/skywinder/github-changelog-generator/pull/264) ([raphink](https://github.com/raphink))
- Add a rake task [\#260](https://github.com/skywinder/github-changelog-generator/pull/260) ([raphink](https://github.com/raphink)) - Add a rake task [\#260](https://github.com/skywinder/github-changelog-generator/pull/260) ([raphink](https://github.com/raphink))
- Add release\_url option [\#259](https://github.com/skywinder/github-changelog-generator/pull/259) ([raphink](https://github.com/raphink)) - Add release\_url option [\#259](https://github.com/skywinder/github-changelog-generator/pull/259) ([raphink](https://github.com/raphink))
- Add --base option [\#258](https://github.com/skywinder/github-changelog-generator/pull/258) ([raphink](https://github.com/raphink)) - Add --since-tag, close [\#257](https://github.com/skywinder/github-changelog-generator/pull/257) ([raphink](https://github.com/raphink))
- Add --since-tag [\#257](https://github.com/skywinder/github-changelog-generator/pull/257) ([raphink](https://github.com/raphink))
## [1.7.0](https://github.com/skywinder/github-changelog-generator/tree/1.7.0) (2015-07-16) ## [1.7.0](https://github.com/skywinder/github-changelog-generator/tree/1.7.0) (2015-07-16)
[Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.6.2...1.7.0) [Full Changelog](https://github.com/skywinder/github-changelog-generator/compare/1.6.2...1.7.0)

View File

@@ -1,7 +1,7 @@
PATH PATH
remote: . remote: .
specs: specs:
github_changelog_generator (1.8.0) github_changelog_generator (1.7.0)
colorize (~> 0.7) colorize (~> 0.7)
github_api (~> 0.12) github_api (~> 0.12)
@@ -29,13 +29,13 @@ GEM
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
faraday (0.9.1) faraday (0.9.1)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
github_api (0.12.4) github_api (0.12.3)
addressable (~> 2.3) addressable (~> 2.3)
descendants_tracker (~> 0.0.4) descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10) faraday (~> 0.8, < 0.10)
hashie (>= 3.4) hashie (>= 3.3)
multi_json (>= 1.7.5, < 2.0) multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.6) nokogiri (~> 1.6.3)
oauth2 oauth2
hashie (3.4.2) hashie (3.4.2)
http-cookie (1.0.2) http-cookie (1.0.2)
@@ -112,6 +112,3 @@ DEPENDENCIES
rspec (~> 3.2) rspec (~> 3.2)
rubocop (~> 0.31) rubocop (~> 0.31)
simplecov (~> 0.10) simplecov (~> 0.10)
BUNDLED WITH
1.10.6

View File

@@ -92,7 +92,7 @@ Since GitHub allows you to make only 50 requests without authentication it's rec
And: And:
- Run with key `-t [your-40-digit-token]` - Run with key `-t [your-16-digit-token]`
- Or set environment variable `CHANGELOG_GITHUB_TOKEN` and specify there your token. - Or set environment variable `CHANGELOG_GITHUB_TOKEN` and specify there your token.
i.e. add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string : i.e. add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string :
@@ -104,14 +104,6 @@ So, if you got error like this:
It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP. It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP.
## Migrating from a manual changelog
Knowing how dedicated you are to your project, you probably haven't been waiting for github-changelog-generator to keep a changelog,
but you most likely wouln't like to have to open issues and PRs for all past features listed in your historic changelog.
That's where `--base` comes handy. This option lets you pass a static changelog to be appended at the end of the generated entries.
If you have a `HISTORY.md` file in your project, it will automatically be picked as the static historical changelog and appended.
### Rake task ### Rake task

View File

@@ -21,8 +21,6 @@
**Merged pull requests:** **Merged pull requests:**
- This a PR with a lot of comments and events [\#17](https://github.com/skywinder/changelog_test/pull/17) ([skywinder](https://github.com/skywinder))
- PR [\#16](https://github.com/skywinder/changelog_test/pull/16) ([skywinder](https://github.com/skywinder))
- This PR closes 14 from commit [\#15](https://github.com/skywinder/changelog_test/pull/15) ([skywinder](https://github.com/skywinder)) - This PR closes 14 from commit [\#15](https://github.com/skywinder/changelog_test/pull/15) ([skywinder](https://github.com/skywinder))
- This PR to close \#12 from body [\#13](https://github.com/skywinder/changelog_test/pull/13) ([skywinder](https://github.com/skywinder)) - This PR to close \#12 from body [\#13](https://github.com/skywinder/changelog_test/pull/13) ([skywinder](https://github.com/skywinder))

View File

@@ -163,13 +163,10 @@ Make sure, that you push tags to remote repo via 'git push --tags'".yellow
issues_slice.each do |issue| issues_slice.each do |issue|
threads << Thread.new do threads << Thread.new do
begin begin
response = @github.issues.events.list user: @options[:user], obj = @github.issues.events.list user: @options[:user],
repo: @options[:project], repo: @options[:project],
issue_number: issue["number"] issue_number: issue["number"]
issue[:events] = [] issue[:events] = obj.body
response.each_page do |page|
issue[:events].concat(page)
end
rescue rescue
Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow Helper.log.warn GH_RATE_LIMIT_EXCEEDED_MSG.yellow
end end

View File

@@ -66,7 +66,7 @@ module GitHubChangelogGenerator
if @options[:issues] if @options[:issues]
# Generate issues: # Generate issues:
log += issues_to_log(issues, pull_requests) log += issues_to_log(issues)
end end
if @options[:pulls] if @options[:pulls]
@@ -77,14 +77,13 @@ module GitHubChangelogGenerator
log log
end end
# Generate ready-to-paste log from list of issues and pull requests. # Generate ready-to-paste log from list of issues.
# #
# @param [Array] issues # @param [Array] issues
# @param [Array] pull_requests
# @return [String] generated log for issues # @return [String] generated log for issues
def issues_to_log(issues, pull_requests) def issues_to_log(issues)
log = "" log = ""
bugs_a, enhancement_a, issues_a = parse_by_sections(issues, pull_requests) bugs_a, enhancement_a, issues_a = parse_by_sections(issues)
log += generate_sub_section(enhancement_a, @options[:enhancement_prefix]) log += generate_sub_section(enhancement_a, @options[:enhancement_prefix])
log += generate_sub_section(bugs_a, @options[:bug_prefix]) log += generate_sub_section(bugs_a, @options[:bug_prefix])
@@ -96,9 +95,8 @@ module GitHubChangelogGenerator
# (bugs, features, or just closed issues) by labels # (bugs, features, or just closed issues) by labels
# #
# @param [Array] issues # @param [Array] issues
# @param [Array] pull_requests
# @return [Array] tuple of filtered arrays: (Bugs, Enhancements Issues) # @return [Array] tuple of filtered arrays: (Bugs, Enhancements Issues)
def parse_by_sections(issues, pull_requests) def parse_by_sections(issues)
issues_a = [] issues_a = []
enhancement_a = [] enhancement_a = []
bugs_a = [] bugs_a = []
@@ -119,24 +117,6 @@ module GitHubChangelogGenerator
end end
issues_a.push dict unless added issues_a.push dict unless added
end end
pull_requests.each do |dict|
added = false
dict.labels.each do |label|
if @options[:bug_labels].include? label.name
bugs_a.push dict
added = true
next
end
if @options[:enhancement_labels].include? label.name
enhancement_a.push dict
added = true
next
end
end
pull_requests.delete(dict) if added
end
[bugs_a, enhancement_a, issues_a] [bugs_a, enhancement_a, issues_a]
end end
end end

View File

@@ -48,11 +48,11 @@ module GitHubChangelogGenerator
# Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit. # Fill :actual_date parameter of specified issue by closed date of the commit, if it was closed by commit.
# @param [Hash] issue # @param [Hash] issue
def find_closed_date_by_commit(issue) def find_closed_date_by_commit(issue)
unless issue[:events].nil? unless issue["events"].nil?
# if it's PR -> then find "merged event", in case of usual issue -> fond closed date # if it's PR -> then find "merged event", in case of usual issue -> fond closed date
compare_string = issue[:merged_at].nil? ? "closed" : "merged" compare_string = issue[:merged_at].nil? ? "closed" : "merged"
# reverse! - to find latest closed event. (event goes in date order) # reverse! - to find latest closed event. (event goes in date order)
issue[:events].reverse!.each do |event| issue["events"].reverse!.each do |event|
if event[:event].eql? compare_string if event[:event].eql? compare_string
set_date_from_event(event, issue) set_date_from_event(event, issue)
break break

View File

@@ -16,8 +16,6 @@ module GitHubChangelogGenerator
log += generate_log_for_all_tags log += generate_log_for_all_tags
end end
log += File.read(@options[:base]) if File.file?(@options[:base])
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*" log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
@log = log @log = log
end end
@@ -103,7 +101,7 @@ module GitHubChangelogGenerator
def generate_log_between_tags(older_tag, newer_tag) def generate_log_between_tags(older_tag, newer_tag)
filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag) filtered_issues, filtered_pull_requests = filter_issues_for_tags(newer_tag, older_tag)
older_tag_name = older_tag.nil? ? detect_since_tag : older_tag["name"] older_tag_name = older_tag.nil? ? nil : older_tag["name"]
if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty? if newer_tag.nil? && filtered_issues.empty? && filtered_pull_requests.empty?
# do not generate empty unreleased section # do not generate empty unreleased section
@@ -117,7 +115,7 @@ module GitHubChangelogGenerator
# #
# @return [Array] filtered issues and pull requests # @return [Array] filtered issues and pull requests
def filter_issues_for_tags(newer_tag, older_tag) def filter_issues_for_tags(newer_tag, older_tag)
filtered_pull_requests = delete_by_time(@pull_requests, :actual_date, older_tag, newer_tag) filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, older_tag, newer_tag)
filtered_issues = delete_by_time(@issues, :actual_date, older_tag, newer_tag) filtered_issues = delete_by_time(@issues, :actual_date, older_tag, newer_tag)
newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"] newer_tag_name = newer_tag.nil? ? nil : newer_tag["name"]

View File

@@ -63,21 +63,21 @@ module GitHubChangelogGenerator
end end
# Method filter issues, that belong only specified tag range # Method filter issues, that belong only specified tag range
# @param [Array] issues issues to filter # @param [Array] array of issues to filter
# @param [Symbol] hash_key key of date value default is :actual_date # @param [Symbol] hash_key key of date value default is :actual_date
# @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag # @param [String] older_tag all issues before this tag date will be excluded. May be nil, if it's first tag
# @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section # @param [String] newer_tag all issue after this tag will be excluded. May be nil for unreleased section
# @return [Array] filtered issues # @return [Array] filtered issues
def delete_by_time(issues, hash_key = :actual_date, older_tag = nil, newer_tag = nil) def delete_by_time(array, hash_key = :actual_date, older_tag = nil, newer_tag = nil)
# in case if not tags specified - return unchanged array # in case if not tags specified - return unchanged array
return issues if older_tag.nil? && newer_tag.nil? return array if older_tag.nil? && newer_tag.nil?
newer_tag_time = newer_tag && get_time_of_tag(newer_tag) newer_tag_time = newer_tag && get_time_of_tag(newer_tag)
older_tag_time = older_tag && get_time_of_tag(older_tag) older_tag_time = older_tag && get_time_of_tag(older_tag)
issues.select do |issue| array.select do |req|
if issue[hash_key] if req[hash_key]
time = Time.parse(issue[hash_key]).utc time = Time.parse(req[hash_key]).utc
tag_in_range_old = tag_newer_old_tag?(older_tag_time, time) tag_in_range_old = tag_newer_old_tag?(older_tag_time, time)

View File

@@ -52,17 +52,6 @@ module GitHubChangelogGenerator
[newer_tag_link, newer_tag_name, newer_tag_time] [newer_tag_link, newer_tag_name, newer_tag_time]
end end
# @return [Object] try to find newest tag using #Reader and :base option if specified otherwise returns nil
def detect_since_tag
@since_tag ||= @options[:since_tag]
if @since_tag.nil? && @options[:base] && File.file?(@options[:base])
reader = GitHubChangelogGenerator::Reader.new
content = reader.read(@options[:base])
@since_tag = content[0]["version"] if content
end
@since_tag
end
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags # Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
# #
# @return [Array] # @return [Array]
@@ -72,11 +61,9 @@ module GitHubChangelogGenerator
filter_excluded_tags(filtered_tags) filter_excluded_tags(filtered_tags)
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :since_tag option
def filter_since_tag(all_tags) def filter_since_tag(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
tag = detect_since_tag tag = @options[:since_tag]
if tag if tag
if all_tags.map(&:name).include? tag if all_tags.map(&:name).include? tag
idx = all_tags.index { |t| t.name == tag } idx = all_tags.index { |t| t.name == tag }
@@ -92,29 +79,6 @@ module GitHubChangelogGenerator
filtered_tags filtered_tags
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :due_tag option
def filter_due_tag(all_tags)
filtered_tags = all_tags
tag = @options[:due_tag]
if tag
if (all_tags.count > 0) && (all_tags.map(&:name).include? tag)
idx = all_tags.index { |t| t.name == tag }
last_index = all_tags.count - 1
if idx > 0 && idx < last_index
filtered_tags = all_tags[idx + 1..last_index]
else
filtered_tags = []
end
else
Helper.log.warn "Warning: can't find tag #{tag}, specified with --due-tag option."
end
end
filtered_tags
end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :between_tags option
def filter_between_tags(all_tags) def filter_between_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:between_tags] if @options[:between_tags]
@@ -128,8 +92,6 @@ module GitHubChangelogGenerator
filtered_tags filtered_tags
end end
# @param [Array] all_tags all tags
# @return [Array] filtered tags according :exclude_tags option
def filter_excluded_tags(all_tags) def filter_excluded_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:exclude_tags] if @options[:exclude_tags]

View File

@@ -50,9 +50,6 @@ module GitHubChangelogGenerator
opts.on("-o", "--output [NAME]", "Output file. Default is CHANGELOG.md") do |last| opts.on("-o", "--output [NAME]", "Output file. Default is CHANGELOG.md") do |last|
options[:output] = last options[:output] = last
end end
opts.on("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last|
options[:base] = last
end
opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v| opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v|
options[:bug_prefix] = v options[:bug_prefix] = v
end end
@@ -119,9 +116,6 @@ module GitHubChangelogGenerator
opts.on("--since-tag x", "Change log will start after specified tag") do |v| opts.on("--since-tag x", "Change log will start after specified tag") do |v|
options[:since_tag] = v options[:since_tag] = v
end end
opts.on("--due-tag x", "Change log will end before specified tag") do |v|
options[:due_tag] = v
end
opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max| opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max|
options[:max_issues] = max options[:max_issues] = max
end end
@@ -162,7 +156,6 @@ module GitHubChangelogGenerator
tag2: nil, tag2: nil,
date_format: "%Y-%m-%d", date_format: "%Y-%m-%d",
output: "CHANGELOG.md", output: "CHANGELOG.md",
base: "HISTORY.md",
issues: true, issues: true,
add_issues_wo_labels: true, add_issues_wo_labels: true,
add_pr_wo_labels: true, add_pr_wo_labels: true,

View File

@@ -16,7 +16,7 @@ module GitHubChangelogGenerator
bug_labels enhancement_labels bug_labels enhancement_labels
between_tags exclude_tags since_tag max_issues between_tags exclude_tags since_tag max_issues
github_site github_endpoint simple_list github_site github_endpoint simple_list
future_release verbose release_url ) future_release verbose )
OPTIONS.each do |o| OPTIONS.each do |o|
attr_accessor o.to_sym attr_accessor o.to_sym

View File

@@ -1,3 +1,3 @@
module GitHubChangelogGenerator module GitHubChangelogGenerator
VERSION = "1.8.0" VERSION = "1.7.0"
end end

View File

@@ -90,70 +90,18 @@ describe GitHubChangelogGenerator::Generator do
end end
describe "#filter_since_tag" do describe "#filter_since_tag" do
context "with filled array" do subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
context "with valid since tag" do context "with valid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") } let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array } it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1))) } it { is_expected.to match_array(tags_mash_from_strings(%w(1))) }
end
context "with invalid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
end
end end
context "with empty array" do context "with invalid since tag" do
subject { generator.filter_since_tag(tags_mash_from_strings(%w())) } let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: %w(invalid tags)) }
it { is_expected.to be_a Array }
context "with valid since tag" do it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
context "with invalid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
end
end
describe "#filter_due_tag" do
context "with filled array" do
subject { generator.filter_due_tag(tags_mash_from_strings(%w(1 2 3))) }
context "with valid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(3))) }
end
context "with invalid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
end
end
context "with empty array" do
subject { generator.filter_due_tag(tags_mash_from_strings(%w())) }
context "with valid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
context "with invalid due tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(due_tag: "Invalid tag") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w())) }
end
end end
end end