587557e1ac
There's a lot in this PR. - Added a Section class to more easily make the other changes and hopefully add flexibility for the future - Added an option called `configure_sections` that allows you create your own custom sections. It blows away all other sections and uses only the ones you give it. - Added an option called `add_sections` that allows you to add_sections to the default section set - Added an option called `include_merged` that can be used when configure_sections is defined. Configure sections blows away any and all default sections so to get this one back, you have to set this option. - Added tests for this stuff @HAIL9000 was a co-author. Because of a little git snafu, I accidentally squashed all of our work into one so it looks like it was just me. --- Refactor details: Before this change, the code in generator.rb and generator_generation.rb was conflated and method call flow went back and forth between the two files seemingly randomly. They also both defined the exact same class, which is un-ruby-ish. I tried to separate methods used for the whole changelog generation from methods used for specific parts of the changelog and move them into specific classes. I reasoned that a changelog is a series of "entries" of all tagged releases plus an extra entry for the unreleased entry. Each entry is comprised of a header and a series of "sections" for that entry. Each section is comprized of a list of issues and/or pull requests for that entry. So the log contains entries, entries contain sections, and sections contain issues & prs. I have structured the classes around this idea. - lib/github_changelog_generator/generator/generator.rb is for code related to generating the entire changelog. - lib/github_changelog_generator/generator/entry.rb is for code related to generating entries. - lib/github_changelog_generator/generator/section.rb is for code relating to geneating entry sections. Issues and PRs are already special objects, so it doesn't make sense to break those out into their own class.
68 lines
2.1 KiB
Ruby
68 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
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 exclude_tags_regex since_tag max_issues
|
|
github_site github_endpoint simple_list
|
|
future_release release_branch verbose release_url
|
|
base configure_sections add_sections]
|
|
|
|
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 Changelog from GitHub"
|
|
|
|
yield(*[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.default_options
|
|
|
|
OPTIONS.each do |o|
|
|
v = instance_variable_get("@#{o}")
|
|
options[o.to_sym] = v unless v.nil?
|
|
end
|
|
abort "user and project are required." unless options[:user] && options[:project]
|
|
generator = Generator.new options
|
|
|
|
log = generator.compound_changelog
|
|
|
|
output_filename = (options[:output]).to_s
|
|
File.open(output_filename, "w") { |file| file.write(log) }
|
|
puts "Done!"
|
|
puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
|
|
end
|
|
end
|
|
end
|
|
end
|