bundler-diff 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 396448a09341622ba815d36158c1c75326187d1e02e80bf034679c3734151ea7
4
- data.tar.gz: 258c66d28bcd0fb02d41543e9c33188cb75e3e5b092d77db3d0a70e167f3f2bd
3
+ metadata.gz: aa495cccf95f5c21f03fa11fac02dd9f682205d9892fc53a6c4b72a3fcca066d
4
+ data.tar.gz: ddd43a9b67597a11167d9eee5d32b19c6e96cd4d9f2c096d250d3fa5ba292082
5
5
  SHA512:
6
- metadata.gz: 00bb8a49e251f8c6e14492e46c17f6a8574da4eddcee31d6d008aa83b1402961277cb82266af1d0b2a0cac856bfc0c6c135a9d8817b7b32bd42999a7686f5345
7
- data.tar.gz: 8a18283e1635cd52d379e08cc76a3437e4b5a74e7c9e174c02f9d62d00d1b3e23ebe5db5ead6fc8a274ec76cc96e76ad2b220c84398b2c5215f2be800b6ea674
6
+ metadata.gz: 91b003ca66c18d8c78d28145349b8e20817912a52703da2f2698f731c4b05d8ed5fc75de3c668e43b5c98f720d26338df1b81b2829519ce2f10bacfc0b5a81cf
7
+ data.tar.gz: 130a7bf297aa2d21b847f2058d53e9d89776cd469674f15cdbefc1e2bd868e2c866412f679fee3a9dc7effb596a520f3298b59f209be128cff959f2385cba00e
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.5
3
3
  DisplayCopNames: true
4
4
  DisplayStyleGuide: true
5
5
  ExtraDetails: true
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
 
4
4
  rvm:
5
- - 2.3.7
6
5
  - 2.4.4
7
6
  - 2.5.1
8
7
  - ruby-head
data/README.md CHANGED
@@ -54,6 +54,7 @@ Usage: bundle diff [options]
54
54
  default
55
55
  md_table
56
56
  --escape-json Escape output as a JSON string
57
+ --access-token ACCESS_TOKEN Set access token for GitHub API
57
58
  -v, --version Display the version
58
59
  ```
59
60
 
data/lib/bundler_diff.rb CHANGED
@@ -7,10 +7,40 @@ require 'bundler_diff/formatter/md_table'
7
7
  require 'bundler_diff/version'
8
8
 
9
9
  module BundlerDiff
10
- def self.formatters
11
- @formatters ||= {
12
- default: Formatter::Default,
13
- md_table: Formatter::MdTable
14
- }
10
+ class << self
11
+ def formatters
12
+ @formatters ||= {
13
+ default: Formatter::Default,
14
+ md_table: Formatter::MdTable
15
+ }
16
+ end
17
+
18
+ def parse_options(args) # rubocop:disable Metrics/MethodLength
19
+ options = {}
20
+
21
+ opt = OptionParser.new
22
+ opt.banner = 'Usage: bundle diff [options]'
23
+ opt.on('-c', '--commit COMMIT', 'Specify a commit') { |val| options[:commit] = val }
24
+ formatter_desc = [
25
+ 'Choose a formatter',
26
+ ' default',
27
+ ' md_table'
28
+ ]
29
+ opt.on('-f', '--format FORMATTER', *formatter_desc) do |val|
30
+ options[:format] = val.to_sym
31
+ end
32
+ opt.on('--escape-json', 'Escape output as a JSON string') do |val|
33
+ options[:escape_json] = val
34
+ end
35
+ opt.on('--access-token ACCESS_TOKEN', 'Set access token for GitHub API') do |val|
36
+ options[:access_token] = val
37
+ end
38
+
39
+ opt.on('-v', '--version', 'Display the version') { options[:version] = true }
40
+
41
+ remaining_args = opt.parse(args)
42
+ options[:commit] ||= remaining_args.shift
43
+ options
44
+ end
15
45
  end
16
46
  end
@@ -25,7 +25,7 @@ module BundlerDiff
25
25
 
26
26
  gems = GemsComparator.compare(before_lockfile, after_lockfile)
27
27
  output = formatter.new.render(gems)
28
- output = JSON.dump(output) if @escape_json
28
+ output = JSON.dump(output) if @options[:escape_json]
29
29
  puts output
30
30
  rescue StandardError => e
31
31
  puts e.inspect
@@ -47,46 +47,41 @@ module BundlerDiff
47
47
  File.read(file_name)
48
48
  end
49
49
 
50
- def parse_options! # rubocop:disable Metrics/MethodLength
51
- opt = OptionParser.new
52
- opt.banner = 'Usage: bundle diffgems [options]'
53
- opt.on('-c', '--commit COMMIT', 'Specify a commit') { |val| @commit = val }
54
- formatter_desc = [
55
- 'Choose a formatter',
56
- ' default',
57
- ' md_table'
58
- ]
59
- opt.on('-f', '--format FORMATTER', *formatter_desc) { |val| @format = val.to_sym }
60
- opt.on('--escape-json', 'Escape output as a JSON string') do |val|
61
- @escape_json = val
62
- end
63
- opt.on('-v', '--version', 'Display the version') do
50
+ def parse_options!
51
+ @options = BundlerDiff.parse_options(@args)
52
+
53
+ if @options.key?(:version)
64
54
  puts BundlerDiff::VERSION
65
55
  exit
66
56
  end
67
- options = opt.parse(@args)
68
- @commit ||= options.shift
57
+ @options[:commit] ||= DEFAULT_OPTIONS[:commit]
58
+ @options[:format] ||= DEFAULT_OPTIONS[:format]
59
+ @options[:access_token] ||=
60
+ ENV['BUNDLER_DIFF_GITHUB_TOKEN'] || ENV['GITHUB_TOKEN'] || hub_token
69
61
  end
70
62
 
71
63
  def set_access_token!
72
- return if GemsComparator.config.client.access_token
64
+ return if @options[:access_token].nil?
65
+
66
+ GemsComparator.configure do |config|
67
+ config.client = Octokit::Client.new(access_token: @options[:access_token])
68
+ end
69
+ end
70
+
71
+ def hub_token
73
72
  hub_config_path = "#{ENV['HOME']}/.config/hub"
74
73
  return unless File.exist?(hub_config_path)
75
74
 
76
75
  yaml = YAML.load_file(hub_config_path)
77
- oauth_token = yaml.dig('github.com', 0, 'oauth_token')
78
- return if oauth_token.nil?
79
- GemsComparator.configure do |config|
80
- config.client = Octokit::Client.new(access_token: oauth_token)
81
- end
76
+ yaml.dig('github.com', 0, 'oauth_token')
82
77
  end
83
78
 
84
79
  def commit
85
- @commit || DEFAULT_OPTIONS[:commit]
80
+ @options[:commit]
86
81
  end
87
82
 
88
83
  def formatter
89
- format = @format || DEFAULT_OPTIONS[:format]
84
+ format = @options[:format]
90
85
  BundlerDiff.formatters[format] || Formatter::Default
91
86
  end
92
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BundlerDiff
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-14 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gems_comparator
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.7.6
146
+ rubygems_version: 2.7.7
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: A gem support your "bundle update"