tukune 0.0.3 → 0.1.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
  SHA1:
3
- metadata.gz: 73d08b6076a382f4cf209647056bfcce7a43f133
4
- data.tar.gz: 99146e70bef2a37a55df7cc8b72f83087a4d7485
3
+ metadata.gz: 5d4e98ddb41caa3e00a497df06da16bfc8fb57dd
4
+ data.tar.gz: c32e2e3aa97c537629c86ae00df2f34b5ba7c989
5
5
  SHA512:
6
- metadata.gz: c1e7cddf73594634ccb4cddb30f5653b0f2be8f54ccbff0084a9821933aca170dc91d19926e13c645ff85e6a129e5a475072f447563a013df17989a0d431ca84
7
- data.tar.gz: 5f0cc1005ff747072627982110e0066fdc7910bc27cf7845f47fbe0dda7103d83a1c0bd052333e9763fa339840992d346ca154a68c6fe2d8289bab005cf7878d
6
+ metadata.gz: 3bb90b2a43b70565ffc2bfa8f925f520449d2e6831bf954eb05c352a1046f9ed8c8f6ded35294e0f9c87a9a3f6f040af5cf3e6954be66401ea7f52050077e547
7
+ data.tar.gz: 8ba4b8c96f108d04814bce5f4b91ab2e2c36b3895f4b5b263f341e0cb8cdcab03222c195863b723aaa84d22c9293b4198096ea27daa44c0b13caa25393bafa75
@@ -16,3 +16,4 @@ Metrics/AbcSize:
16
16
  Metrics/MethodLength:
17
17
  Exclude:
18
18
  - lib/tukune/cli.rb
19
+ - lib/tukune/option_parser.rb
data/bin/tukune CHANGED
@@ -4,28 +4,7 @@ require 'bundler/setup'
4
4
  require 'tukune'
5
5
  require 'optparse'
6
6
 
7
- options = {}
8
- opt_parser = OptionParser.new do |opt|
9
- opt.banner = 'Usage: tukune [OPTIONS]'
10
- opt.separator ''
11
- opt.separator 'Options'
7
+ parser = Tukune::OptionParser.new
8
+ parser.parse!(ARGV)
12
9
 
13
- opt.on('-t', '--title TITLE', 'Pull request title') do |title|
14
- options[:title] = title
15
- end
16
-
17
- opt.on('-b', '--body BODY', 'Pull request body') do |body|
18
- options[:body] = body
19
- end
20
-
21
- opt.on('--enable-all') do |enable_all|
22
- options[:enable_all] = enable_all
23
- end
24
-
25
- opt.on('-h', '--help', 'help') do
26
- puts opt_parser
27
- end
28
- end
29
-
30
- opt_parser.parse!
31
- Tukune::CLI.start(options)
10
+ Tukune::CLI.start(parser.options)
@@ -1,6 +1,7 @@
1
1
  require 'github'
2
2
  require 'tukune/cli'
3
3
  require 'tukune/configuration'
4
+ require 'tukune/option_parser'
4
5
  require 'tukune/git/diff'
5
6
  require 'tukune/version'
6
7
 
@@ -3,16 +3,11 @@ module Tukune
3
3
  class << self
4
4
  def start(options)
5
5
  config = Tukune.configuration
6
- diff = Tukune::Git::Diff.name_status
6
+ diff = Tukune::Git::Diff.name_status(options[:target_paths])
7
7
  if config.tukune_branch?
8
8
  puts 'this branch is tukune'
9
9
  return
10
10
  end
11
- unless options[:enable_all] || config.pull_request?
12
- puts 'This build is not part of pull request.'
13
- puts 'If you want to exec tukune, try to use `--enable-all` option.'
14
- return
15
- end
16
11
  if diff.nothing_to_commit?
17
12
  puts 'nothing to commit, working directory clean'
18
13
  return
@@ -1,10 +1,14 @@
1
+ require 'mem'
2
+
1
3
  module Tukune
2
4
  module Git
3
5
  class Diff
6
+ include Mem
7
+
4
8
  attr_reader :changed_files
5
9
 
6
- def initialize(changed_files)
7
- @changed_files = changed_files
10
+ def initialize(target_paths)
11
+ @target_paths = target_paths.join(' ')
8
12
  end
9
13
 
10
14
  def nothing_to_commit?
@@ -12,21 +16,28 @@ module Tukune
12
16
  end
13
17
 
14
18
  def added_files
15
- `git ls-files --others --exclude-standard`.strip.split("\n")
19
+ `git ls-files --others --exclude-standard #{@target_paths}`.strip.split("\n")
16
20
  end
21
+ memoize :added_files
17
22
 
18
23
  def modified_files
19
24
  changed_files.select { |type, _| type == 'M' }.map { |_, name| name }
20
25
  end
26
+ memoize :modified_files
21
27
 
22
28
  def deleted_files
23
29
  changed_files.select { |type, _| type == 'D' }.map { |_, name| name }
24
30
  end
31
+ memoize :deleted_files
32
+
33
+ def changed_files
34
+ @changed_files ||= `git diff --name-status #{@target_paths}`.strip.split("\n").map { |e| e.split("\t") }
35
+ end
36
+ memoize :changed_files
25
37
 
26
38
  class << self
27
- def name_status
28
- changed_files ||= `git diff --name-status`.strip.split("\n").map { |e| e.split("\t") }
29
- Diff.new(changed_files)
39
+ def name_status(target_paths = [])
40
+ Diff.new(target_paths)
30
41
  end
31
42
  end
32
43
  end
@@ -0,0 +1,39 @@
1
+ module Tukune
2
+ class OptionParser
3
+ def initialize
4
+ @opt_parser = ::OptionParser.new do |opt|
5
+ opt.banner = 'Usage: tukune [OPTIONS]'
6
+ opt.separator ''
7
+ opt.separator 'Options'
8
+
9
+ opt.on('-t', '--title TITLE', 'Pull request title') do |title|
10
+ @title = title
11
+ end
12
+
13
+ opt.on('-b', '--body BODY', 'Pull request body') do |body|
14
+ @body = body
15
+ end
16
+
17
+ opt.on('--target-path V,V...', Array) do |path|
18
+ @target_paths = path
19
+ end
20
+
21
+ opt.on('-h', '--help', 'help') do
22
+ puts @opt_parser
23
+ end
24
+ end
25
+ end
26
+
27
+ def parse!(argv = @opt_parser.default_argv)
28
+ @opt_parser.parse!(argv)
29
+ end
30
+
31
+ def options
32
+ {
33
+ title: @title,
34
+ body: @body,
35
+ target_paths: @target_paths || []
36
+ }
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Tukune
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tukune
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gin0606
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-04 00:00:00.000000000 Z
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -138,6 +138,7 @@ files:
138
138
  - lib/tukune/configuration/default.rb
139
139
  - lib/tukune/configuration/travis_ci.rb
140
140
  - lib/tukune/git/diff.rb
141
+ - lib/tukune/option_parser.rb
141
142
  - lib/tukune/version.rb
142
143
  - tukune.gemspec
143
144
  homepage: https://github.com/gin0606/tukune