Add a rake task
This commit is contained in:
parent
295cfbc767
commit
5d9b44eac3
14
README.md
14
README.md
|
@ -104,6 +104,20 @@ So, if you got error like this:
|
|||
|
||||
It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP.
|
||||
|
||||
|
||||
### Rake task
|
||||
|
||||
You love Rake? So do we! And so we've made it easier for you by providing a Rake task library for your Change log generation. In your Rakefile, use:
|
||||
|
||||
```ruby
|
||||
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
||||
config.since_tag = '0.1.14'
|
||||
config.future_release = '0.2.0'
|
||||
end
|
||||
```
|
||||
|
||||
All command line options can be passed to the Rake task as `config` parameters. Since you're naming the Rake task yourself, you can create as many as you want, too.
|
||||
|
||||
##Features and advantages of this project
|
||||
- Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com/) :gem:
|
||||
- Possible to generate **Unreleased** changes (closed issues that have not released yet) :dizzy:
|
||||
|
|
|
@ -14,7 +14,7 @@ module GitHubChangelogGenerator
|
|||
parser.parse!
|
||||
|
||||
if options[:user].nil? || options[:project].nil?
|
||||
detect_user_and_project(options)
|
||||
detect_user_and_project(options, ARGV[0], ARGV[1])
|
||||
end
|
||||
|
||||
if !options[:user] || !options[:project]
|
||||
|
@ -180,8 +180,8 @@ module GitHubChangelogGenerator
|
|||
end
|
||||
|
||||
# Detects user and project from git
|
||||
def self.detect_user_and_project(options)
|
||||
options[:user], options[:project] = user_project_from_option(ARGV[0], ARGV[1], options[:github_site])
|
||||
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
|
||||
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
|
||||
if !options[:user] || !options[:project]
|
||||
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
|
||||
options[:user] = "skywinder"
|
||||
|
|
68
lib/github_changelog_generator/task.rb
Normal file
68
lib/github_changelog_generator/task.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require "rake"
|
||||
require "rake/tasklib"
|
||||
require "github_changelog_generator"
|
||||
|
||||
module GitHubChangelogGenerator
|
||||
class RakeTask < ::Rake::TaskLib
|
||||
include ::Rake::DSL if defined?(::Rake::DSL)
|
||||
|
||||
OPTIONS = %w( user project token date_format output
|
||||
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
|
||||
between_tags exclude_tags since_tag max_issues
|
||||
github_site github_endpoint simple_list
|
||||
future_release verbose )
|
||||
|
||||
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"
|
||||
|
||||
task_block.call(*[self, args].slice(0, task_block.arity)) if task_block
|
||||
|
||||
# clear any (auto-)pre-existing task
|
||||
Rake::Task[@name].clear if Rake::Task.task_defined?(@name)
|
||||
|
||||
task @name do
|
||||
# mimick parse_options
|
||||
options = Parser.get_default_options
|
||||
|
||||
if options[:user].nil? || options[:project].nil?
|
||||
Parser.detect_user_and_project(options)
|
||||
end
|
||||
|
||||
OPTIONS.each do |o|
|
||||
v = instance_variable_get("@#{o}")
|
||||
options[o.to_sym] = v if v
|
||||
end
|
||||
|
||||
generator = Generator.new options
|
||||
|
||||
log = generator.compound_changelog
|
||||
|
||||
output_filename = "#{options[:output]}"
|
||||
File.open(output_filename, "w") { |file| file.write(log) }
|
||||
puts "Done!"
|
||||
puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user