last_hit 0.0.15 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07ba59c386d41319e0087e3e28c788a744dae693
4
+ data.tar.gz: 6f7cd5e832a4b814d7a16e3ffcc2f4840b4718ba
5
+ SHA512:
6
+ metadata.gz: d6c11b245f9daee575d43c9cd0f8ed842138e463b35897d8e3cfcefb253cb68bfb6e7621856a44bc9ad2629af24266cf7ee27311fca4a3063f4495cab1fd2fc5
7
+ data.tar.gz: 399b0323100a284fdd0b260c3706430da011d65199bda40a85b6931ffe35e3b20ab4160ee68361ddabb54bb55728fec7f1fbf4f118828c2d36a8150c06cb9466
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LastHit
2
2
 
3
- Help you to run relevant tests
3
+ You push code to test server and they fails after centuries wating.
4
4
 
5
5
  ## Installation
6
6
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "last_hit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/last_hit ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "last_hit"
5
+
6
+ LastHit::Cli.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/last_hit.gemspec CHANGED
@@ -14,12 +14,13 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.executables = ['last_hit']
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.1"
24
- spec.add_dependency "rails"
24
+
25
+ spec.add_dependency 'thor', '~> 0.19.1'
25
26
  end
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+
3
+ class LastHit
4
+ class Cli < Thor
5
+ include Thor::Actions
6
+
7
+ desc 'modified_tests', 'Run tests which are currently modified'
8
+ def modified_tests
9
+ LastHit.modified_tests
10
+ end
11
+
12
+ desc 'all_tests', 'Run all tests which have been modified in the current branch'
13
+ method_option :base, aliases: '-b', desc: 'Base branch for compare', type: :string
14
+ def all_tests
15
+ LastHit.all_tests(options[:base])
16
+ end
17
+ end
18
+ end
@@ -1,14 +1,14 @@
1
- module LastHit
1
+ class LastHit
2
+ def self.config
3
+ yield(Configure) if block_given?
4
+ end
5
+
2
6
  class Configure
3
7
  @test_command = "bundle exec rspec"
4
8
  @default_base_branch = "development"
5
9
 
6
10
  class << self
7
11
  attr_accessor :test_command, :default_base_branch
8
-
9
- def config
10
- yield(self)
11
- end
12
12
  end
13
13
  end
14
14
  end
@@ -1,10 +1,10 @@
1
- module LastHit
1
+ class LastHit
2
2
  module FileFilter
3
- class SpecFilter
3
+ class Spec
4
4
  SPEC_REGEX = /\A.+_spec.rb\z/
5
5
 
6
6
  class << self
7
- def get_files(files)
7
+ def filter(files)
8
8
  files.select { |file| file =~ SPEC_REGEX }
9
9
  end
10
10
  end
@@ -0,0 +1,6 @@
1
+ require 'last_hit/file_filter/spec'
2
+
3
+ class LastHit
4
+ module FileFilter
5
+ end
6
+ end
@@ -0,0 +1,46 @@
1
+ class LastHit
2
+ module RcAdapter
3
+ class Git
4
+ class << self
5
+ def modified_files
6
+ `git status -z`.split("\x0").map { |line| line.split(" ").last }
7
+ end
8
+
9
+ def current_branch_files(base_branch)
10
+ current_sha = current_commit_sha
11
+ ancestor_sha = common_ancestor(current_branch, base_branch)
12
+
13
+ `git diff --name-only #{current_sha} #{ancestor_sha} -z`.split("\x0")
14
+ end
15
+
16
+ private
17
+
18
+ def current_branch
19
+ # NOTE: We need to remove the last 2 characters of the sha
20
+ # because they're white line characters
21
+ # E.g: "master\n" should become to "master"
22
+
23
+ `git rev-parse --abbrev-ref HEAD`[0..-2]
24
+ end
25
+
26
+ def current_commit_sha
27
+ # NOTE: We need to remove the last 2 characters of the sha
28
+ # because they're white line characters
29
+ # E.g: "b0fb765371777c8c8e340bbf32dc9f2e160ca998\n"
30
+ # should become "b0fb765371777c8c8e340bbf32dc9f2e160ca998"
31
+
32
+ `git rev-parse --verify HEAD`[0..-2]
33
+ end
34
+
35
+ def common_ancestor(branch_1, branch_2)
36
+ # NOTE: We need to remove the last 2 characters of the sha
37
+ # because they're white line characters
38
+ # E.g: "6b90b4e272b717a33cd40687b1914dd87022d3b0\n"
39
+ # should become "6b90b4e272b717a33cd40687b1914dd87022d3b0"
40
+
41
+ `git merge-base #{branch_1} #{branch_2}`[0..-2]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,6 @@
1
+ require 'last_hit/rc_adapter/git'
2
+
3
+ class LastHit
4
+ module RcAdapter
5
+ end
6
+ end
@@ -1,4 +1,4 @@
1
- module LastHit
1
+ class LastHit
2
2
  class TestHandler
