From 3a78f97d61f1442409aa779b67e608ed5ed6b5d9 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 13:20:19 +0200 Subject: [PATCH 01/10] add changelog file --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..ea81ab5e7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog + +## [0.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) +#### 07/11/14 +- Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) + +- Add option (-o --output) to specify name of the output file. [\#1](https://github.com/skywinder/Github-Changelog-Generator/pull/1) + +## [0.0.2] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.2) +#### 06/11/14 +## [0.0.1] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.0.1) +#### 06/11/14 + + +*This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 4237b751a06da4bd7dd4a4da2590460bf68ecbd6 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 13:21:54 +0200 Subject: [PATCH 02/10] clean gitignore file --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index a64bd1285..e69de29bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +0,0 @@ -constants.rb -*.md From 8457b764bfe1e1662be3d65e12c470f24d3ff17e Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 13:52:23 +0200 Subject: [PATCH 03/10] update readme and bump gem --- README.md | 2 +- github_changelog_generator.gemspec | 2 +- lib/github_changelog_generator.rb | 4 +++- lib/github_changelog_generator/parser.rb | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c5cbce0a..eed0ef8c8 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ See `github_changelog_generator --help` for detailed usage. -v, --[no-]verbose Run verbosely -l, --last-changes Generate log between only last 2 tags -f, --date-format [FORMAT] Date format. Default is %d/%m/%y - -o, --output [FORMAT] Output file. Default is CHANGELOG.md + -o, --output [NAME] Output file. Default is CHANGELOG.md ## Examples: ### This changelog: [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 1e067fc58..2e7696cce 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "github_changelog_generator" - s.version = "0.0.2" + s.version = "0.1.0" s.default_executable = "github_changelog_generator" s.required_ruby_version = '>= 1.9.3' diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index ec41d919a..8e0736011 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -220,5 +220,7 @@ def get_time_of_tag(prev_tag) end if __FILE__ == $0 - ChangelogGenerator.new.compund_changelog + changelog_generator = ChangelogGenerator.new + # changelog_generator.compund_changelog + end \ No newline at end of file diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 0dc882a0d..68574a169 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -29,7 +29,7 @@ def self.parse_options opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last| options[:format] = last end - opts.on('-o', '--output [FORMAT]', 'Output file. Default is CHANGELOG.md') do |last| + opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last| options[:output] = last end } From f9e6a076bcf88ae417dc762e752ba0921e4c40fe Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 17:04:03 +0200 Subject: [PATCH 04/10] implement "issues" parsing + check for merged requests --- lib/github_changelog_generator.rb | 57 ++++++++++++------------ lib/github_changelog_generator/parser.rb | 10 ++++- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 8e0736011..fcdffa349 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -8,7 +8,7 @@ class ChangelogGenerator - attr_accessor :options, :all_tags + attr_accessor :options, :all_tags, :github def initialize() @@ -35,17 +35,14 @@ def exec_command(cmd) def get_all_closed_pull_requests - - - issues = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed' - json = issues.body + request = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed' + pull_requests = request.body if @options[:verbose] puts 'Receive all pull requests' end - json - + pull_requests end def compund_changelog @@ -87,7 +84,7 @@ def compund_changelog puts log end - log += "\n\n*This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*" + log += "\n\n**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*" output_filename = "#{@options[:output]}" File.open(output_filename, 'w') { |file| file.write(log) } @@ -111,19 +108,6 @@ def is_megred(number) @github.pull_requests.merged? @options[:user], @options[:project], number end - def get_all_merged_pull_requests - json = self.get_all_closed_pull_requests - puts 'Check if the requests is merged... (it can take a while)' - - json.delete_if { |req| - merged = self.is_megred(req[:number]) - if @options[:verbose] - puts "##{req[:number]} #{merged ? 'merged' : 'not merged'}" - end - !merged - } - end - def get_all_tags url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags" @@ -133,7 +117,7 @@ def get_all_tags end response = HTTParty.get(url, - :headers => {'Authorization' => 'token 8587bb22f6bf125454768a4a19dbcc774ea68d48', + :headers => {'Authorization' => "token #{@options[:token]}", 'User-Agent' => 'Changelog-Generator'}) json_parse = JSON.parse(response.body) @@ -160,12 +144,17 @@ def generate_log_between_tags(since_tag, till_tag) pull_requests = Array.new(@pull_requests) pull_requests.delete_if { |req| - t = Time.parse(req[:merged_at]).utc - tag_is_later_since = t > since_tag_time - tag_is_before_till = t <= till_tag_time + if req[:merged_at] + t = Time.parse(req[:merged_at]).utc + tag_is_later_since = t > since_tag_time + tag_is_before_till = t <= till_tag_time + + in_range = (tag_is_later_since) && (tag_is_before_till) + !in_range + else + true + end - in_range = (tag_is_later_since) && (tag_is_before_till) - !in_range } self.create_log(pull_requests, till_tag_name, till_tag_time) @@ -217,10 +206,20 @@ def get_time_of_tag(prev_tag) @tag_times_hash[prev_tag['name']] = Time.parse(time_string) end + def get_all_issues + all_issues = [] + @options[:labels].each { |label| + issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label + all_issues = all_issues.concat(issues.body) + } + all_issues + + end + end if __FILE__ == $0 changelog_generator = ChangelogGenerator.new - # changelog_generator.compund_changelog - + changelog_generator.compund_changelog + changelog_generator.get_all_issues end \ No newline at end of file diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 68574a169..655f865ab 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -3,7 +3,7 @@ class Parser def self.parse_options - options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md'} + options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement)} parser = OptionParser.new { |opts| opts.banner = 'Usage: changelog_generator --user username --project project_name [options]' @@ -23,7 +23,10 @@ def self.parse_options opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| options[:verbose] = v end - opts.on('-l', '--last-changes', 'Generate log between only last 2 tags') do |last| + opts.on('-i', '--[no-]issues', 'Include closed issues to changelog') do |v| + options[:issues] = v + end + opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last| options[:last] = last end opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last| @@ -32,6 +35,9 @@ def self.parse_options opts.on('-o', '--output [NAME]', 'Output file. Default is CHANGELOG.md') do |last| options[:output] = last end + opts.on('--labels x,y,z', Array, 'List of labels. Issues with that labels will be included to changelog. Default is \'bug,enhancement\'') do |list| + options[:labels] = list + end } parser.parse! From 381ffeb2614b44a8e4852292f3d347f3fbdeede6 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 17:45:35 +0200 Subject: [PATCH 05/10] add support for issues --- lib/github_changelog_generator.rb | 80 +++++++++++++++++++++--- lib/github_changelog_generator/parser.rb | 5 +- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index fcdffa349..978d658f8 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -20,6 +20,7 @@ def initialize() end @all_tags = self.get_all_tags @pull_requests = self.get_all_closed_pull_requests + @issues = self.get_all_issues @tag_times_hash = {} end @@ -157,7 +158,24 @@ def generate_log_between_tags(since_tag, till_tag) } - self.create_log(pull_requests, till_tag_name, till_tag_time) + issues = Array.new(@issues) + + issues.delete_if{ |issue| + if issue[:closed_at] + t = Time.parse(issue[:closed_at]).utc + tag_is_later_since = t > since_tag_time + tag_is_before_till = t <= till_tag_time + + in_range = (tag_is_later_since) && (tag_is_before_till) + !in_range + else + true + end + + } + + self.create_log(pull_requests, issues, till_tag_name, till_tag_time) + end def generate_log_before_tag(tag) @@ -167,26 +185,65 @@ def generate_log_before_tag(tag) pull_requests = Array.new(@pull_requests) pull_requests.delete_if { |req| - t = Time.parse(req[:closed_at]).utc - t > tag_time + if req[:merged_at] + t = Time.parse(req[:merged_at]).utc + t > tag_time + else + true + end + } - self.create_log(pull_requests, tag_name, tag_time) + issues = Array.new(@issues) + + issues.delete_if{ |issue| + if issue[:closed_at] + t = Time.parse(issue[:closed_at]).utc + t > tag_time + else + true + end + } + + self.create_log(pull_requests, issues, tag_name, tag_time) end - def create_log(pull_requests, tag_name, tag_time) + def create_log(pull_requests, issues, tag_name, tag_time) + # Generate tag name and link trimmed_tag = tag_name.tr('v', '') log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n" + #Generate date string: time_string = tag_time.strftime @options[:format] log += "#### #{time_string}\n" - pull_requests.each { |dict| - merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n" - log += "- #{merge}" - } + if @options[:pulls] + # Generate pull requests: + if pull_requests + pull_requests.each { |dict| + merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n" + log += "- #{merge}" + } + end + end + + if @options[:issues] + # Generate issues: + if issues && issues.any? + if pull_requests && pull_requests.any? && @options[:pulls] + log += "\n\n-\n\n" + end + + issues.each { |dict| + merge = "*Fixed issue:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n" + log += "- #{merge}" + } + end + + end + log end @@ -212,6 +269,10 @@ def get_all_issues issues = @github.issues.list user: @options[:user], repo: @options[:project], state: 'closed', filter: 'all', labels: label all_issues = all_issues.concat(issues.body) } + if @options[:verbose] + puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues" + end + all_issues end @@ -221,5 +282,4 @@ def get_all_issues if __FILE__ == $0 changelog_generator = ChangelogGenerator.new changelog_generator.compund_changelog - changelog_generator.get_all_issues end \ No newline at end of file diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index 655f865ab..c856caf4b 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -3,7 +3,7 @@ class Parser def self.parse_options - options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement)} + options = {:tag1 => nil, :tag2 => nil, :format => '%d/%m/%y', :output => 'CHANGELOG.md', :labels => %w(bug enhancement), :pulls => true, :issues => true } parser = OptionParser.new { |opts| opts.banner = 'Usage: changelog_generator --user username --project project_name [options]' @@ -26,6 +26,9 @@ def self.parse_options opts.on('-i', '--[no-]issues', 'Include closed issues to changelog') do |v| options[:issues] = v end + opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v| + options[:pulls] = v + end opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last| options[:last] = last end From acd2daada3c52dcca132fd7fe7f3efe59a0de1ac Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 17:52:07 +0200 Subject: [PATCH 06/10] Remove delimeter and fix parser. This final commit should close #6 enchantment! Yay! --- lib/github_changelog_generator.rb | 6 +----- lib/github_changelog_generator/parser.rb | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 978d658f8..358a95915 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -231,11 +231,7 @@ def create_log(pull_requests, issues, tag_name, tag_time) if @options[:issues] # Generate issues: - if issues && issues.any? - if pull_requests && pull_requests.any? && @options[:pulls] - log += "\n\n-\n\n" - end - + if issues issues.each { |dict| merge = "*Fixed issue:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n" log += "- #{merge}" diff --git a/lib/github_changelog_generator/parser.rb b/lib/github_changelog_generator/parser.rb index c856caf4b..8a6fa20b4 100644 --- a/lib/github_changelog_generator/parser.rb +++ b/lib/github_changelog_generator/parser.rb @@ -23,7 +23,7 @@ def self.parse_options opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| options[:verbose] = v end - opts.on('-i', '--[no-]issues', 'Include closed issues to changelog') do |v| + opts.on('--[no-]issues', 'Include closed issues to changelog. Default is true') do |v| options[:issues] = v end opts.on('--[no-]pull-requests', 'Include pull-requests to changelog. Default is true') do |v| From 606fab42898940072ad40a5260e3d9ad32c28be5 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 18:14:26 +0200 Subject: [PATCH 07/10] update Text for issues. (depends of what label placed) --- lib/github_changelog_generator.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 358a95915..4ed93e6d1 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -233,7 +233,27 @@ def create_log(pull_requests, issues, tag_name, tag_time) # Generate issues: if issues issues.each { |dict| - merge = "*Fixed issue:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n" + is_bug = false + is_enchantment = false + dict.labels.each { |label| + if label.name == 'bug' + is_bug = true + end + if label.name == 'enchantment' + is_enchantment = true + end + } + + intro = 'Fixed issue' + if is_bug + intro = 'Fixed bug' + end + + if is_enchantment + intro = 'Implemented enchantment' + end + + merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n" log += "- #{merge}" } end From 5882762800ed60b161393333a6a516139e4a410c Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 18:14:56 +0200 Subject: [PATCH 08/10] tst cm --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea81ab5e7..e9842e488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [0.3.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.3.0) +#### 07/11/14 +- Fix parsing date of pull request [\#3](https://github.com/skywinder/Github-Changelog-Generator/pull/3) + +- *Fixed bug:* Last tag not appeared in changelog [\#5](https://github.com/skywinder/Github-Changelog-Generator/issues/5) + +- *Fixed issue:* Implement option to specify output filename [\#4](https://github.com/skywinder/Github-Changelog-Generator/issues/4) + ## [0.1.0] (https://github.com/skywinder/Github-Changelog-Generator/tree/0.1.0) #### 07/11/14 - Add changelog generation for last tag [\#2](https://github.com/skywinder/Github-Changelog-Generator/pull/2) @@ -12,4 +20,4 @@ #### 06/11/14 -*This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file +**This file was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 502ae431b75c7105a80d255525c2ec4c58004657 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 18:24:02 +0200 Subject: [PATCH 09/10] fix typo! --- lib/github_changelog_generator.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 4ed93e6d1..4afae76c7 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -234,23 +234,23 @@ def create_log(pull_requests, issues, tag_name, tag_time) if issues issues.each { |dict| is_bug = false - is_enchantment = false + is_enhancement = false dict.labels.each { |label| if label.name == 'bug' is_bug = true end - if label.name == 'enchantment' - is_enchantment = true + if label.name == 'enhancement' + is_enhancement = true end } - intro = 'Fixed issue' + intro = 'Closed issue' if is_bug intro = 'Fixed bug' end - if is_enchantment - intro = 'Implemented enchantment' + if is_enhancement + intro = 'Implemented enhancement' end merge = "*#{intro}:* #{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/issues/#{dict[:number]})\n\n" From afea098355c686fdf71817edb78f17976f017767 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Fri, 7 Nov 2014 18:29:42 +0200 Subject: [PATCH 10/10] Bump major verion --- github_changelog_generator.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 2e7696cce..d02969b79 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "github_changelog_generator" - s.version = "0.1.0" + s.version = "1.0.0" s.default_executable = "github_changelog_generator" s.required_ruby_version = '>= 1.9.3'