Merge branch 'master' into develop

This commit is contained in:
Petr Korolev 2015-08-24 14:54:53 +03:00
commit ed179ed7be
6 changed files with 352 additions and 201 deletions

View File

@ -92,7 +92,7 @@ Since GitHub allows you to make only 50 requests without authentication it's rec
And: And:
- Run with key `-t [your-16-digit-token]` - Run with key `-t [your-40-digit-token]`
- Or set environment variable `CHANGELOG_GITHUB_TOKEN` and specify there your token. - Or set environment variable `CHANGELOG_GITHUB_TOKEN` and specify there your token.
i.e. add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string : i.e. add to your `~/.bash_profile` or `~/.zshrc` or any other place to load ENV variables string :
@ -104,6 +104,28 @@ 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. It's time to create this token or wait for 1 hour before GitHub reset the counter for your IP.
## Migrating from a manual changelog
Knowing how dedicated you are to your project, you probably haven't been waiting for github-changelog-generator to keep a changelog,
but you most likely wouln't like to have to open issues and PRs for all past features listed in your historic changelog.
That's where `--base` comes handy. This option lets you pass a static changelog to be appended at the end of the generated entries.
If you have a `HISTORY.md` file in your project, it will automatically be picked as the static historical changelog and appended.
### 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 ##Features and advantages of this project
- Generate canonical, neat change log file, followed by [basic change log guidelines](http://keepachangelog.com/) :gem: - 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: - Possible to generate **Unreleased** changes (closed issues that have not released yet) :dizzy:

View File

@ -16,6 +16,8 @@ module GitHubChangelogGenerator
log += generate_log_for_all_tags log += generate_log_for_all_tags
end end
log += File.read(@options[:base]) if File.file?(@options[:base])
log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*" log += "\n\n\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
@log = log @log = log
end end
@ -76,10 +78,15 @@ module GitHubChangelogGenerator
time_string = newer_tag_time.strftime @options[:date_format] time_string = newer_tag_time.strftime @options[:date_format]
# Generate tag name and link # Generate tag name and link
if newer_tag_name.equal? @options[:unreleased_label] if @options[:release_url]
log += "## [#{newer_tag_name}](#{project_url}/tree/#{newer_tag_link})\n\n" release_url = format(@options[:release_url], newer_tag_link)
else else
log += "## [#{newer_tag_name}](#{project_url}/tree/#{newer_tag_link}) (#{time_string})\n" release_url = "#{project_url}/tree/#{newer_tag_link}"
end
if newer_tag_name.equal? @options[:unreleased_label]
log += "## [#{newer_tag_name}](#{release_url})\n\n"
else
log += "## [#{newer_tag_name}](#{release_url}) (#{time_string})\n"
end end
if @options[:compare_link] && older_tag_link if @options[:compare_link] && older_tag_link

View File

@ -52,14 +52,42 @@ module GitHubChangelogGenerator
[newer_tag_link, newer_tag_name, newer_tag_time] [newer_tag_link, newer_tag_name, newer_tag_time]
end end
def detect_since_tag
if @options[:base] && File.file?(@options[:base])
reader = GitHubChangelogGenerator::Reader.new
content = reader.read(@options[:base])
return content[0]["version"] if content
end
end
# Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags # Return tags after filtering tags in lists provided by option: --between-tags & --exclude-tags
# #
# @return [Array] # @return [Array]
def get_filtered_tags(all_tags) def get_filtered_tags(all_tags)
filtered_tags = filter_between_tags(all_tags) filtered_tags = filter_since_tag(all_tags)
filtered_tags = filter_between_tags(filtered_tags)
filter_excluded_tags(filtered_tags) filter_excluded_tags(filtered_tags)
end end
def filter_since_tag(all_tags)
filtered_tags = all_tags
tag = @options[:since_tag]
tag ||= detect_since_tag
if tag
if all_tags.map(&:name).include? tag
idx = all_tags.index { |t| t.name == tag }
if idx > 0
filtered_tags = all_tags[0..idx - 1]
else
filtered_tags = []
end
else
Helper.log.warn "Warning: can't find tag #{tag}, specified with --since-tag option."
end
end
filtered_tags
end
def filter_between_tags(all_tags) def filter_between_tags(all_tags)
filtered_tags = all_tags filtered_tags = all_tags
if @options[:between_tags] if @options[:between_tags]

View File

@ -14,7 +14,7 @@ module GitHubChangelogGenerator
parser.parse! parser.parse!
if options[:user].nil? || options[:project].nil? if options[:user].nil? || options[:project].nil?
detect_user_and_project(options) detect_user_and_project(options, ARGV[0], ARGV[1])
end end
if !options[:user] || !options[:project] if !options[:user] || !options[:project]
@ -50,6 +50,9 @@ module GitHubChangelogGenerator
opts.on("-o", "--output [NAME]", "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("-b", "--base [NAME]", "Optional base file to append generated changes to.") do |last|
options[:base] = last
end
opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v| opts.on("--bugs-label [LABEL]", "Setup custom label for bug-fixes section. Default is \"**Fixed bugs:**""") do |v|
options[:bug_prefix] = v options[:bug_prefix] = v
end end
@ -110,12 +113,18 @@ module GitHubChangelogGenerator
opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list| opts.on("--between-tags x,y,z", Array, "Change log will be filled only between specified tags") do |list|
options[:between_tags] = list options[:between_tags] = list
end end
opts.on("--exclude-tags x,y,z", Array, "Change log will be exclude specified tags") do |list| opts.on("--exclude-tags x,y,z", Array, "Change log will exclude specified tags") do |list|
options[:exclude_tags] = list options[:exclude_tags] = list
end end
opts.on("--since-tag x", "Change log will start after specified tag") do |v|
options[:since_tag] = v
end
opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max| opts.on("--max-issues [NUMBER]", Integer, "Max number of issues to fetch from GitHub. Default is unlimited") do |max|
options[:max_issues] = max options[:max_issues] = max
end end
opts.on("--release-url [URL]", "The URL to point to for release links, in printf format (with the tag as variable).") do |url|
options[:release_url] = url
end
opts.on("--github-site [URL]", "The Enterprise Github site on which your project is hosted.") do |last| opts.on("--github-site [URL]", "The Enterprise Github site on which your project is hosted.") do |last|
options[:github_site] = last options[:github_site] = last
end end
@ -150,6 +159,7 @@ module GitHubChangelogGenerator
tag2: nil, tag2: nil,
date_format: "%Y-%m-%d", date_format: "%Y-%m-%d",
output: "CHANGELOG.md", output: "CHANGELOG.md",
base: "HISTORY.md",
issues: true, issues: true,
add_issues_wo_labels: true, add_issues_wo_labels: true,
add_pr_wo_labels: true, add_pr_wo_labels: true,
@ -177,8 +187,8 @@ module GitHubChangelogGenerator
end end
# Detects user and project from git # Detects user and project from git
def self.detect_user_and_project(options) def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
options[:user], options[:project] = user_project_from_option(ARGV[0], ARGV[1], options[:github_site]) options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
if !options[:user] || !options[:project] if !options[:user] || !options[:project]
if ENV["RUBYLIB"] =~ /ruby-debug-ide/ if ENV["RUBYLIB"] =~ /ruby-debug-ide/
options[:user] = "skywinder" options[:user] = "skywinder"

View 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

View File

@ -89,6 +89,22 @@ describe GitHubChangelogGenerator::Generator do
end end
end end
describe "#filter_since_tag" do
subject { generator.filter_since_tag(tags_mash_from_strings(%w(1 2 3))) }
context "with valid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: "2") }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1))) }
end
context "with invalid since tag" do
let(:generator) { GitHubChangelogGenerator::Generator.new(since_tag: %w(invalid tags)) }
it { is_expected.to be_a Array }
it { is_expected.to match_array(tags_mash_from_strings(%w(1 2 3))) }
end
end
describe "#get_time_of_tag" do describe "#get_time_of_tag" do
current_time = Time.now current_time = Time.now
before(:all) { @generator = GitHubChangelogGenerator::Generator.new } before(:all) { @generator = GitHubChangelogGenerator::Generator.new }