Merge pull request #46 from sue445/feature/compare_link

Add compare link between older version and newer version
This commit is contained in:
Petr Korolev 2015-01-26 16:58:34 +02:00
commit 1940974c4c
3 changed files with 39 additions and 11 deletions

View File

@ -1,10 +1,12 @@
# Changelog # Changelog
## [1.2.6](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.6) ## [1.2.6](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.6)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.5...1.2.6)
#### 21/01/15 #### 21/01/15
- *Merged pull-request:* fix link tag format [\#45](https://github.com/skywinder/Github-Changelog-Generator/pull/45) ([sugamasao](https://github.com/sugamasao)) - *Merged pull-request:* fix link tag format [\#45](https://github.com/skywinder/Github-Changelog-Generator/pull/45) ([sugamasao](https://github.com/sugamasao))
## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5) ## [1.2.5](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.5)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.4...1.2.5)
#### 15/01/15 #### 15/01/15
- *Merged pull-request:* PrettyPrint class is included using lowercase 'pp' [\#43](https://github.com/skywinder/Github-Changelog-Generator/pull/43) ([schwing](https://github.com/schwing)) - *Merged pull-request:* PrettyPrint class is included using lowercase 'pp' [\#43](https://github.com/skywinder/Github-Changelog-Generator/pull/43) ([schwing](https://github.com/schwing))
@ -15,6 +17,7 @@
- *Fixed bug:* Error when trying to generate log for repo without tags [\#32](https://github.com/skywinder/Github-Changelog-Generator/issues/32) - *Fixed bug:* Error when trying to generate log for repo without tags [\#32](https://github.com/skywinder/Github-Changelog-Generator/issues/32)
## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) ## [1.2.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.3...1.2.4)
#### 16/12/14 #### 16/12/14
- *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Fix crash when user is NULL [\#40](https://github.com/skywinder/Github-Changelog-Generator/pull/40) ([skywinder](https://github.com/skywinder))
@ -29,14 +32,17 @@
- *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35) - *Fixed bug:* Crash when try generate log for rails [\#35](https://github.com/skywinder/Github-Changelog-Generator/issues/35)
## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) ## [1.2.3](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.2...1.2.3)
#### 16/12/14 #### 16/12/14
## [1.2.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) ## [1.2.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.1...1.2.2)
#### 10/12/14 #### 10/12/14
- *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef)) - *Merged pull-request:* Add a Bitdeli Badge to README [\#36](https://github.com/skywinder/Github-Changelog-Generator/pull/36) ([bitdeli-chef](https://github.com/bitdeli-chef))
- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) - *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34)
## [1.2.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1) ## [1.2.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.1)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.2.0...1.2.1)
#### 22/11/14 #### 22/11/14
- *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Issues for last tag not in list [\#29](https://github.com/skywinder/Github-Changelog-Generator/pull/29) ([skywinder](https://github.com/skywinder))
@ -45,6 +51,7 @@
- *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20) - *Fixed bug:* Script fills changelog only for first 30 tags. [\#20](https://github.com/skywinder/Github-Changelog-Generator/issues/20)
## [1.2.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0) ## [1.2.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.0)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.4...1.2.0)
#### 19/11/14 #### 19/11/14
- *Merged pull-request:* Add filter for pull-requests labels. \(option --filter-pull-requests\) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add filter for pull-requests labels. \(option --filter-pull-requests\) [\#27](https://github.com/skywinder/Github-Changelog-Generator/pull/27) ([skywinder](https://github.com/skywinder))
@ -55,18 +62,21 @@
- *Merged pull-request:* Don't receive issues in case of --no-isses flag specied [\#24](https://github.com/skywinder/Github-Changelog-Generator/pull/24) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Don't receive issues in case of --no-isses flag specied [\#24](https://github.com/skywinder/Github-Changelog-Generator/pull/24) ([skywinder](https://github.com/skywinder))
## [1.1.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4) ## [1.1.4](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.4)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.2...1.1.4)
#### 18/11/14 #### 18/11/14
- *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Sort tags by date [\#23](https://github.com/skywinder/Github-Changelog-Generator/pull/23) ([skywinder](https://github.com/skywinder))
- *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable \(to not put it to script directly\) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19) - *Implemented enhancement:* Implement ability to retrieve GitHub token from ENV variable \(to not put it to script directly\) [\#19](https://github.com/skywinder/Github-Changelog-Generator/issues/19)
## [1.1.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2) ## [1.1.2](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.2)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.1...1.1.2)
#### 12/11/14 #### 12/11/14
- *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Fix bug with dot signs in project name [\#18](https://github.com/skywinder/Github-Changelog-Generator/pull/18) ([skywinder](https://github.com/skywinder))
- *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Fix bug with dot signs in user name [\#17](https://github.com/skywinder/Github-Changelog-Generator/pull/17) ([skywinder](https://github.com/skywinder))
## [1.1.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1) ## [1.1.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.1)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.1.0...1.1.1)
#### 10/11/14 #### 10/11/14
- *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Remove duplicates of issues and pull-requests with same number [\#15](https://github.com/skywinder/Github-Changelog-Generator/pull/15) ([skywinder](https://github.com/skywinder))
@ -75,6 +85,7 @@
- *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add ability to add or exclude issues without any labels [\#13](https://github.com/skywinder/Github-Changelog-Generator/pull/13) ([skywinder](https://github.com/skywinder))
## [1.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0) ## [1.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.1.0)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.1...1.1.0)
#### 10/11/14 #### 10/11/14
- *Implemented enhancement:* Detect username and project form origin [\#11](https://github.com/skywinder/Github-Changelog-Generator/issues/11) - *Implemented enhancement:* Detect username and project form origin [\#11](https://github.com/skywinder/Github-Changelog-Generator/issues/11)
@ -83,10 +94,12 @@
- *Fixed bug:* Bug with wrong credentials in 1.0.1 [\#12](https://github.com/skywinder/Github-Changelog-Generator/issues/12) - *Fixed bug:* Bug with wrong credentials in 1.0.1 [\#12](https://github.com/skywinder/Github-Changelog-Generator/issues/12)
## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1) ## [1.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.1)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/1.0.0...1.0.1)
#### 10/11/14 #### 10/11/14
- *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Implement support of different tags. [\#8](https://github.com/skywinder/Github-Changelog-Generator/pull/8) ([skywinder](https://github.com/skywinder))
## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0) ## [1.0.0](https://github.com/skywinder/Github-Changelog-Generator/tree/1.0.0)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.1.0...1.0.0)
#### 07/11/14 #### 07/11/14
- *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add support for issues in CHANGELOG [\#7](https://github.com/skywinder/Github-Changelog-Generator/pull/7) ([skywinder](https://github.com/skywinder))
@ -99,12 +112,14 @@
- *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5) - *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5)
## [0.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) ## [0.1.0](https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.2...0.1.0)
#### 07/11/14 #### 07/11/14
- *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) ([skywinder](https://github.com/skywinder))
- *Merged pull-request:* Add option \(-o --output\) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) ([skywinder](https://github.com/skywinder)) - *Merged pull-request:* Add option \(-o --output\) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) ([skywinder](https://github.com/skywinder))
## [0.0.2](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2) ## [0.0.2](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2)
[Full Changelog](https://github.com/skywinder/Github-Changelog-Generator/compare/0.0.1...0.0.2)
#### 06/11/14 #### 06/11/14
## [0.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1) ## [0.0.1](https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1)
#### 06/11/14 #### 06/11/14

View File

@ -240,10 +240,12 @@ module GitHubChangelogGenerator
newer_tag_name = newer_tag['name'] newer_tag_name = newer_tag['name']
if older_tag.nil? if older_tag.nil?
older_tag_name = nil
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time) filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time)
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time) filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time)
else else
older_tag_time = self.get_time_of_tag(older_tag) older_tag_time = self.get_time_of_tag(older_tag)
older_tag_name = older_tag['name']
filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time) filtered_pull_requests = delete_by_time(@pull_requests, :merged_at, newer_tag_time, older_tag_time)
filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time) filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time)
end end
@ -285,7 +287,7 @@ module GitHubChangelogGenerator
filtered_issues |= issues_to_add filtered_issues |= issues_to_add
end end
self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time) self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time, older_tag_name)
end end
@ -311,20 +313,28 @@ module GitHubChangelogGenerator
} }
end end
# @param [Array] pull_requests # @param [Array] pull_requests
# @param [Array] issues # @param [Array] issues
# @param [String] tag_name # @param [String] newer_tag_name
# @param [String] tag_time # @param [String] newer_tag_time
# @return [String] # @param [String] older_tag_name
def create_log(pull_requests, issues, tag_name, tag_time) # @return [String]
def create_log(pull_requests, issues, newer_tag_name, newer_tag_time, older_tag_name = nil)
github_site = options[:github_site] || 'https://github.com' github_site = options[:github_site] || 'https://github.com'
project_url = "#{github_site}/#{@options[:user]}/#{@options[:project]}"
# Generate tag name and link # Generate tag name and link
log = "## [#{tag_name}](#{github_site}/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n" log = "## [#{newer_tag_name}](#{project_url}/tree/#{newer_tag_name})\n"
if @options[:compare_link] && older_tag_name
# Generate compare link
log += "[Full Changelog](#{project_url}/compare/#{older_tag_name}...#{newer_tag_name})\n"
end
#Generate date string: #Generate date string:
time_string = tag_time.strftime @options[:format] time_string = newer_tag_time.strftime @options[:format]
log += "#### #{time_string}\n" log += "#### #{time_string}\n"
if @options[:pulls] if @options[:pulls]

View File

@ -6,7 +6,7 @@ require_relative 'version'
module GitHubChangelogGenerator module GitHubChangelogGenerator
class Parser class Parser
def self.parse_options def self.parse_options
options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :pull_request_labels => nil, :filter_issues_by_milestone => true} options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true, :verbose => true, :add_issues_wo_labels => true, :merge_prefix => '*Merged pull-request:* ', :author => true, :pull_request_labels => nil, :filter_issues_by_milestone => true, :compare_link => true}
parser = OptionParser.new { |opts| parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator [options]' opts.banner = 'Usage: changelog_generator [options]'
@ -43,6 +43,9 @@ module GitHubChangelogGenerator
opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author| opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author|
options[:last] = author options[:last] = author
end end
opts.on('--[no-]compare-link', 'Include compare link between older version and newer version. Default is true') do |v|
options[:compare_link] = v
end
opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list| opts.on('--labels x,y,z', Array, 'Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list|
options[:labels] = list options[:labels] = list
end end