conditional_dcommit 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alf Mikula
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ = conditional_dcommit
2
+
3
+ A command for running your commit tests, rebasing, rerunning if necessary, and dcommitting once everything is all good.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Alf Mikula. See LICENSE for details.
8
+ growlNotify.applescript redistributed with permission from Mike Hagedorn.
9
+ Traffic light image provided by Believe Collective (http://www.flickr.com/photos/chainedreactions/)
10
+ Stop sign image provided by ladybeames (http://www.flickr.com/photos/50906336@N00/)
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "conditional_dcommit"
8
+ gem.summary = %Q{Loops through rebase and test until tests pass and there are no new changes in the repository, then issues a git svn dcommit.}
9
+ gem.email = "amikula@gmail.com"
10
+ gem.homepage = "http://github.com/amikula/conditional_dcommit"
11
+ gem.authors = ["Alf Mikula"]
12
+ gem.files.concat(FileList['data/**/*'])
13
+ %w[open4].each{|d| gem.add_dependency d}
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ require 'rake/rdoctask'
21
+ Rake::RDocTask.new do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'conditional_dcommit'
24
+ rdoc.options << '--line-numbers' << '--inline-source'
25
+ rdoc.rdoc_files.include('README*')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
27
+ end
28
+
29
+ require 'spec/rake/spectask'
30
+ Spec::Rake::SpecTask.new(:spec) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.spec_files = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
36
+ spec.libs << 'lib' << 'spec'
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+
42
+ task :default => :spec
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 3
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
+ require 'conditional_dcommit/command'
4
+ exit ::ConditionalDcommit::Command.new.main
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{conditional_dcommit}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alf Mikula"]
12
+ s.date = %q{2009-09-29}
13
+ s.default_executable = %q{conditional_dcommit}
14
+ s.email = %q{amikula@gmail.com}
15
+ s.executables = ["conditional_dcommit"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION.yml",
26
+ "bin/conditional_dcommit",
27
+ "conditional_dcommit.gemspec",
28
+ "data/growlNotify.applescript",
29
+ "data/growlNotify.applescript",
30
+ "data/stop_sign.jpg",
31
+ "data/stop_sign.jpg",
32
+ "data/traffic_green.jpg",
33
+ "data/traffic_green.jpg",
34
+ "lib/conditional_dcommit.rb",
35
+ "lib/conditional_dcommit/command.rb",
36
+ "lib/conditional_dcommit/package.rb",
37
+ "spec/conditional_dcommit/command_spec.rb",
38
+ "spec/conditional_dcommit/package_spec.rb",
39
+ "spec/conditional_dcommit_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/amikula/conditional_dcommit}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.5}
46
+ s.summary = %q{Loops through rebase and test until tests pass and there are no new changes in the repository, then issues a git svn dcommit.}
47
+ s.test_files = [
48
+ "spec/conditional_dcommit/command_spec.rb",
49
+ "spec/conditional_dcommit/package_spec.rb",
50
+ "spec/conditional_dcommit_spec.rb",
51
+ "spec/spec_helper.rb"
52
+ ]
53
+
54
+ if s.respond_to? :specification_version then
55
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<open4>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<open4>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<open4>, [">= 0"])
65
+ end
66
+ end
@@ -0,0 +1,35 @@
1
+ -- growlNotify.applescript
2
+ --
3
+ -- Created by Mike Hagedorn on 2007-10-31.
4
+ -- Copyright (c) 2007 Silverchair Solutions. All rights reserved. http://www.silverchairsolutions.com
5
+ -- based on script from the growl website
6
+ -- works around the fact that growlnotify doesnt work on leopard
7
+
8
+ -- pass in like osascript growlNotify.applescript
9
+ on run argv
10
+ set rspectitle to item 1 of argv
11
+ set rspecmessage to item 2 of argv
12
+ set rspecimage to item 3 of argv
13
+ set rspecsticky to item 4 of argv
14
+
15
+ tell application "GrowlHelperApp"
16
+ -- Make a list of all the notification types
17
+ -- that this script will ever send:
18
+ set the allNotificationsList to {"RSpec Notification"}
19
+
20
+ -- Make a list of the notifications
21
+ -- that will be enabled by default.
22
+ -- Those not enabled by default can be enabled later
23
+ -- in the 'Applications' tab of the growl prefpane.
24
+ set the enabledNotificationsList to {"RSpec Notification"}
25
+
26
+ -- Register our script with growl.
27
+ -- You can optionally (as here) set a default icon
28
+ -- for this script's notifications.
29
+ register as application "Growl-RSpec AppleScript Notifications" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"
30
+
31
+ -- Send a Notification...
32
+ notify with name "RSpec Notification" title rspectitle description rspecmessage application name "Growl-RSpec AppleScript Notifications" image from location rspecimage sticky rspecsticky
33
+ end tell
34
+
35
+ end run
Binary file
Binary file
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'open4'
5
+
6
+ require 'conditional_dcommit/package'
7
+
8
+ module ConditionalDcommit
9
+ class Command
10
+ attr_accessor :status_code
11
+
12
+ def test_command
13
+ @test_command ||= if env_command = ENV['TEST_COMMAND']
14
+ env_command
15
+ elsif(File.exists?(cruise_file=File.join(%w{script cruise})))
16
+ cruise_file
17
+ else
18
+ 'rake'
19
+ end
20
+ end
21
+
22
+ def code_tests_ok?
23
+ puts "testing code"
24
+ system(test_command) ? true : false
25
+ end
26
+
27
+ def dcommit
28
+ puts "dcommitting"
29
+ system("git svn dcommit") ? true : false
30
+ end
31
+
32
+ def rebase
33
+ puts "rebasing"
34
+ pid, stdin, stdout, stderr = Open4.popen4('git svn rebase')
35
+ firstline = nil
36
+
37
+ until (firstline = stdout.gets) || (firsterror = stderr.gets)
38
+ end
39
+
40
+ puts "firstline: #{firstline}"
41
+ puts "firsterror: #{firsterror}"
42
+
43
+ matcher = /Current branch .* is up to date./
44
+
45
+ if (firsterror && firsterror.chomp =~ matcher) ||
46
+ (firstline && firstline.chomp =~ matcher)
47
+ retval = false
48
+ else
49
+ puts firstline || firsterror
50
+
51
+ while line = stdout.gets || stderr.gets
52
+ puts line
53
+ end
54
+ retval = true
55
+ end
56
+
57
+ ignored, status = Process::waitpid2 pid
58
+
59
+ raise StandardError.new("Error rebasing") if status != 0
60
+
61
+ puts "rebase return: #{retval.to_s}"
62
+
63
+ retval
64
+ end
65
+
66
+ def report_fail(message="Failed dcommit")
67
+ puts message
68
+ self.status_code = 255
69
+ growl('FAIL', message, Package.data_file('stop_sign.jpg'))
70
+ end
71
+
72
+ def report_success(message="Successful dcommit")
73
+ puts message
74
+ self.status_code = 0
75
+ growl('Success', message, Package.data_file('traffic_green.jpg'))
76
+ end
77
+
78
+ def growl(title, message, image, stick="yes")
79
+ growlNotify_file = Package.data_file('growlNotify.applescript')
80
+
81
+ system "osascript #{growlNotify_file} '#{title}' '#{message}' '#{image}' #{stick}"
82
+ end
83
+
84
+ def main
85
+ self.status_code = 254
86
+
87
+ begin
88
+ rebase
89
+
90
+ 5.times do
91
+ if code_tests_ok?
92
+ unless rebase
93
+ raise StandardError.new("Error dcommitting") unless dcommit
94
+ report_success
95
+ break
96
+ end
97
+ else
98
+ raise StandardError.new("Code tests failed")
99
+ end
100
+ end && report_fail("Too many tries")
101
+ rescue StandardError => err
102
+ report_fail(err.to_s)
103
+ end
104
+
105
+ self.status_code
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ module ConditionalDcommit
2
+ class Package
3
+ def self.data_path
4
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data'))
5
+ end
6
+
7
+ def self.data_file(filename)
8
+ File.join(data_path, filename)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ module ConditionalDcommit
2
+ end
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ require 'conditional_dcommit/command'
4
+
5
+ describe ConditionalDcommit::Command do
6
+ def subject
7
+ @subject ||= ConditionalDcommit::Command.new
8
+ end
9
+
10
+ describe :test_command do
11
+ before :each do
12
+ ENV.stub!(:[]).with('TEST_COMMAND').and_return(nil)
13
+ end
14
+
15
+ it "returns the environment variable 'TEST_COMMAND'" do
16
+ ENV.should_receive(:[]).with('TEST_COMMAND').and_return("test command")
17
+
18
+ subject.test_command.should == 'test command'
19
+ end
20
+
21
+ it "defaults to 'rake'" do
22
+ subject.test_command.should == 'rake'
23
+ end
24
+
25
+ it "caches the test_command value" do
26
+ ENV.should_receive(:[]).exactly(1).times.with('TEST_COMMAND').and_return(nil)
27
+
28
+ subject.test_command.should == 'rake'
29
+ subject.test_command.should == 'rake'
30
+ end
31
+
32
+ it "uses script/cruise if it's available" do
33
+ cruise_file = File.join(%w{script cruise})
34
+ File.should_receive(:exists?).with(cruise_file).and_return(true)
35
+
36
+ subject.test_command.should == cruise_file
37
+ end
38
+ end
39
+
40
+ describe :report_fail do
41
+ before(:each) do
42
+ subject.stub!(:puts)
43
+ subject.stub!(:growl)
44
+ end
45
+
46
+ it 'outputs the failure message to the console' do
47
+ subject.should_receive(:puts).with(:message)
48
+
49
+ subject.report_fail(:message)
50
+ end
51
+
52
+ it "sets status code to 255" do
53
+ subject.report_fail(:anything)
54
+
55
+ subject.status_code.should == 255
56
+ end
57
+
58
+ it "growls the message" do
59
+ subject.should_receive(:growl).with('FAIL', :message, anything)
60
+
61
+ subject.report_fail(:message)
62
+ end
63
+
64
+ it "growls with the failure image" do
65
+ ConditionalDcommit::Package.should_receive(:data_file).with('stop_sign.jpg').and_return(:stop_sign_file)
66
+ subject.should_receive(:growl).with('FAIL', anything, :stop_sign_file)
67
+
68
+ subject.report_fail(:message)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ require 'conditional_dcommit/package'
4
+
5
+ describe ConditionalDcommit::Package do
6
+ def subject
7
+ ConditionalDcommit::Package
8
+ end
9
+
10
+ describe :data_path do
11
+ it "should point to a directory containing data I care about" do
12
+ File.file?(File.join(subject.data_path, 'stop_sign.jpg')).should be_true
13
+ end
14
+ end
15
+
16
+ describe :data_file do
17
+ it "should return a path starting with data_path and ending with the data file specified" do
18
+ subject.data_file('foo').should == File.join(subject.data_path, 'foo')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe ConditionalDcommit do
4
+ # Add tests
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'conditional_dcommit'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conditional_dcommit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Alf Mikula
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-29 00:00:00 -07:00
13
+ default_executable: conditional_dcommit
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: open4
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: amikula@gmail.com
27
+ executables:
28
+ - conditional_dcommit
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.rdoc
38
+ - Rakefile
39
+ - VERSION.yml
40
+ - bin/conditional_dcommit
41
+ - conditional_dcommit.gemspec
42
+ - data/growlNotify.applescript
43
+ - data/stop_sign.jpg
44
+ - data/traffic_green.jpg
45
+ - lib/conditional_dcommit.rb
46
+ - lib/conditional_dcommit/command.rb
47
+ - lib/conditional_dcommit/package.rb
48
+ - spec/conditional_dcommit/command_spec.rb
49
+ - spec/conditional_dcommit/package_spec.rb
50
+ - spec/conditional_dcommit_spec.rb
51
+ - spec/spec_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/amikula/conditional_dcommit
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Loops through rebase and test until tests pass and there are no new changes in the repository, then issues a git svn dcommit.
80
+ test_files:
81
+ - spec/conditional_dcommit/command_spec.rb
82
+ - spec/conditional_dcommit/package_spec.rb
83
+ - spec/conditional_dcommit_spec.rb
84
+ - spec/spec_helper.rb