fuci 0.2.0 → 0.3.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: d6ac65a1e15ae2e4186b03e0988dc5fae93b789d
4
- data.tar.gz: 19a5f43ed5018e7dc30491539b15e6948c35eef9
3
+ metadata.gz: b5ba244bcdcab4ce2878400e677ac26b989f7900
4
+ data.tar.gz: 1b12e99347df18f93d5cee35a8440e17c59d4586
5
5
  SHA512:
6
- metadata.gz: ec5f4d3c0008ab34b53769bc3e0fcb3e8548927e26a113d9ad7266b4c240f027ef0aa9582356f417b31975024c9988dccf3aa2bb629d13454353820741812c16
7
- data.tar.gz: 2a5b14f07f033c41f3701260c344096efdf78d37db351c788936541e9da5737a07a7669b4cc47eee530218a3ce883d7e63859a10be51a3ebf0275cc7c61f088a
6
+ metadata.gz: bf6727e01bf54307aea86683af8faaf1ad9ca6d454f441c859777c56e18839e7659dd627d68ec9ce52ccce84ae40dc43a59964f52840bfeb9ba056d9c7ed3a76
7
+ data.tar.gz: e3e318715eca38d250c7c98d4f86efb5b459cf730ec03bf4dc282965d18f5dad8d9c4b4c54eef3f4b6f855b2489012f220a068266160ebf475d25bfcd0f6668b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### version 0.3.0 *August 5, 2013*
2
+ * Adds three methods to Git helper:
3
+ 1. `#remote_sha_from(branch_name)`
4
+ 2. `#pull_merge_sha_from(branch_name)`
5
+ 3. `#pull_number_from(branch_name`
6
+
1
7
  ### version 0.2.0 *July 31, 2013*
2
8
  * Offers command-line option (`--last`, `-l`) which runs failed tests
3
9
  from last call to `fuci`
data/lib/fuci/git.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  module Fuci
2
2
  module Git
3
- CURRENT_BRANCH_COMMAND = "git branch | sed -n '/\* /s///p'"
4
- REMOTE_MASTER_SHA_COMMAND = "git rev-parse origin/master"
5
- REMOTE_REPO_COMMAND =
3
+ MASTER = 'master'
4
+ CURRENT_BRANCH_COMMAND = "git branch | sed -n '/\* /s///p'"
5
+ REMOTE_REPO_COMMAND =
6
6
  "git remote -v | grep origin | grep push | awk 'match($0, /:\(.*)\.git/) { print substr($0, RSTART+1, RLENGTH-5) }'"
7
+ REMOTE_SHA_FROM_BRANCH_COMMAND =
8
+ lambda { |branch_name| "git rev-parse origin/#{branch_name}" }
9
+ PULL_MERGE_SHA_FROM_NUMBER_COMMAND =
10
+ lambda { |pull_number| "git ls-remote origin | grep refs\\/pull\\/#{pull_number}\\/merge | awk '{ print $1 };'" }
11
+ PULL_NUMBER_FROM_SHA_COMMAND =
12
+ lambda { |sha| "git ls-remote origin | grep #{sha} | grep pull | perl -n -e '/pull\\/(.*)\\/head/ && print $1'" }
7
13
 
8
14
  def current_branch_name
9
15
  with_popen current_branch_command
@@ -14,14 +20,37 @@ module Fuci
14
20
  end
15
21
 
16
22
  def remote_master_sha
17
- with_popen remote_master_sha_command
23
+ with_popen remote_sha_from_branch_command(MASTER)
24
+ end
25
+
26
+ def remote_sha_from branch_name
27
+ with_popen remote_sha_from_branch_command(branch_name)
28
+ end
29
+
30
+ def pull_merge_sha_from branch_name
31
+ pull_number = pull_number_from branch_name
32
+ with_popen pull_merge_sha_command(pull_number)
33
+ end
34
+
35
+ def pull_number_from branch_name
36
+ remote_sha = remote_sha_from branch_name
37
+
38
+ begin
39
+ with_popen pull_number_from_sha_command(remote_sha)
40
+ rescue NoResponseError
41
+ raise NoPullError
42
+ end
18
43
  end
19
44
 
20
45
  private
21
46
 
22
47
  def with_popen command
23
48
  IO.popen command do |io|
24
- io.first.chomp
49
+ if first_line = io.first
50
+ first_line.chomp
51
+ else
52
+ raise NoResponseError
53
+ end
25
54
  end
26
55
  end
27
56
 
@@ -33,8 +62,19 @@ module Fuci
33
62
  REMOTE_REPO_COMMAND
34
63
  end
35
64
 
36
- def remote_master_sha_command
37
- REMOTE_MASTER_SHA_COMMAND
65
+ def remote_sha_from_branch_command branch_name
66
+ REMOTE_SHA_FROM_BRANCH_COMMAND.(branch_name)
67
+ end
68
+
69
+ def pull_merge_sha_command pull_number
70
+ PULL_MERGE_SHA_FROM_NUMBER_COMMAND.(pull_number)
38
71
  end
72
+
73
+ def pull_number_from_sha_command sha
74
+ PULL_NUMBER_FROM_SHA_COMMAND.(sha)
75
+ end
76
+
77
+ class NoResponseError < StandardError; end;
78
+ class NoPullError < StandardError; end;
39
79
  end
40
80
  end
