diff --git a/Gemfile b/Gemfile index d106303..12e9ea8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,6 @@ source 'https://rubygems.org' -gem 'rake' - -gem 'github_api' -gem 'colorize' +gemspec group :test do gem 'rspec' diff --git a/Gemfile.lock b/Gemfile.lock index 0e7c878..4d69dc1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +PATH + remote: . + specs: + github_changelog_generator (1.3.11) + colorize (~> 0.7) + github_api (~> 0.12) + thor (~> 0.19) + GEM remote: https://rubygems.org/ specs: @@ -94,10 +102,10 @@ PLATFORMS ruby DEPENDENCIES - colorize + bundler (~> 1.7) coveralls - github_api - rake + github_changelog_generator! + rake (~> 10.0) rspec rubocop simplecov diff --git a/bin/ghclgen b/bin/ghclgen new file mode 100755 index 0000000..77ac711 --- /dev/null +++ b/bin/ghclgen @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby -U +require 'github_changelog_generator' +GitHubChangelogGenerator::CLI.start(ARGV) diff --git a/github_changelog_generator.gemspec b/github_changelog_generator.gemspec index 8452ee7..8c5e012 100644 --- a/github_changelog_generator.gemspec +++ b/github_changelog_generator.gemspec @@ -28,4 +28,5 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency('github_api', ['~> 0.12']) spec.add_runtime_dependency('colorize', ['~> 0.7']) + spec.add_runtime_dependency('thor', ['~> 0.19']) end diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index 30ff897..e7d6b74 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -5,10 +5,11 @@ require 'json' require 'colorize' require 'benchmark' -require_relative 'github_changelog_generator/parser' -require_relative 'github_changelog_generator/generator' -require_relative 'github_changelog_generator/version' -require_relative 'github_changelog_generator/reader' +require 'github_changelog_generator/parser' +require 'github_changelog_generator/generator' +require 'github_changelog_generator/version' +require 'github_changelog_generator/reader' +require 'github_changelog_generator/cli' module GitHubChangelogGenerator class ChangelogGenerator diff --git a/lib/github_changelog_generator/cli.rb b/lib/github_changelog_generator/cli.rb new file mode 100644 index 0000000..3e45564 --- /dev/null +++ b/lib/github_changelog_generator/cli.rb @@ -0,0 +1,62 @@ +# +# Author:: Enrico Stahn +# +# Copyright 2014, Zanui, +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'thor' + +module GitHubChangelogGenerator + class CLI < Thor + default_task :generate + + desc 'generate', 'Generates the CHANGELOG.md based on the given options' + option :user, aliases: '-u', type: :string, desc: 'Username of the owner of target GitHub repo' + option :project, aliases: '-p', type: :string, desc: 'Username of the owner of target GitHub repo' + option :token, aliases: '-t', type: :string, desc: 'To make more than 50 requests per hour your GitHub token required. You can generate it here: https://github.com/settings/tokens/new' + option :date_format, aliases: '-f', type: :string, default: '%d/%m/%y', desc: 'Date format.' + option :output, aliases: '-o', type: :string, default: 'CHANGELOG.md', desc: 'Output file.' + # TODO: Should be "closed_issues" + option :issues, type: :boolean, default: true, desc: 'Include closed issues to changelog.' + option :issues_wo_labels, type: :boolean, default: true, desc: 'Include closed issues without labels to changelog.' + option :pr_wo_labels, type: :boolean, default: true, desc: 'Include pull requests without labels to changelog.' + option :pull_requests, type: :boolean, default: true, desc: 'Include pull-requests to changelog.' + option :filter_by_milestone, type: :boolean, default: true, desc: 'Use milestone to detect when issue was resolved.' + option :author, type: :boolean, default: true, desc: 'Add author of pull-request in the end.' + option :unreleased_only, type: :boolean, default: true, desc: 'Generate log from unreleased closed issues only.' + option :unreleased, type: :boolean, default: true, desc: 'Add to log unreleased closed issues.' + option :unreleased_label, type: :boolean, default: true, desc: 'Add to log unreleased closed issues.' + option :compare_link, type: :boolean, default: true, desc: 'Include compare link (Full Changelog) between older version and newer version.' + option :include_labels, type: :array, default: %w(bug enhancement), desc: 'Issues only with that labels will be included to changelog.' + option :exclude_labels, type: :array, default: %w(duplicate question invalid wontfix), desc: 'Issues with that labels will be always excluded from changelog.' + option :max_issues, type: :numeric, desc: 'Max number of issues to fetch from GitHub. Default is unlimited' + option :github_site, :banner => 'URL', type: :string, desc: 'The Enterprise Github site on which your project is hosted.' + option :github_api, :banner => 'URL', type: :string, desc: 'The enterprise endpoint to use for your Github API.' + option :simple_list, type: :boolean, default: false, desc: 'Create simple list from issues and pull requests.' + option :verbose, type: :boolean, default: true, desc: 'Run verbosely.' + + long_desc <<-LONGDESC +Automatically generate change log from your tags, issues, labels and pull requests on GitHub. + LONGDESC + def generate + end + + map %w[--version -v] => :__print_version + desc '--version, -v', 'print the version' + def __print_version + puts "Version: #{GitHubChangelogGenerator::VERSION}" + end + end +end