diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b1b6fb16..7ab6a16e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## [1.2.4] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.4) +#### 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:* Implement async fetching [\#39](https://github.com/skywinder/Github-Changelog-Generator/pull/39) ([skywinder](https://github.com/skywinder)) + +- *Implemented enhancement:* Add ability to run with one parameter instead -u -p [\#38](https://github.com/skywinder/Github-Changelog-Generator/issues/38) + +- *Implemented enhancement:* Detailed output [\#33](https://github.com/skywinder/Github-Changelog-Generator/issues/33) + +- *Fixed bug:* Docs lacking or basic behavior not as advertised [\#30](https://github.com/skywinder/Github-Changelog-Generator/issues/30) + +## [1.2.3] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.3) +#### 16/12/14 +- *Fixed bug:* Encapsulate \[ \> \* \_ \ \] signs in issues names [\#34](https://github.com/skywinder/Github-Changelog-Generator/issues/34) + ## [1.2.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/1.2.2) #### 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)) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 300c5bb51..646c20fa1 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -28,12 +28,12 @@ def initialize github_token - if @github_token.nil? - @github = Github.new per_page: PER_PAGE_NUMBER - else - @github = Github.new oauth_token: @github_token, - per_page: PER_PAGE_NUMBER - end + github_options = {per_page: PER_PAGE_NUMBER} + github_options[:oauth_token] = @github_token unless @github_token.nil? + github_options[:endpoint] = options[:github_endpoint] unless options[:github_endpoint].nil? + github_options[:site] = options[:github_endpoint] unless options[:github_site].nil? + + @github = Github.new github_options @generator = Generator.new(@options) @@ -231,6 +231,11 @@ def github_token def generate_log_between_tags(older_tag, newer_tag) + if newer_tag.nil? + puts "Can't find tag -> terminate" + exit 1 + end + newer_tag_time = self.get_time_of_tag(newer_tag) newer_tag_name = newer_tag['name'] @@ -243,6 +248,43 @@ def generate_log_between_tags(older_tag, newer_tag) filtered_issues = delete_by_time(@issues, :closed_at, newer_tag_time, older_tag_time) end + + if @options[:filter_issues_by_milestone] + #delete excess irrelevant issues (according milestones) + filtered_issues.select! { |issue| + if issue.milestone.nil? + true + else + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find { |tag| + tag.name == issue.milestone.title + } + milestone_is_tag.nil? + end + + } + + #add missed issues (according milestones) + issues_to_add = @issues.select { |issue| + if issue.milestone.nil? + false + else + #check, that this milestone in tag list: + milestone_is_tag = @all_tags.find { |tag| + tag.name == issue.milestone.title + } + + if milestone_is_tag.nil? + false + else + issue.milestone.title == newer_tag_name + end + end + } + + filtered_issues |= issues_to_add + end + self.create_log(filtered_pull_requests, filtered_issues, newer_tag_name, newer_tag_time) end @@ -276,8 +318,10 @@ def delete_by_time(array, hash_key, newer_tag_time, older_tag_time = nil) # @return [String] def create_log(pull_requests, issues, tag_name, tag_time) + github_site = options[:github_site] || 'https://github.com' + # Generate tag name and link - log = "## [#{tag_name}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n" + log = "## [#{tag_name}] (#{github_site}/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n" #Generate date string: time_string = tag_time.strftime @options[:format] diff --git a/lib/github_changelog_generator/generator.rb b/lib/github_changelog_generator/generator.rb index 5680f4118..0c08a3d4e 100644 --- a/lib/github_changelog_generator/generator.rb +++ b/lib/github_changelog_generator/generator.rb @@ -10,10 +10,10 @@ def get_string_for_pull_request(pull_request) merge = "#{@options[:merge_prefix]}#{encapsulated_title} [\\##{pull_request[:number]}](#{pull_request.html_url})" if @options[:author] - if !pull_request.user.nil? - merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" - else + if pull_request.user.nil? merge += " ({Null user})\n\n" + else + merge += " ([#{pull_request.user.login}](#{pull_request.user.html_url}))\n\n" end else merge += "\n\n" diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index e193b9b85..b927b9a48 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -1,12 +1,12 @@ #!/usr/bin/env ruby require 'optparse' -require 'PP' +require 'pp' require_relative 'version' module GitHubChangelogGenerator class Parser 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} + 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} parser = OptionParser.new { |opts| opts.banner = 'Usage: changelog_generator [options]' @@ -37,6 +37,9 @@ def self.parse_options opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v| options[:pulls] = v end + opts.on('--[no-]filter-issues-by-milestone', 'Use milestone to detect when issue was resolved. Default is true') do |last| + options[:filter_issues_by_milestone] = last + end opts.on('--[no-]author', 'Add author of pull-request in the end. Default is true') do |author| options[:last] = author end @@ -46,6 +49,12 @@ def self.parse_options opts.on('--labels-pr x,y,z', Array, 'Only pull requests with specified labels will be included to changelog. Default is nil') do |list| options[:pull_request_labels] = list end + opts.on('--github-site [URL]', 'The Enterprise Github site on which your project is hosted.') do |last| + options[:github_site] = last + end + opts.on('--github-api [URL]', 'The enterprise endpoint to use for your Github API.') do |last| + options[:github_endpoint] = last + end opts.on('-v', '--version', 'Print version number') do |v| puts "Version: #{GitHubChangelogGenerator::VERSION}" exit @@ -59,8 +68,9 @@ def self.parse_options parser.parse! if ARGV[0] && !ARGV[1] + github_site = options[:github_site] ? options[:github_site] : 'github.com' # this match should parse https://github.com/skywinder/Github-Changelog-Generator and skywinder/Github-Changelog-Generator to user and name - match = /(?:.+github\.com\/)?(.+)\/(.+)/.match(ARGV[0]) + match = /(?:.+#{Regexp.escape(github_site)}\/)?(.+)\/(.+)/.match(ARGV[0]) if match[2].nil? exit @@ -94,4 +104,4 @@ def self.parse_options options end end -end \ No newline at end of file +end diff --git a/lib/github_changelog_generator/version.rb b/lib/github_changelog_generator/version.rb index 4d93f7471..78538567d 100644 --- a/lib/github_changelog_generator/version.rb +++ b/lib/github_changelog_generator/version.rb @@ -1,3 +1,3 @@ module GitHubChangelogGenerator - VERSION = '1.2.4' + VERSION = '1.2.5' end