xxx-integrity-script 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ # Integrity Script Notifier
2
+
3
+ With this notifier, Integrity will call a script/program/whatever,
4
+ passing 'pass' or 'fail' as an argument, along with other optional args.
5
+
6
+ This was originally conceived so the author could have Integrity talk to a script that talks to an Arduino.
7
+
8
+
9
+ # Installation
10
+
11
+ 1. (sudo) gem install xxx-integrity-script --source http://gems.github.com
12
+
13
+ 2. In your config.ru add:
14
+
15
+ require "integrity/notifier/script"
16
+
17
+ 3. Restart Integrity, then hit your project in a browser to configure the notifier from there.
18
+
19
+ # Stuff
20
+
21
+ There are security implications here in that this is purposely opening up an arbitrary code execution, and nothing is done to prevent bad things from happening right now. Be aware of that. Do not use this code on public CI servers.
22
+
23
+
24
+ # License
25
+
26
+ (The MIT License)
27
+
28
+ Copyright (c) 2009 - M. Dungan
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ task :default => :test
2
+
3
+ task :test do
4
+ ruby "test/integrity_script_test.rb"
5
+ end
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gemspec|
10
+ gemspec.name = "integrity-script"
11
+ gemspec.summary = "Integrity notifier that runs an arbitrary script"
12
+ gemspec.description = "This notifier will execute a script of your choosing, passing pass/fail as well as any extra args you choose to it. It was originally conceived to be used to talk to an Arduino board"
13
+ gemspec.email = "mpd@jesters-court.net"
14
+ gemspec.homepage = "http://github.com/xxx/integrity-script"
15
+ gemspec.authors = ["Michael Dungan"]
16
+ end
17
+ rescue LoadError
18
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
20
+
21
+
22
+ #begin
23
+ # require "mg"
24
+ # MG.new("integrity-script.gemspec")
25
+ #rescue LoadError
26
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,50 @@
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{integrity-script}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael Dungan"]
12
+ s.date = %q{2009-09-14}
13
+ s.description = %q{This notifier will execute a script of your choosing, passing pass/fail as well as any extra args you choose to it. It was originally conceived to be used to talk to an Arduino board}
14
+ s.email = %q{mpd@jesters-court.net}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ "VERSION"
20
+ ]
21
+ s.homepage = %q{http://github.com/xxx/integrity-script}
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.rubygems_version = %q{1.3.5}
24
+ s.summary = %q{Integrity notifier that runs an arbitrary script}
25
+ s.test_files = [
26
+ "test/integrity_script_test.rb",
27
+ "test/test_script.rb"
28
+ ]
29
+
30
+ s.files = %w[
31
+ README.markdown
32
+ VERSION
33
+ Rakefile
34
+ integrity-script.gemspec
35
+ lib/integrity/notifier/config.haml
36
+ lib/integrity/notifier/script.rb
37
+ test/integrity_script_test.rb
38
+ test/test_script.rb
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ end
@@ -0,0 +1,8 @@
1
+ %p.normal
2
+ %label{ :for => "script_notifier_script_path" } Script path (make sure it's readable and executable!)
3
+ %input.text#script_notifier_script_path{ :name => "notifiers[Script][script_path]", :type => "text", :value => config["script_path"] }
4
+
5
+ %p.normal
6
+ %label{ :for => "script_notifier_extra_args" } Extra args, to be added at the end of the invocation.
7
+ %input.text#script_notifier_extra_args{ :name => "notifiers[Script][extra_args]", :type => "text", :value => config["extra_args"] }
8
+
@@ -0,0 +1,25 @@
1
+ require "integrity"
2
+
3
+ module Integrity
4
+ class Notifier
5
+ class Script < Notifier::Base
6
+ attr_reader :script_path, :extra_args
7
+
8
+ def self.to_haml
9
+ File.read(File.dirname(__FILE__) + "/config.haml")
10
+ end
11
+
12
+ def initialize(commit, config={})
13
+ @script_path = config.delete("script_path") || '/bin/echo'
14
+ @extra_args = config.delete("extra_args") || ''
15
+ super(commit, config)
16
+ end
17
+
18
+ def deliver!
19
+ `#{script_path} #{commit.successful? ? "pass" : "fail"} #{extra_args}`
20
+ end
21
+ end
22
+
23
+ register Script
24
+ end
25
+ end
@@ -0,0 +1,79 @@
1
+ require "test/unit"
2
+ require "integrity/notifier/test"
3
+
4
+ begin
5
+ require "redgreen"
6
+ rescue LoadError
7
+ end
8
+
9
+ require File.dirname(__FILE__) + "/../lib/integrity/notifier/script"
10
+
11
+ class IntegrityScriptTest < Test::Unit::TestCase
12
+ include Integrity::Notifier::Test
13
+
14
+ def notifier
15
+ "Script"
16
+ end
17
+
18
+ def setup
19
+ setup_database
20
+ end
21
+
22
+ def commit(status=:successful)
23
+ Integrity::Commit.gen(status)
24
+ end
25
+
26
+ def teardown
27
+ File.unlink(testing_file) if File.exist?(testing_file)
28
+ end
29
+
30
+ def test_it_passes_pass
31
+ line = get_arg_for_status(:successful)
32
+ assert_equal 'pass', line.chomp
33
+ end
34
+
35
+ def test_it_passes_fail
36
+ line = get_arg_for_status(:failed)
37
+ assert_equal 'fail', line.chomp
38
+ end
39
+
40
+ def test_it_passes_extra_args
41
+ line = nil
42
+ Integrity::Notifier::Script.new(commit,
43
+ 'script_path' => testing_script,
44
+ 'extra_args' => 'foobar').deliver!
45
+
46
+ File.open(testing_file, 'r') do |f|
47
+ f.gets # skip pass/fail
48
+ line = f.gets
49
+ end
50
+ assert_equal 'foobar', line.chomp
51
+ end
52
+
53
+ def test_configuration_form
54
+ assert form_have_tag? "#script_notifier_script_path"
55
+ assert form_have_tag? "#script_notifier_extra_args"
56
+ end
57
+
58
+ private
59
+
60
+ def get_arg_for_status(commit_status)
61
+ line = nil
62
+ Integrity::Notifier::Script.new(commit(commit_status),
63
+ 'script_path' => testing_script,
64
+ 'extra_args' => 'foobar').deliver!
65
+
66
+ File.open(testing_file, 'r') do |f|
67
+ line = f.gets
68
+ end
69
+ line
70
+ end
71
+
72
+ def testing_file
73
+ File.join(File.dirname(__FILE__), 'shumway.txt')
74
+ end
75
+
76
+ def testing_script
77
+ File.join(File.dirname(__FILE__), 'test_script.rb')
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ @arg = ARGV.first
4
+ @extra = ARGV.last
5
+
6
+ File.open(File.join(File.dirname(__FILE__), 'shumway.txt'), 'w') do |f|
7
+ f.write(@arg + "\n")
8
+ f.write(@extra + "\n")
9
+ end
10
+
11
+ exit 69
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xxx-integrity-script
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Dungan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This notifier will execute a script of your choosing, passing pass/fail as well as any extra args you choose to it. It was originally conceived to be used to talk to an Arduino board
17
+ email: mpd@jesters-court.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - README.markdown
26
+ - VERSION
27
+ - Rakefile
28
+ - integrity-script.gemspec
29
+ - lib/integrity/notifier/config.haml
30
+ - lib/integrity/notifier/script.rb
31
+ - test/integrity_script_test.rb
32
+ - test/test_script.rb
33
+ has_rdoc: false
34
+ homepage: http://github.com/xxx/integrity-script
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --charset=UTF-8
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Integrity notifier that runs an arbitrary script
59
+ test_files:
60
+ - test/integrity_script_test.rb
61
+ - test/test_script.rb