3
3
  class << self
4
4
  def run(files)
@@ -1,3 +1,3 @@
1
- module LastHit
2
- VERSION = "0.0.15"
1
+ class LastHit
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/last_hit.rb CHANGED
@@ -1,29 +1,28 @@
1
1
  require "last_hit/version"
2
2
  require "last_hit/configure"
3
- require 'last_hit/railtie' if defined?(Rails::Railtie)
4
3
 
5
- require 'last_hit/rc_adapter/git_adapter'
6
- require 'last_hit/file_filter/spec_filter'
4
+ require 'last_hit/rc_adapter'
5
+ require 'last_hit/file_filter'
7
6
 
8
7
  require 'last_hit/test_handler'
9
8
 
10
- module LastHit
11
- class << self
12
- def run_modified_tests
13
- files = RcAdapter::GitAdapter.get_modified_files
14
- process(files)
15
- end
9
+ require 'last_hit/cli'
16
10
 
17
- def run_current_branch_tests(another_branch)
18
- files = RcAdapter::GitAdapter.get_current_branch_files(another_branch)
19
- process(files)
20
- end
11
+ class LastHit
12
+ def modified_tests
13
+ files = RcAdapter::Git.modified_files
14
+ process(files)
15
+ end
16
+
17
+ def all_tests(base_branch = Configure.default_base_branch)
18
+ files = RcAdapter::Git.current_branch_files(base_branch)
19
+ process(files)
20
+ end
21
21
 
22
- private
22
+ private
23
23
 
24
- def process(files)
25
- tests = FileFilter::SpecFilter.get_files(files)
26
- TestHandler.run(tests)
27
- end
24
+ def process(files)
25
+ tests = FileFilter::Spec.filter(files)
26
+ TestHandler.run(tests)
28
27
  end
29
28
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe LastHit::FileFilter::Spec do
4
+ describe '.filter' do
5
+ let(:files) { ['model.rb', 'model_spec.rb'] }
6
+ let(:spec_files) { ['model_spec.rb'] }
7
+
8
+ it 'return files with extension is spec' do
9
+ expect(LastHit::FileFilter::Spec.filter(files)).to eq(spec_files)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe LastHit::RcAdapter::Git do
4
+ describe '.modified_files' do
5
+ it 'true' do
6
+ expect(true).to be true
7
+ end
8
+ end
9
+
10
+ describe '.current_branch_files' do
11
+ it 'true' do
12
+ expect(true).to be true
13
+ end
14
+ end
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
1
3
  require 'last_hit'
metadata CHANGED
@@ -1,132 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: last_hit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Duc Le
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-25 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.7'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.7'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '10.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '10.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '3.1'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '3.1'
62
55
  - !ruby/object:Gem::Dependency
63
- name: rails
56
+ name: thor
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
- version: '0'
61
+ version: 0.19.1
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
- version: '0'
68
+ version: 0.19.1
78
69
  description: Working with GIT
79
70
  email:
80
71
  - leminhducktvn@gmail.com
81
- executables: []
72
+ executables:
73
+ - last_hit
82
74
  extensions: []
83
75
  extra_rdoc_files: []
