git_manager 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/git_manager.rb CHANGED
@@ -1,29 +1,180 @@
1
1
  require 'rubygems'
2
+
3
+ # usage Git::Blames::Pending.new(
4
+ # :root => <root folder where build logs are located>
5
+ # :rspec => boolean specifying whether or
6
+ # not you want to run rspec now to get pending specs
7
+ # ).blame
8
+ # usage Git::Managed::Branch.new.delete_branches
9
+
2
10
  module Git
3
- class Manager
4
- attr_accessor :branches, :current_branch, :branches_to_delete
5
- def initialize
6
- @branches = `git branch`.split /\n/
7
- partition_branches
8
- end
9
- def partition_branches
10
- @current_branch = @branches.select {|branch| branch.match /^\*/}.first
11
- @branches_to_delete = @branches.select {|branch| branch != @current_branch }
12
- @current_branch.chomp!
13
- @current_branch.gsub! /\s|\*/, ''
14
- end
15
-
16
- def delete_branches
17
- return false if @branches_to_delete.length == 0
18
- @branches_to_delete.each do |branch|
19
- delete_branch( branch.gsub /\s/, '' )
11
+ module Managed
12
+ class Branch
13
+ end
14
+ end
15
+ module Blames
16
+ def blame
17
+ self.tasks.each_pair do |key, attributes|
18
+ puts "\nPending Spec Information:"
19
+ puts " Description: #{key}"
20
+ puts " Contributors: #{attributes[:contributors].join(', ')}"
21
+ puts " File: #{attributes[:spec_file]}"
22
+ puts " Line: #{attributes[:line_number]}\n"
20
23
  end
21
24
  end
25
+ class Pending
26
+ end
27
+ class Blame
28
+ end
29
+ end
30
+ end
31
+
32
+ class Git::Managed::Branch
33
+ attr_accessor :branches, :current_branch, :branches_to_delete
34
+ def initialize
35
+ @branches = `git branch`.split /\n/
36
+ partition_branches
37
+ end
38
+ def partition_branches
39
+ @current_branch = @branches.select {|branch| branch.match /^\*/}.first
40
+ @branches_to_delete = @branches.select {|branch| branch != @current_branch }
41
+ @current_branch.chomp!
42
+ @current_branch.gsub! /\s|\*/, ''
43
+ end
22
44
 
23
- def delete_branch branch
24
- `git branch -D #{branch}`
45
+ def delete_branches
46
+ return false if @branches_to_delete.length == 0
47
+ @branches_to_delete.each do |branch|
48
+ delete_branch( branch.gsub /\s/, '' )
25
49
  end
50
+ end
26
51
 
52
+ def delete_branch branch
53
+ `git branch -D #{branch}`
27
54
  end
55
+
28
56
  end
29
57
 