data/lib/fuci/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fuci
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -30,20 +30,91 @@ describe Fuci::Git do
30
30
 
31
31
  describe '#remote_master_sha' do
32
32
  it 'returns the remote master sha' do
33
- @test_class.stubs(:remote_master_sha_command).
34
- returns remote_master_sha_command = mock
35
- @test_class.expects(:with_popen).with remote_master_sha_command
33
+ @test_class.stubs(:remote_sha_from_branch_command).
34
+ with('master').
35
+ returns command = mock
36
+ @test_class.expects(:with_popen).with command
36
37
 
37
38
  @test_class.remote_master_sha
38
39
  end
39
40
  end
40
41
 
42
+ describe '#remote_sha_from' do
43
+ it 'returns the remote sha from the branch name passed in' do
44
+ @test_class.stubs(:remote_sha_from_branch_command).
45
+ with(branch_name = 'branch_name').
46
+ returns command = mock
47
+ @test_class.expects(:with_popen).with command
48
+
49
+ @test_class.remote_sha_from branch_name
50
+ end
51
+ end
52
+
53
+ describe '#pull_merge_sha_from' do
54
+ it 'gets the merge sha from the pull number' do
55
+ @test_class.stubs(:pull_number_from).
56
+ with(branch_name = 'branch_name').
57
+ returns pull_number = 1
58
+ @test_class.stubs(:pull_merge_sha_command).
59
+ with(pull_number).
60
+ returns command = mock
61
+ @test_class.stubs(:with_popen).
62
+ with(command).
63
+ returns sha = 'didizxndfjii223994w'
64
+
65
+ expect(@test_class.pull_merge_sha_from(branch_name)).to_equal sha
66
+ end
67
+ end
68
+
69
+ describe '#pull_number_from' do
70
+ before do
71
+ @branch_name = 'branch_name'
72
+ command = mock
73
+ remote_sha = '12k3asdifi23ia92'
74
+ @test_class.stubs(:remote_sha_from).
75
+ with(@branch_name).
76
+ returns remote_sha
77
+ @test_class.stubs(:pull_number_from_sha_command).
78
+ with(remote_sha).
79
+ returns command
80
+ @with_popen = @test_class.stubs(:with_popen).with command
81
+ end
82
+
83
+ describe 'when there is a pull number' do
84
+ before { @with_popen.returns @pull_number = '1' }
85
+
86
+ it 'returns the pull number with the remote sha' do
87
+ expect(@test_class.pull_number_from(@branch_name)).
88
+ to_equal @pull_number
89
+ end
90
+ end
91
+
92
+ describe 'when there is no pull number' do
93
+ before { @with_popen.raises Fuci::Git::NoResponseError }
94
+
95
+ it 'raises a NoPullError' do
96
+ expect { @test_class.pull_number_from(@branch_name) }.
97
+ to_raise Fuci::Git::NoPullError
98
+ end
99
+ end
100
+ end
101
+
41
102
  describe '#with_popen' do
42
- it 'runs the command with popen' do
43
- current_branch = 'current_branch'
44
- result = @test_class.send :with_popen, "echo #{current_branch}"
103
+ describe 'when there is a string response' do
104
+ it 'runs the command with popen' do
105
+ current_branch = 'current_branch'
106
+ result = @test_class.send :with_popen, "echo #{current_branch}"
107
+
108
+ expect(result).to_equal current_branch
109
+ end
110
+ end
111
+
112
+ describe 'when the response is nil' do
113
+ it 'raises a no response error' do
114
+ IO.stubs(:popen).with(command = '').yields []
45
115
 
46
- expect(result).to_equal current_branch
116
+ expect { @test_class.send :with_popen, command }.to_raise Fuci::Git::NoResponseError
117
+ end
47
118
  end
48
119
  end
49
120
 
@@ -61,10 +132,27 @@ describe Fuci::Git do
61
132
  end
62
133
  end
63
134
 
64
- describe '#remote_master_sha_command' do
65
- it 'returns the git/unix command to return the remote master sha' do
66
- current_branch_command = @test_class.send :remote_master_sha_command
67
- expect(current_branch_command).to_equal "git rev-parse origin/master"
135
+ describe '#remote_sha_from_branch_command' do
136
+ it 'returns the git/unix command to return the remote sha from the branch' do
137
+ branch_name = 'branch_name'
138
+ command = @test_class.send :remote_sha_from_branch_command, branch_name
139
+ expect(command).to_equal "git rev-parse origin/#{branch_name}"
140
+ end
141
+ end
142
+
143
+ describe '#pull_merge_sha_command' do
144
+ it 'is the pull merge sha command with the pull number' do
145
+ pull_number = 1
146
+ command = @test_class.send :pull_merge_sha_command, pull_number
147
+ expect(command).to_equal "git ls-remote origin | grep refs\\/pull\\/#{pull_number}\\/merge | awk '{ print $1 };'"
148
+ end
149
+ end
150
+
151
+ describe '#pull_number_from_sha_command' do
152
+ it 'gets the pull number with the sha' do
153
+ sha = '234asdf'
154
+ command = @test_class.send :pull_number_from_sha_command, sha
155
+ expect(command).to_equal "git ls-remote origin | grep #{sha} | grep pull | perl -n -e '/pull\\/(.*)\\/head/ && print $1'"
68
156
  end
69
157
  end
70
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Jachimiak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2013-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest-spec-expect