84
76
  files:
85
- - .gitignore
77
+ - ".gitignore"
86
78
  - Gemfile
87
79
  - LICENSE.txt
88
80
  - README.md
89
81
  - Rakefile
82
+ - bin/console
83
+ - bin/last_hit
84
+ - bin/setup
90
85
  - last_hit.gemspec
91
86
  - lib/last_hit.rb
87
+ - lib/last_hit/cli.rb
92
88
  - lib/last_hit/configure.rb
93
- - lib/last_hit/file_filter/spec_filter.rb
94
- - lib/last_hit/railtie.rb
95
- - lib/last_hit/rc_adapter/git_adapter.rb
89
+ - lib/last_hit/file_filter.rb
90
+ - lib/last_hit/file_filter/spec.rb
91
+ - lib/last_hit/rc_adapter.rb
92
+ - lib/last_hit/rc_adapter/git.rb
96
93
  - lib/last_hit/test_handler.rb
97
94
  - lib/last_hit/version.rb
98
- - lib/tasks/last_hit.rake
95
+ - spec/file_filter/spec_spec.rb
96
+ - spec/rc_adapter/git_spec.rb
99
97
  - spec/spec_helper.rb
100
98
  homepage: ''
101
99
  licenses:
102
100
  - MIT
101
+ metadata: {}
103
102
  post_install_message:
104
103
  rdoc_options: []
105
104
  require_paths:
106
105
  - lib
107
106
  required_ruby_version: !ruby/object:Gem::Requirement
108
- none: false
109
107
  requirements:
110
- - - ! '>='
108
+ - - ">="
111
109
  - !ruby/object:Gem::Version
112
110
  version: '0'
113
- segments:
114
- - 0
115
- hash: -1844496156572415882
116
111
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
112
  requirements:
119
- - - ! '>='
113
+ - - ">="
120
114
  - !ruby/object:Gem::Version
121
115
  version: '0'
122
- segments:
123
- - 0
124
- hash: -1844496156572415882
125
116
  requirements: []
126
117
  rubyforge_project:
127
- rubygems_version: 1.8.23.2
118
+ rubygems_version: 2.5.1
128
119
  signing_key:
129
- specification_version: 3
120
+ specification_version: 4
130
121
  summary: Help you to run relevant tests
131
122
  test_files:
123
+ - spec/file_filter/spec_spec.rb
124
+ - spec/rc_adapter/git_spec.rb
132
125
  - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- require 'rails'
2
-
3
- module LastHit
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- Dir.glob("#{File.dirname(__FILE__)}/../tasks/*.rake", &method(:load))
7
- end
8
- end
9
- end
@@ -1,32 +0,0 @@
1
- module LastHit
2
- module RcAdapter
3
- class GitAdapter
4
- class << self
5
- def get_modified_files
6
- `git status -z`.split("\x0").map { |line| line.split(" ").last }
7
- end
8
-
9
- def get_current_branch_files(another_branch)
10
- current_sha = current_commit_sha
11
- ancestor_sha = common_ancestor(current_branch, another_branch)
12
-
13
- `git diff --name-only #{current_sha} #{ancestor_sha} -z`.split("\x0")
14
- end
15
-
16
- private
17
-
18
- def current_branch
19
- `git rev-parse --abbrev-ref HEAD`
20
- end
21
-
22
- def current_commit_sha
23
- `git rev-parse --verify HEAD`
24
- end
25
-
26
- def common_ancestor(branch_1, branch_2)
27
- `git merge-base #{branch_1} #{branch_2}`
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,12 +0,0 @@
1
- namespace :last_hit do
2
- desc "Run current modified tests before commiting"
3
- task :current_modified => :environment do
4
- LastHit.run_modified_tests
5
- end
6
-
7
- desc "Run all changed tests of a branch from its fork with another branch"
8
- task :current_branch, [:another_branch] => :environment do |task, args|
9
- args.with_defaults(another_branch: LastHit::Configure.default_base_branch)
10
- LastHit.run_current_branch_tests(args.another_branch)
11
- end
12
- end