xlymian-cijoe 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+
4
+ class CIJoe
5
+ module Talker
6
+ class TalkerRoom
7
+ def initialize(subdomain, options)
8
+ @subdomain = subdomain
9
+ @ssl = options[:ssl]
10
+ @room_id = options[:room]
11
+ @token = options[:token]
12
+ end
13
+
14
+ def leave
15
+ end
16
+
17
+ def speak msg
18
+ send msg
19
+ end
20
+
21
+ def paste msg
22
+ send msg
23
+ end
24
+
25
+ private
26
+
27
+ def send msg
28
+ uri = URI.parse("https://#{@subdomain}.talkerapp.com/rooms/#{@room_id}/messages.json")
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+ http.use_ssl = true
31
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+ request = Net::HTTP::Post.new(uri.request_uri)
33
+ request['X-Talker-Token'] = @token
34
+ request['Accept'] = 'application/json'
35
+ request['Content-Type'] = 'application/json'
36
+ params = {:message => msg}
37
+ request.set_form_data params
38
+ response = http.request(request)
39
+ end
40
+ end
41
+
42
+ def self.activate
43
+ if valid_config?
44
+
45
+ CIJoe::Build.class_eval do
46
+ include CIJoe::Talker
47
+ end
48
+
49
+ puts "Loaded Talker notifier"
50
+ else
51
+ puts "Can't load Talker notifier."
52
+ puts "Please add the following to your project's .git/config:"
53
+ puts "[talker]"
54
+ puts "\ttoken = yourtalkertoken"
55
+ puts "\tsubdomain = whatever"
56
+ puts "\troom_id = nnn"
57
+ puts "\tssl = false"
58
+ end
59
+ end
60
+
61
+ def self.config
62
+ @config ||= {
63
+ :subdomain => Config.talker.subdomain.to_s,
64
+ :token => Config.talker.token.to_s,
65
+ :room => Config.talker.room.to_s,
66
+ :ssl => Config.talker.ssl.to_s.strip == 'true'
67
+ }
68
+ end
69
+
70
+ def self.valid_config?
71
+ %w( subdomain token room ).all? do |key|
72
+ !config[key.intern].empty?
73
+ end
74
+ end
75
+
76
+ def notify
77
+ room.speak "#{short_message}. #{commit.url}"
78
+ room.paste full_message if failed?
79
+ room.leave
80
+ end
81
+
82
+ private
83
+ def room
84
+ @room ||= begin
85
+ config = Talker.config
86
+ options = {}
87
+ options[:ssl] = config[:ssl] ? true : false
88
+ options[:room] = config[:room]
89
+ options[:token] = config[:token]
90
+ TalkerRoom.new(config[:subdomain], options)
91
+ end
92
+ end
93
+
94
+ def short_message
95
+ "Build #{short_sha} of #{project} #{worked? ? "was successful" : "failed"}"
96
+ end
97
+
98
+ def full_message
99
+ <<-EOM
100
+ Commit Message: #{commit.message}
101
+ Commit Date: #{commit.committed_at}
102
+ Commit Author: #{commit.author}
103
+
104
+ #{clean_output}
105
+ EOM
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,3 @@
1
+ class CIJoe
2
+ Version = "0.2.1"
3
+ end
@@ -0,0 +1,65 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link href="<%= cijoe_root %>/screen.css" media="screen" rel="stylesheet" type="text/css" />
5
+ <link rel="shortcut icon" href="<%= cijoe_root %>/favicon.ico" type="image/x-icon" />
6
+ <title><%= h(joe.project) %>: CI Joe</title>
7
+ </head>
8
+ <body>
9
+ <div class="site">
10
+ <div class="title">
11
+ <a href="<%= cijoe_root %>/">CI Joe</a>
12
+ <span class="extra">because knowing is half the battle</span>
13
+ </div>
14
+
15
+ <div id="home">
16
+ <h1><a href="<%= joe.url %>"><%= joe.project %></a></h1>
17
+ <ul class="posts">
18
+ <% if joe.current_build %>
19
+ <li>
20
+ <span class="date"><%= pretty_time(joe.current_build.started_at) if joe.current_build %></span> &raquo;
21
+ <% if joe.current_build.sha %>
22
+ Building <a href="<%= joe.url %>/commits/<%= joe.current_build.sha %>"><%= joe.current_build.short_sha %></a> <small>(pid: <%= joe.pid %>)</small>
23
+ <% else %>
24
+ Build starting...
25
+ <% end %>
26
+ </li>
27
+ <% else %>
28
+ <li><form method="POST"><input type="submit" value="Build"/></form></li>
29
+ <% end %>
30
+
31
+ <% if joe.last_build %>
32
+ <li><span class="date"><%= pretty_time(joe.last_build.finished_at) %></span> &raquo; Built <a href="<%= joe.url %>/commits/<%= joe.last_build.sha %>"><%= joe.last_build.short_sha %></a> <span class="<%= joe.last_build.status %>">(<%= joe.last_build.status %>)</span></li>
33
+ <% if joe.last_build.failed? %>
34
+ <li><pre class="terminal"><code><%=ansi_color_codes h(joe.last_build.output) %></code></pre></li>
35
+ <% end %>
36
+ <% end %>
37
+ </ul>
38
+ </div>
39
+
40
+ <div class="footer">
41
+ <div class="contact">
42
+ <p>
43
+ <a href="http://github.com/defunkt/cijoe/tree/master#readme">Documentation</a><br/>
44
+ <a href="http://github.com/defunkt/cijoe">Source</a><br/>
45
+ <a href="http://github.com/defunkt/cijoe/issues">Issues</a><br/>
46
+ <a href="http://twitter.com/defunkt">Twitter</a>
47
+ </p>
48
+ </div>
49
+ <div class="contact">
50
+ <p>
51
+ Designed by <a href="http://tom.preston-werner.com/">Tom Preston-Werner</a><br/>
52
+ Influenced by <a href="http://integrityapp.com/">Integrity</a><br/>
53
+ Built with <a href="http://sinatrarb.com/">Sinatra</a><br/>
54
+ Keep it simple, Sam.
55
+ </p>
56
+ </div>
57
+ <div class="rss">
58
+ <a href="http://github.com/defunkt/cijoe">
59
+ <img src="<%= cijoe_root %>/octocat.png" alt="Octocat!" />
60
+ </a>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ </body>
65
+ </html>
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'cijoe'
7
+
8
+ CIJoe::Server.set :project_path, "."
9
+ CIJoe::Server.set :environment, "test"
10
+
11
+ class Test::Unit::TestCase
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class TestCIJoe < Test::Unit::TestCase
4
+ def test_raise_error_on_invalid_command
5
+ assert_raise RuntimeError, LoadError do
6
+ CIJoe::Config.new('--invalid').to_s
7
+ end
8
+ end
9
+
10
+ def test_return_value_of_config
11
+ assert_equal `git config blame`.chomp, CIJoe::Config.new('blame').to_s
12
+ end
13
+
14
+ def test_return_empty_string_when_config_does_not_exist
15
+ assert_equal '', CIJoe::Config.new('invalid').to_s
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ require "helper"
2
+ require "rack/test"
3
+ require "cijoe/server"
4
+
5
+ class TestCIJoeServer < Test::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ class ::CIJoe
9
+ attr_writer :current_build, :last_build
10
+ end
11
+
12
+ attr_accessor :app
13
+
14
+ def setup
15
+ @app = CIJoe::Server.new
16
+ end
17
+
18
+ def test_ping
19
+ app.joe.last_build = build :worked
20
+ assert !app.joe.building?, "have a last build, but not a current"
21
+
22
+ get "/ping"
23
+ assert_equal 200, last_response.status
24
+ assert_equal app.joe.last_build.sha, last_response.body
25
+ end
26
+
27
+ def test_ping_building
28
+ app.joe.current_build = build :building
29
+ assert app.joe.building?, "buildin' a awsum project"
30
+
31
+ get "/ping"
32
+ assert_equal 412, last_response.status
33
+ assert_equal "building", last_response.body
34
+ end
35
+
36
+ def test_ping_failed
37
+ app.joe.last_build = build :failed
38
+
39
+ get "/ping"
40
+ assert_equal 412, last_response.status
41
+ assert_equal app.joe.last_build.sha, last_response.body
42
+ end
43
+
44
+ # Create a new, fake build. All we care about is status.
45
+
46
+ def build status
47
+ CIJoe::Build.new "user", "project", Time.now, Time.now,
48
+ "deadbeef", status, "output", 1337
49
+ end
50
+ end
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{xlymian-cijoe}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Wanstrath"]
12
+ s.date = %q{2010-02-01}
13
+ s.default_executable = %q{cijoe}
14
+ s.description = %q{CI Joe is a simple Continuous Integration server.}
15
+ s.email = %q{chris@ozmm.org}
16
+ s.executables = ["cijoe"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "bin/cijoe",
27
+ "deps.rip",
28
+ "examples/cijoe.ru",
29
+ "examples/cijoed",
30
+ "lib/cijoe.rb",
31
+ "lib/cijoe/build.rb",
32
+ "lib/cijoe/campfire.rb",
33
+ "lib/cijoe/commit.rb",
34
+ "lib/cijoe/config.rb",
35
+ "lib/cijoe/public/favicon.ico",
36
+ "lib/cijoe/public/octocat.png",
37
+ "lib/cijoe/public/screen.css",
38
+ "lib/cijoe/server.rb",
39
+ "lib/cijoe/talker.rb",
40
+ "lib/cijoe/version.rb",
41
+ "lib/cijoe/views/template.erb",
42
+ "test/helper.rb",
43
+ "test/test_cijoe.rb",
44
+ "test/test_cijoe_server.rb",
45
+ "xlymian-cijoe.gemspec"
46
+ ]
47
+ s.homepage = %q{http://github.com/defunkt/cijoe}
48
+ s.rdoc_options = ["--charset=UTF-8"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.5}
51
+ s.summary = %q{CI Joe is a simple Continuous Integration server.}
52
+ s.test_files = [
53
+ "test/helper.rb",
54
+ "test/test_cijoe.rb",
55
+ "test/test_cijoe_server.rb"
56
+ ]
57
+
58
+ if s.respond_to? :specification_version then
59
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
63
+ s.add_runtime_dependency(%q<choice>, [">= 0"])
64
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
65
+ s.add_development_dependency(%q<rack-test>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<choice>, [">= 0"])
68
+ s.add_dependency(%q<sinatra>, [">= 0"])
69
+ s.add_dependency(%q<rack-test>, [">= 0"])
70
+ end
71
+ else
72
+ s.add_dependency(%q<choice>, [">= 0"])
73
+ s.add_dependency(%q<sinatra>, [">= 0"])
74
+ s.add_dependency(%q<rack-test>, [">= 0"])
75
+ end
76
+ end
77
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xlymian-cijoe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Wanstrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-01 00:00:00 -05:00
13
+ default_executable: cijoe
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: choice
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
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ description: CI Joe is a simple Continuous Integration server.
46
+ email: chris@ozmm.org
47
+ executables:
48
+ - cijoe
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.markdown
54
+ files:
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.markdown
58
+ - Rakefile
59
+ - bin/cijoe
60
+ - deps.rip
61
+ - examples/cijoe.ru
62
+ - examples/cijoed
63
+ - lib/cijoe.rb
64
+ - lib/cijoe/build.rb
65
+ - lib/cijoe/campfire.rb
66
+ - lib/cijoe/commit.rb
67
+ - lib/cijoe/config.rb
68
+ - lib/cijoe/public/favicon.ico
69
+ - lib/cijoe/public/octocat.png
70
+ - lib/cijoe/public/screen.css
71
+ - lib/cijoe/server.rb
72
+ - lib/cijoe/talker.rb
73
+ - lib/cijoe/version.rb
74
+ - lib/cijoe/views/template.erb
75
+ - test/helper.rb
76
+ - test/test_cijoe.rb
77
+ - test/test_cijoe_server.rb
78
+ - xlymian-cijoe.gemspec
79
+ has_rdoc: true
80
+ homepage: http://github.com/defunkt/cijoe
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: CI Joe is a simple Continuous Integration server.
107
+ test_files:
108
+ - test/helper.rb
109
+ - test/test_cijoe.rb
110
+ - test/test_cijoe_server.rb