diff --git a/changelog_generator.rb b/changelog_generator.rb index a174a52..5f0bb2a 100755 --- a/changelog_generator.rb +++ b/changelog_generator.rb @@ -2,12 +2,13 @@ # encoding: UTF-8 require_relative 'log_generator' +require_relative 'parser' -if __FILE__ == $0 - generator = LogGenerator.new +def run_generator options + generator = LogGenerator.new(options) - tag_time = generator.findPrevTagDate - pull_requests = generator.getAllClosedPullRequests + tag_time = generator.find_prev_tag_date + pull_requests = generator.get_all_closed_pull_requests pull_requests.delete_if { |req| t = Time.parse(req[:closed_at]).utc @@ -15,4 +16,10 @@ if __FILE__ == $0 } generator.compund_changelog(tag_time, pull_requests) +end + +if __FILE__ == $0 + + options = Parser.new.options + run_generator(options) end \ No newline at end of file diff --git a/log_generator.rb b/log_generator.rb index cdbb7d7..977a804 100644 --- a/log_generator.rb +++ b/log_generator.rb @@ -4,6 +4,12 @@ require 'json' class LogGenerator + attr_accessor :options + + def initialize(options = {}) + @options = options + end + def print_json(json) puts JSON.pretty_generate(json) end @@ -13,7 +19,7 @@ class LogGenerator %x[#{exec_cmd}] end - def findPrevTagDate + def find_prev_tag_date value1 = exec_command "git log --tags --simplify-by-decoration --pretty=\"format:%ci %d\" | grep tag" unless value1 @@ -30,13 +36,14 @@ class LogGenerator exit end - puts "Prev tag is #{prev_tag}" - + if @options[:verbose] + puts "Prev tag is #{prev_tag}" + end time = Time.parse(prev_tag) end - def getAllClosedPullRequests + def get_all_closed_pull_requests if $oauth_token github = Github.new oauth_token: $oauth_token diff --git a/parser.rb b/parser.rb new file mode 100644 index 0000000..31d656a --- /dev/null +++ b/parser.rb @@ -0,0 +1,39 @@ +require 'optparse' +class Parser + + # attr_accessor + attr_reader :options + + def initialize + @options = {:tag1 => nil, :tag2 => nil} + + parser = OptionParser.new { |opts| + opts.banner = 'Usage: changelog_generator.rb [tag1 tag2] [options]' + + opts.on('-h', '--help', 'Displays Help') do + puts opts + exit + end + + opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| + @options[:verbose] = v + end + } + + parser.parse! + + #udefined case with 1 parameter: + if ARGV[0] && !ARGV[1] + puts parser.banner + exit + end + + if ARGV[1] + @options[:tag1] = ARGV[0] + @options[:tag2] = ARGV[1] + + end + + end + +end \ No newline at end of file