58
+ class Git::Blames::Pending
59
+ attr_accessor :tasks, :rspec_results
60
+
61
+ include Git::Blames
62
+
63
+ def initialize options = nil
64
+ if options.nil? || options[:root].nil? && !options[:rspec]
65
+ @root = "#{File.dirname(__FILE__)}/logs"
66
+ elsif options[:rspec]
67
+ find_pending_specs_by_rspec_results( rspec_results )
68
+ else
69
+ @root = options[:root]
70
+ find_pending_specs_by_logfile_name( "#{@root}/#{find_last_logfile_name}" )
71
+ end
72
+ find_contributors
73
+ end
74
+
75
+ def rspec_results
76
+ rspec_output = `rspec spec`
77
+ puts rspec_output
78
+ rspec_output
79
+ end
80
+
81
+ def find_contributors
82
+ # @tasks = Git::Blames::Pending.new.tasks
83
+ contributors = []
84
+ @tasks.each_pair do |key, attributes|
85
+ `git blame "#{attributes[:spec_file]}"`.each do |blame|
86
+ contributor = blame.split(")")[0].split("(")[1]
87
+ contributor = contributor.split(/\s+\d/)[0]
88
+ contributors.push( contributor )
89
+ end
90
+ @tasks[key][:contributors] = contributors.uniq
91
+ @tasks[key][:contributors].reject!{ |contributor| contributor == 'Not Committed Yet'}
92
+ end
93
+ @tasks
94
+ end
95
+
96
+ def found_pending_marker line
97
+ line.match( /^[\s\t]*Pending:/ )
98
+ end
99
+
100
+ def found_new_spec_marker line, status
101
+ ( status == 'start' || status == 'updating spec data' ) && !line.match( /^[\s\t]*#/ )
102
+ end
103
+
104
+ def found_spec_details_marker line, status
105
+ ( status == 'found new pending spec' || status == 'updating spec data' ) && line.match( /^[\s\t]*\#/ )
106
+ end
107
+
108
+ def find_last_logfile_name
109
+ begin
110
+ files = Dir.new @root
111
+ rescue => e
112
+ begin
113
+ Dir.mkdir @root
114
+ files = Dir.new @root
115
+ rescue
116
+ puts e
117
+ end
118
+ end
119
+ files.to_a.select { |log| log.match /\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}/ }.sort.last
120
+ end
121
+
122
+ def find_pending_specs_by_rspec_results spec_output
123
+ status = ''
124
+ @tasks = {}
125
+ task = {}
126
+
127
+ spec_output.each do |line|
128
+ puts "line = #{line}"
129
+ if found_pending_marker line
130
+ status = 'start'
131
+
132
+ elsif found_new_spec_marker line, status
133
+ status = 'found new pending spec'
134
+ task = {}
135
+ task[:name] = line.chomp
136
+ task[:details] = []
137
+
138
+ elsif found_spec_details_marker line, status
139
+ status = 'updating spec data'
140
+ if line.match /(spec.*)[:](\d+)/
141
+ task[:spec_file] = $1
142
+ task[:line_number] = $2
143
+ else
144
+ task[:details].push line.chomp
145
+ end
146
+ @tasks[task[:name]] = task
147
+ end
148
+ end
149
+ end
150
+
151
+ def find_pending_specs_by_logfile_name logfile_name
152
+ logfile = File.new( logfile_name )
153
+ status = ''
154
+ @tasks = {}
155
+ task = {}
156
+
157
+ logfile.readlines.each do |line|
158
+
159
+ if found_pending_marker line
160
+ status = 'start'
161
+
162
+ elsif found_new_spec_marker line, status
163
+ status = 'found new pending spec'
164
+ task = {}
165
+ task[:name] = line.chomp
166
+ task[:details] = []
167
+
168
+ elsif found_spec_details_marker line, status
169
+ status = 'updating spec data'
170
+ if line.match /(spec.*)[:](\d+)/
171
+ task[:spec_file] = $1
172
+ task[:line_number] = $2
173
+ else
174
+ task[:details].push line.chomp
175
+ end
176
+ @tasks[task[:name]] = task
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,11 @@
1
+ Pending:
2
+ Fake test 1 spec/git_manager_spec.rb
3
+ # Test 123
4
+ # ./spec/git_manager_spec.rb:13
5
+ Fake test 2 spec/git_manager_spec.rb
6
+ # Test 123
7
+ # ./spec/git_manager_spec.rb:11
8
+
9
+ Finished in x minutes y seconds
10
+ z examples, 0 failures, 2 pending
11
+ Finished: SUCCESS
@@ -2,33 +2,83 @@ require 'rubygems'
2
2
  require 'rspec'
3
3
  require 'git_manager'
4
4
 
5
- describe Git::Manager do
6
- before :each do
7
- @git_manager = Git::Manager.new
8
- end
9
- it "has branches" do
10
- @git_manager.branches.should_not be_nil
11
- end
12
- it "has branches array" do
13
- @git_manager.branches.class.should == Array
14
- end
15
- it "knows about current branch" do
16
- @git_manager.current_branch.should == 'master'
5
+ describe Git do
6
+ describe Git::Managed::Branch do
7
+ before :each do
8
+ @git_manager = Git::Managed::Branch.new
9
+ end
10
+ it "has branches" do
11
+ @git_manager.branches.should_not be_nil
12
+ end
13
+ it "has branches array" do
14
+ @git_manager.branches.class.should == Array
15
+ end
16
+ it "knows about current branch" do
17
+ @git_manager.current_branch.should == 'master'
18
+ end
19
+ it "knows about branches to delete" do
20
+ @git_manager.branches_to_delete.should_not be_nil
21
+ end
22
+ it "aborts if branches to delete is empty" do
23
+ @git_manager.branches_to_delete = []
24
+ @git_manager.delete_branches.should == false
25
+ end
26
+ it "deltes branches to delete if NOT empty" do
27
+ @fake_branch_name = 'some_fake_branch'
28
+ Git::Managed::Branch.any_instance.stub(:delete_branch).and_return( true )
29
+
30
+ @git_manager.branches_to_delete = ['some_fake_branch']
31
+ @git_manager.delete_branches.should_not == false
32
+ end
17
33
  end
18
- it "knows about branches to delete" do
19
- @git_manager.branches_to_delete.should_not be_nil
20
- end
21
- it "aborts if branches to delete is empty" do
22
- @git_manager.branches_to_delete = []
23
- @git_manager.delete_branches.should == false
24
- end
25
- it "deltes branches to delete if NOT empty" do
26
- @fake_branch_name = 'some_fake_branch'
27
- Git::Manager.any_instance.stub(:delete_branch).and_return( true )
34
+
35
+ describe Git::Blames::Pending do
36
+ before :each do
37
+ Git::Blames::Pending.any_instance.stub(:rspec_results){'mr huxtable'}
38
+ @test_01 = ' Fake test 1 spec/git_manager_spec.rb'
39
+ @test_02 = ' Fake test 2 spec/git_manager_spec.rb'
40
+ @git_blames_pending = Git::Blames::Pending.new(:root => './lib/logs')
41
+ @expected_tasks = {
42
+ @test_01 => {
43
+ :spec_file => 'spec/git_manager_spec.rb',
44
+ :details=>[" # Test 123"],
45
+ :line_number => '13',
46
+ :contributors => ['John Jimenez'],
47
+ :name => " Fake test 1 spec/git_manager_spec.rb"
48
+ },
49
+ @test_02 => {
50
+ :spec_file => 'spec/git_manager_spec.rb',
51
+ :details=>[" # Test 123"],
52
+ :line_number => '11',
53
+ :contributors => ['John Jimenez'],
54
+ :name => " Fake test 2 spec/git_manager_spec.rb"
55
+ }
56
+ }
57
+ end
58
+
59
+ it "collects pending specs as expected" do
60
+ @git_blames_pending.tasks[@test_01][:spec_file].should == @expected_tasks[@test_01][:spec_file]
61
+ @git_blames_pending.tasks[@test_02][:spec_file].should == @expected_tasks[@test_02][:spec_file]
62
+ end
28
63
 
29
- @git_manager.branches_to_delete = ['some_fake_branch']
30
- @git_manager.delete_branches.should_not == false
31
- end
32
- end
64
+ it "collects pending spec line number as expected" do
65
+ @git_blames_pending.tasks[@test_01][:line_number].should == @expected_tasks[@test_01][:line_number]
66
+ @git_blames_pending.tasks[@test_02][:line_number].should == @expected_tasks[@test_02][:line_number]
67
+ end
68
+
69
+ it "collects pending spec name as expected" do
70
+ @git_blames_pending.tasks[@test_01][:spec_name].should == @expected_tasks[@test_01][:spec_name]
71
+ @git_blames_pending.tasks[@test_02][:spec_name].should == @expected_tasks[@test_02][:spec_name]
72
+ end
33
73
 
74
+ it "collects pending spec contributors as expected" do
75
+ @git_blames_pending.tasks[@test_01][:contributors].should == @expected_tasks[@test_01][:contributors]
76
+ @git_blames_pending.tasks[@test_02][:contributors].should == @expected_tasks[@test_02][:contributors]
77
+ end
34
78
 
79
+ it "collects pending spec details as expected" do
80
+ @git_blames_pending.tasks[@test_01][:details].should == @expected_tasks[@test_01][:details]
81
+ @git_blames_pending.tasks[@test_02][:details].should == @expected_tasks[@test_02][:details]
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_manager
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - kikuchiyo
@@ -15,10 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-11 00:00:00 Z
18
+ date: 2012-08-21 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
- description: all local branches, but one you are on
21
+ description: delete old git branches and blame pending specs
22
22
  email: kikuchiyo6@gmail.com
23
23
  executables: []
24
24
 
@@ -28,6 +28,7 @@ extra_rdoc_files: []
28
28
 
29
29
  files:
30
30
  - lib/git_manager.rb
31
+ - lib/logs/2012-08-21_00-00-01
31
32
  - spec/git_manager_spec.rb
32
33
  homepage: http://rubygems.org/gems/git_manager
33
34
  licenses: []
@@ -61,6 +62,7 @@ rubyforge_project:
61
62
  rubygems_version: 1.8.24
62
63
  signing_key:
63
64
  specification_version: 3
64
- summary: manage git
65
+ summary: gem to manage git
65
66
  test_files:
66
67
  - spec/git_manager_spec.rb
68
+ has_rdoc: