Compare commits

...

12 Commits
0.1.0 ... 1.0.0

Author SHA1 Message Date
Petr Korolev
afea098355 Bump major verion 2014-11-07 18:29:42 +02:00
Petr Korolev
d3c3b7850f Merge branch 'new-features' 2014-11-07 18:28:29 +02:00
Petr Korolev
502ae431b7 fix typo! 2014-11-07 18:24:02 +02:00
Petr Korolev
5882762800 tst cm 2014-11-07 18:14:56 +02:00
Petr Korolev
606fab4289 update Text for issues. (depends of what label placed) 2014-11-07 18:14:26 +02:00
Petr Korolev
3d25d1135f Merge branch 'new-features' 2014-11-07 18:00:08 +02:00
Petr Korolev
acd2daada3 Remove delimeter and fix parser. This final commit should close #6 enchantment! Yay! 2014-11-07 17:57:32 +02:00
Petr Korolev
381ffeb261 add support for issues 2014-11-07 17:47:42 +02:00
Petr Korolev
f9e6a076bc implement "issues" parsing + check for merged requests 2014-11-07 17:05:01 +02:00
Petr Korolev
8457b764bf update readme and bump gem 2014-11-07 13:52:23 +02:00
Petr Korolev
4237b751a0 clean gitignore file 2014-11-07 13:21:54 +02:00
Petr Korolev
3a78f97d61 add changelog file 2014-11-07 13:20:19 +02:00
6 changed files with 151 additions and 44 deletions

2
.gitignore vendored
View File

@@ -1,2 +0,0 @@
constants.rb
*.md

23
CHANGELOG.md Normal file
View File

@@ -0,0 +1,23 @@
# 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)
- 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)*

View File

@@ -27,7 +27,7 @@ See `github_changelog_generator --help` for detailed usage.
-v, --[no-]verbose Run verbosely -v, --[no-]verbose Run verbosely
-l, --last-changes Generate log between only last 2 tags -l, --last-changes Generate log between only last 2 tags
-f, --date-format [FORMAT] Date format. Default is %d/%m/%y -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: ## Examples:
### This changelog: [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md) ### This changelog: [ActionSheetPicker-3.0/CHANGELOG.md](https://github.com/skywinder/ActionSheetPicker-3.0/blob/master/CHANGELOG.md)

View File

@@ -1,6 +1,6 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "github_changelog_generator" s.name = "github_changelog_generator"
s.version = "0.0.2" s.version = "1.0.0"
s.default_executable = "github_changelog_generator" s.default_executable = "github_changelog_generator"
s.required_ruby_version = '>= 1.9.3' s.required_ruby_version = '>= 1.9.3'

View File

@@ -8,7 +8,7 @@ require_relative 'github_changelog_generator/parser'
class ChangelogGenerator class ChangelogGenerator
attr_accessor :options, :all_tags attr_accessor :options, :all_tags, :github
def initialize() def initialize()
@@ -20,6 +20,7 @@ class ChangelogGenerator
end end
@all_tags = self.get_all_tags @all_tags = self.get_all_tags
@pull_requests = self.get_all_closed_pull_requests @pull_requests = self.get_all_closed_pull_requests
@issues = self.get_all_issues
@tag_times_hash = {} @tag_times_hash = {}
end end
@@ -35,17 +36,14 @@ class ChangelogGenerator
def get_all_closed_pull_requests def get_all_closed_pull_requests
request = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
pull_requests = request.body
issues = @github.pull_requests.list @options[:user], @options[:project], :state => 'closed'
json = issues.body
if @options[:verbose] if @options[:verbose]
puts 'Receive all pull requests' puts 'Receive all pull requests'
end end
json pull_requests
end end
def compund_changelog def compund_changelog
@@ -87,7 +85,7 @@ class ChangelogGenerator
puts log puts log
end 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]}" output_filename = "#{@options[:output]}"
File.open(output_filename, 'w') { |file| file.write(log) } File.open(output_filename, 'w') { |file| file.write(log) }
@@ -111,19 +109,6 @@ class ChangelogGenerator
@github.pull_requests.merged? @options[:user], @options[:project], number @github.pull_requests.merged? @options[:user], @options[:project], number
end 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 def get_all_tags
url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags" url = "https://api.github.com/repos/#{@options[:user]}/#{@options[:project]}/tags"
@@ -133,7 +118,7 @@ class ChangelogGenerator
end end
response = HTTParty.get(url, response = HTTParty.get(url,
:headers => {'Authorization' => 'token 8587bb22f6bf125454768a4a19dbcc774ea68d48', :headers => {'Authorization' => "token #{@options[:token]}",
'User-Agent' => 'Changelog-Generator'}) 'User-Agent' => 'Changelog-Generator'})
json_parse = JSON.parse(response.body) json_parse = JSON.parse(response.body)
@@ -160,15 +145,37 @@ class ChangelogGenerator
pull_requests = Array.new(@pull_requests) pull_requests = Array.new(@pull_requests)
pull_requests.delete_if { |req| pull_requests.delete_if { |req|
if req[:merged_at]
t = Time.parse(req[:merged_at]).utc t = Time.parse(req[:merged_at]).utc
tag_is_later_since = t > since_tag_time tag_is_later_since = t > since_tag_time
tag_is_before_till = t <= till_tag_time tag_is_before_till = t <= till_tag_time
in_range = (tag_is_later_since) && (tag_is_before_till) in_range = (tag_is_later_since) && (tag_is_before_till)
!in_range !in_range
else
true
end
} }
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 end
def generate_log_before_tag(tag) def generate_log_before_tag(tag)
@@ -178,26 +185,81 @@ class ChangelogGenerator
pull_requests = Array.new(@pull_requests) pull_requests = Array.new(@pull_requests)
pull_requests.delete_if { |req| pull_requests.delete_if { |req|
t = Time.parse(req[:closed_at]).utc if req[:merged_at]
t = Time.parse(req[:merged_at]).utc
t > tag_time 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 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', '') trimmed_tag = tag_name.tr('v', '')
log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n" log = "## [#{trimmed_tag}] (https://github.com/#{@options[:user]}/#{@options[:project]}/tree/#{tag_name})\n"
#Generate date string:
time_string = tag_time.strftime @options[:format] time_string = tag_time.strftime @options[:format]
log += "#### #{time_string}\n" log += "#### #{time_string}\n"
if @options[:pulls]
# Generate pull requests:
if pull_requests
pull_requests.each { |dict| pull_requests.each { |dict|
merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n" merge = "#{dict[:title]} [\\##{dict[:number]}](https://github.com/#{@options[:user]}/#{@options[:project]}/pull/#{dict[:number]})\n\n"
log += "- #{merge}" log += "- #{merge}"
} }
end
end
if @options[:issues]
# Generate issues:
if issues
issues.each { |dict|
is_bug = false
is_enhancement = false
dict.labels.each { |label|
if label.name == 'bug'
is_bug = true
end
if label.name == 'enhancement'
is_enhancement = true
end
}
intro = 'Closed issue'
if is_bug
intro = 'Fixed bug'
end
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"
log += "- #{merge}"
}
end
end
log log
end end
@@ -217,8 +279,23 @@ class ChangelogGenerator
@tag_times_hash[prev_tag['name']] = Time.parse(time_string) @tag_times_hash[prev_tag['name']] = Time.parse(time_string)
end 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)
}
if @options[:verbose]
puts "Receive all closed issues with labels #{@options[:labels]}: #{all_issues.count} issues"
end
all_issues
end
end end
if __FILE__ == $0 if __FILE__ == $0
ChangelogGenerator.new.compund_changelog changelog_generator = ChangelogGenerator.new
changelog_generator.compund_changelog
end end

View File

@@ -3,7 +3,7 @@ require 'optparse'
class Parser class Parser
def self.parse_options 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), :pulls => true, :issues => true }
parser = OptionParser.new { |opts| parser = OptionParser.new { |opts|
opts.banner = 'Usage: changelog_generator --user username --project project_name [options]' opts.banner = 'Usage: changelog_generator --user username --project project_name [options]'
@@ -23,15 +23,24 @@ class Parser
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
options[:verbose] = v options[:verbose] = v
end end
opts.on('-l', '--last-changes', 'Generate log between only last 2 tags') do |last| 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|
options[:pulls] = v
end
opts.on('-l', '--last-changes', 'Generate log between last 2 tags only') do |last|
options[:last] = last options[:last] = last
end end
opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last| opts.on('-f', '--date-format [FORMAT]', 'Date format. Default is %d/%m/%y') do |last|
options[:format] = last options[:format] = last
end 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 options[:output] = last
end 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! parser.parse!