From 8c0ebe380827b9d5764078a453e5cd0b2ac56dce Mon Sep 17 00:00:00 2001 From: Enrico Stahn Date: Fri, 27 Mar 2015 10:23:12 +1100 Subject: [PATCH 1/4] Add thor to Gemfile/gemspec --- Gemfile | 5 +--- Gemfile.lock | 37 +++++++++++++++++++----------- github_changelog_generator.gemspec | 1 + 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 2df9bd4..6de850e 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 457d0d2..faca1e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,17 +1,25 @@ +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: - addressable (2.3.6) + addressable (2.3.7) ast (2.0.0) astrolabe (1.3.0) parser (>= 2.2.0.pre.3, < 3.0) - colorize (0.7.4) + colorize (0.7.5) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) diff-lcs (1.2.5) - faraday (0.9.0) + faraday (0.9.1) multipart-post (>= 1.2, < 3) - github_api (0.12.2) + github_api (0.12.3) addressable (~> 2.3) descendants_tracker (~> 0.0.4) faraday (~> 0.8, < 0.10) @@ -19,13 +27,13 @@ GEM multi_json (>= 1.7.5, < 2.0) nokogiri (~> 1.6.3) oauth2 - hashie (3.3.2) - jwt (1.2.0) - mini_portile (0.6.1) - multi_json (1.10.1) + hashie (3.4.0) + jwt (1.4.1) + mini_portile (0.6.2) + multi_json (1.11.0) multi_xml (0.5.5) multipart-post (2.0.0) - nokogiri (1.6.5) + nokogiri (1.6.6.2) mini_portile (~> 0.6.0) oauth2 (1.0.0) faraday (>= 0.8, < 0.10) @@ -36,7 +44,7 @@ GEM parser (2.2.0.3) ast (>= 1.1, < 3.0) powerpack (0.1.0) - rack (1.5.2) + rack (1.6.0) rainbow (2.0.0) rake (10.4.2) rspec (3.2.0) @@ -59,14 +67,15 @@ GEM rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) ruby-progressbar (1.7.5) - thread_safe (0.3.4) + thor (0.19.1) + thread_safe (0.3.5) PLATFORMS ruby DEPENDENCIES - colorize - github_api - rake + bundler (~> 1.7) + github_changelog_generator! + rake (~> 10.0) rspec rubocop 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 From 3993eeec281708472672c5298657ba7fec7660fa Mon Sep 17 00:00:00 2001 From: Enrico Stahn Date: Fri, 27 Mar 2015 10:23:58 +1100 Subject: [PATCH 2/4] Add thor CLI binary and app class --- bin/ghclgen | 3 +++ lib/github_changelog_generator.rb | 9 ++++--- lib/github_changelog_generator/cli.rb | 35 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100755 bin/ghclgen create mode 100644 lib/github_changelog_generator/cli.rb 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/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index e571e78..ae5c527 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..7b274aa --- /dev/null +++ b/lib/github_changelog_generator/cli.rb @@ -0,0 +1,35 @@ +# +# 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 :issues_wo_labels, :type => :boolean, :default => true, :desc => 'Include closed issues without labels to changelog.' + + def generate + print_table([['Project:', 'zanui/chef-thumbor'], ['Username:', 'estahn']]) + end + end +end \ No newline at end of file From da8f725b2df6943832fad3f815af9e8c55f363a6 Mon Sep 17 00:00:00 2001 From: Enrico Stahn Date: Fri, 27 Mar 2015 12:08:53 +1100 Subject: [PATCH 3/4] Fix robocop issues with cli.rb --- lib/github_changelog_generator/cli.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/github_changelog_generator/cli.rb b/lib/github_changelog_generator/cli.rb index 7b274aa..3119cc6 100644 --- a/lib/github_changelog_generator/cli.rb +++ b/lib/github_changelog_generator/cli.rb @@ -23,13 +23,13 @@ module GitHubChangelogGenerator 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 :issues_wo_labels, :type => :boolean, :default => true, :desc => 'Include closed issues without labels to changelog.' + 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 :issues_wo_labels, type: :boolean, default: true, desc: 'Include closed issues without labels to changelog.' def generate print_table([['Project:', 'zanui/chef-thumbor'], ['Username:', 'estahn']]) end end -end \ No newline at end of file +end From 5e55ef672bc40ba43ecf2951a09a1128dfb1b337 Mon Sep 17 00:00:00 2001 From: Enrico Stahn Date: Fri, 27 Mar 2015 13:43:50 +1100 Subject: [PATCH 4/4] Migrate all options to thor --- lib/github_changelog_generator/cli.rb | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/github_changelog_generator/cli.rb b/lib/github_changelog_generator/cli.rb index 3119cc6..3e45564 100644 --- a/lib/github_changelog_generator/cli.rb +++ b/lib/github_changelog_generator/cli.rb @@ -26,10 +26,37 @@ module GitHubChangelogGenerator 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 - print_table([['Project:', 'zanui/chef-thumbor'], ['Username:', 'estahn']]) + end + + map %w[--version -v] => :__print_version + desc '--version, -v', 'print the version' + def __print_version + puts "Version: #{GitHubChangelogGenerator::VERSION}" end end end