2016-09-22 17:16:29 +00:00
|
|
|
# frozen_string_literal: true
|
2017-05-24 22:11:02 +00:00
|
|
|
|
2015-08-05 07:50:06 +00:00
|
|
|
require "rake"
|
|
|
|
require "rake/tasklib"
|
|
|
|
require "github_changelog_generator"
|
|
|
|
|
|
|
|
module GitHubChangelogGenerator
|
|
|
|
class RakeTask < ::Rake::TaskLib
|
|
|
|
include ::Rake::DSL if defined?(::Rake::DSL)
|
|
|
|
|
2017-05-24 22:11:02 +00:00
|
|
|
OPTIONS = %w[ user project token date_format output
|
2015-08-05 07:50:06 +00:00
|
|
|
bug_prefix enhancement_prefix issue_prefix
|
|
|
|
header merge_prefix issues
|
|
|
|
add_issues_wo_labels add_pr_wo_labels
|
|
|
|
pulls filter_issues_by_milestone author
|
|
|
|
unreleased_only unreleased unreleased_label
|
|
|
|
compare_link include_labels exclude_labels
|
|
|
|
bug_labels enhancement_labels
|
2016-07-06 12:12:22 +00:00
|
|
|
between_tags exclude_tags exclude_tags_regex since_tag max_issues
|
2015-08-05 07:50:06 +00:00
|
|
|
github_site github_endpoint simple_list
|
2016-01-02 20:11:49 +00:00
|
|
|
future_release release_branch verbose release_url
|
2017-05-24 22:11:02 +00:00
|
|
|
base ]
|
2015-08-05 07:50:06 +00:00
|
|
|
|
|
|
|
OPTIONS.each do |o|
|
|
|
|
attr_accessor o.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
# Public: Initialise a new GitHubChangelogGenerator::RakeTask.
|
|
|
|
#
|
|
|
|
# Example
|
|
|
|
#
|
|
|
|
# GitHubChangelogGenerator::RakeTask.new
|
|
|
|
def initialize(*args, &task_block)
|
|
|
|
@name = args.shift || :changelog
|
|
|
|
|
|
|
|
define(args, &task_block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def define(args, &task_block)
|
|
|
|
desc "Generate a Change log from GitHub"
|
|
|
|
|
2016-02-23 15:18:36 +00:00
|
|
|
yield(*[self, args].slice(0, task_block.arity)) if task_block
|
2015-08-05 07:50:06 +00:00
|
|
|
|
|
|
|
# clear any (auto-)pre-existing task
|
|
|
|
Rake::Task[@name].clear if Rake::Task.task_defined?(@name)
|
|
|
|
|
|
|
|
task @name do
|
|
|
|
# mimick parse_options
|
2015-10-21 22:09:25 +00:00
|
|
|
options = Parser.default_options
|
2015-08-05 07:50:06 +00:00
|
|
|
|
|
|
|
OPTIONS.each do |o|
|
|
|
|
v = instance_variable_get("@#{o}")
|
2015-09-14 22:35:07 +00:00
|
|
|
options[o.to_sym] = v unless v.nil?
|
2015-08-05 07:50:06 +00:00
|
|
|
end
|
2017-10-10 17:53:21 +00:00
|
|
|
abort "user and project are required." unless options[:user] && options[:project]
|
2015-08-05 07:50:06 +00:00
|
|
|
generator = Generator.new options
|
|
|
|
|
|
|
|
log = generator.compound_changelog
|
|
|
|
|
2016-02-23 15:18:36 +00:00
|
|
|
output_filename = (options[:output]).to_s
|
2015-08-05 07:50:06 +00:00
|
|
|
File.open(output_filename, "w") { |file| file.write(log) }
|
|
|
|
puts "Done!"
|
|
|
|
puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|