glennr-cijoe 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.markdown +170 -0
- data/Rakefile +68 -0
- data/bin/cijoe +51 -0
- data/cijoe.gemspec +77 -0
- data/deps.rip +4 -0
- data/examples/build-failed +22 -0
- data/examples/build-worked +22 -0
- data/examples/cijoe.ru +15 -0
- data/examples/cijoed +53 -0
- data/glennr-cijoe.gemspec +82 -0
- data/lib/cijoe.rb +233 -0
- data/lib/cijoe/build.rb +62 -0
- data/lib/cijoe/campfire.rb +70 -0
- data/lib/cijoe/commit.rb +27 -0
- data/lib/cijoe/config.rb +43 -0
- data/lib/cijoe/public/favicon.ico +0 -0
- data/lib/cijoe/public/octocat.png +0 -0
- data/lib/cijoe/public/screen.css +213 -0
- data/lib/cijoe/server.rb +91 -0
- data/lib/cijoe/version.rb +3 -0
- data/lib/cijoe/views/template.erb +70 -0
- data/test/helper.rb +12 -0
- data/test/test_cijoe.rb +17 -0
- data/test/test_cijoe_server.rb +50 -0
- metadata +150 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
class CIJoe
|
2
|
+
module Campfire
|
3
|
+
def self.activate(project_path)
|
4
|
+
@project_path = project_path
|
5
|
+
if valid_config?
|
6
|
+
require 'tinder'
|
7
|
+
|
8
|
+
CIJoe::Build.class_eval do
|
9
|
+
include CIJoe::Campfire
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "Loaded Campfire notifier"
|
13
|
+
else
|
14
|
+
puts "Can't load Campfire notifier."
|
15
|
+
puts "Please add the following to your project's .git/config:"
|
16
|
+
puts "[campfire]"
|
17
|
+
puts "\ttoken = your_api_token"
|
18
|
+
puts "\tsubdomain = whatever"
|
19
|
+
puts "\troom = Awesomeness"
|
20
|
+
puts "\tssl = false"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config
|
25
|
+
@config ||= {
|
26
|
+
:subdomain => Config.campfire(@project_path).subdomain.to_s,
|
27
|
+
:token => Config.campfire(@project_path).token.to_s,
|
28
|
+
:room => Config.campfire(@project_path).room.to_s,
|
29
|
+
:ssl => Config.campfire(@project_path).ssl.to_s.strip == 'true'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.valid_config?
|
34
|
+
%w( subdomain token room ).all? do |key|
|
35
|
+
!config[key.intern].empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def notify
|
40
|
+
room.speak "#{short_message}. #{commit.url}"
|
41
|
+
room.paste full_message if failed?
|
42
|
+
room.leave
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def room
|
47
|
+
@room ||= begin
|
48
|
+
config = Campfire.config
|
49
|
+
campfire = Tinder::Campfire.new(config[:subdomain],
|
50
|
+
:token => config[:token],
|
51
|
+
:ssl => config[:ssl] || false)
|
52
|
+
campfire.find_room_by_name(config[:room])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def short_message
|
57
|
+
"Build #{short_sha} of #{project} #{worked? ? "was successful" : "failed"}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def full_message
|
61
|
+
<<-EOM
|
62
|
+
Commit Message: #{commit.message}
|
63
|
+
Commit Date: #{commit.committed_at}
|
64
|
+
Commit Author: #{commit.author}
|
65
|
+
|
66
|
+
#{clean_output}
|
67
|
+
EOM
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/cijoe/commit.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class CIJoe
|
2
|
+
class Commit < Struct.new(:sha, :user, :project, :project_path)
|
3
|
+
def url
|
4
|
+
"http://github.com/#{user}/#{project}/commit/#{sha}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def author
|
8
|
+
raw_commit_lines.grep(/Author:/).first.split(':', 2)[-1]
|
9
|
+
end
|
10
|
+
|
11
|
+
def committed_at
|
12
|
+
raw_commit_lines.grep(/Date:/).first.split(':', 2)[-1]
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
raw_commit.split("\n\n", 3)[1].to_s.strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def raw_commit
|
20
|
+
@raw_commit ||= `cd #{project_path} && git show #{sha}`.chomp
|
21
|
+
end
|
22
|
+
|
23
|
+
def raw_commit_lines
|
24
|
+
@raw_commit_lines ||= raw_commit.split("\n")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/cijoe/config.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class CIJoe
|
2
|
+
class Config
|
3
|
+
def self.method_missing(command, *args)
|
4
|
+
new(command, args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(command, project_path = nil, parent = nil)
|
8
|
+
@command = command
|
9
|
+
@parent = parent
|
10
|
+
@project_path = project_path || File.join(File.dirname(__FILE__), '../../')
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(command, *args)
|
14
|
+
Config.new(command, @project_path, self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
git_command = "cd #{@project_path} && git config #{config_string}"
|
19
|
+
result = `#{git_command} 2>&1`.chomp
|
20
|
+
process_status = $?
|
21
|
+
|
22
|
+
if successful_command?(process_status) || config_command_with_empty_value?(result,process_status)
|
23
|
+
return result
|
24
|
+
else
|
25
|
+
raise "Error calling git config, is a recent version of git installed? Command: #{git_command}, Error: #{result}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_string
|
30
|
+
@parent ? "#{@parent.config_string}.#{@command}" : @command
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def successful_command?(process_status)
|
36
|
+
process_status.exitstatus.to_i == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def config_command_with_empty_value?(result, process_status)
|
40
|
+
process_status.exitstatus.to_i == 1 && result.empty?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,213 @@
|
|
1
|
+
/*****************************************************************************/
|
2
|
+
/*
|
3
|
+
/* Common
|
4
|
+
/*
|
5
|
+
/*****************************************************************************/
|
6
|
+
|
7
|
+
/* Global Reset */
|
8
|
+
|
9
|
+
* {
|
10
|
+
margin: 0;
|
11
|
+
padding: 0;
|
12
|
+
}
|
13
|
+
|
14
|
+
html, body {
|
15
|
+
height: 100%;
|
16
|
+
}
|
17
|
+
|
18
|
+
body {
|
19
|
+
background-color: white;
|
20
|
+
font: 13.34px helvetica, arial, clean, sans-serif;
|
21
|
+
*font-size: small;
|
22
|
+
text-align: center;
|
23
|
+
}
|
24
|
+
|
25
|
+
h1, h2, h3, h4, h5, h6 {
|
26
|
+
font-size: 100%;
|
27
|
+
}
|
28
|
+
|
29
|
+
h1 {
|
30
|
+
margin-bottom: 1em;
|
31
|
+
}
|
32
|
+
|
33
|
+
h1 a {
|
34
|
+
text-decoration: none;
|
35
|
+
color: #000;
|
36
|
+
}
|
37
|
+
|
38
|
+
.failed, .color31 {
|
39
|
+
color: red !important;
|
40
|
+
}
|
41
|
+
|
42
|
+
.worked, .color32 {
|
43
|
+
color: green !important;
|
44
|
+
}
|
45
|
+
|
46
|
+
.errored, .color33 {
|
47
|
+
color: yellow !important;
|
48
|
+
}
|
49
|
+
|
50
|
+
p {
|
51
|
+
margin: 1em 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
a {
|
55
|
+
color: #00a;
|
56
|
+
}
|
57
|
+
|
58
|
+
a:hover {
|
59
|
+
color: black;
|
60
|
+
}
|
61
|
+
|
62
|
+
a:visited {
|
63
|
+
color: #a0a;
|
64
|
+
}
|
65
|
+
|
66
|
+
table {
|
67
|
+
font-size: inherit;
|
68
|
+
font: 100%;
|
69
|
+
}
|
70
|
+
|
71
|
+
/*****************************************************************************/
|
72
|
+
/*
|
73
|
+
/* Home
|
74
|
+
/*
|
75
|
+
/*****************************************************************************/
|
76
|
+
|
77
|
+
ul.posts {
|
78
|
+
list-style-type: none;
|
79
|
+
margin-bottom: 2em;
|
80
|
+
}
|
81
|
+
|
82
|
+
ul.posts li {
|
83
|
+
line-height: 1.75em;
|
84
|
+
}
|
85
|
+
|
86
|
+
ul.posts .date,
|
87
|
+
ul.posts .duration {
|
88
|
+
color: #aaa;
|
89
|
+
font-family: Monaco, "Courier New", monospace;
|
90
|
+
font-size: 80%;
|
91
|
+
}
|
92
|
+
|
93
|
+
/*****************************************************************************/
|
94
|
+
/*
|
95
|
+
/* Site
|
96
|
+
/*
|
97
|
+
/*****************************************************************************/
|
98
|
+
|
99
|
+
.site {
|
100
|
+
font-size: 110%;
|
101
|
+
text-align: justify;
|
102
|
+
width: 80%;
|
103
|
+
margin: 3em auto 2em auto;
|
104
|
+
line-height: 1.5em;
|
105
|
+
}
|
106
|
+
|
107
|
+
.title {
|
108
|
+
color: #a00;
|
109
|
+
font-weight: bold;
|
110
|
+
margin-bottom: 2em;
|
111
|
+
}
|
112
|
+
|
113
|
+
.site .title a {
|
114
|
+
color: #a00;
|
115
|
+
text-decoration: none;
|
116
|
+
}
|
117
|
+
|
118
|
+
.site .title a:hover {
|
119
|
+
color: black;
|
120
|
+
}
|
121
|
+
|
122
|
+
.site .title .extra {
|
123
|
+
color: #aaa;
|
124
|
+
text-decoration: none;
|
125
|
+
margin-left: 1em;
|
126
|
+
font-size: 0.9em;
|
127
|
+
}
|
128
|
+
|
129
|
+
.site .title a.extra:hover {
|
130
|
+
color: black;
|
131
|
+
}
|
132
|
+
|
133
|
+
.site .meta {
|
134
|
+
color: #aaa;
|
135
|
+
}
|
136
|
+
|
137
|
+
.site .footer {
|
138
|
+
font-size: 80%;
|
139
|
+
color: #666;
|
140
|
+
border-top: 4px solid #eee;
|
141
|
+
margin-top: 2em;
|
142
|
+
overflow: hidden;
|
143
|
+
}
|
144
|
+
|
145
|
+
.site .footer .contact {
|
146
|
+
float: left;
|
147
|
+
margin-right: 3em;
|
148
|
+
}
|
149
|
+
|
150
|
+
.site .footer .contact a {
|
151
|
+
color: #8085C1;
|
152
|
+
}
|
153
|
+
|
154
|
+
.site .footer .rss {
|
155
|
+
margin-top: 1.1em;
|
156
|
+
margin-right: -.2em;
|
157
|
+
float: right;
|
158
|
+
}
|
159
|
+
|
160
|
+
.site .footer .rss img {
|
161
|
+
border: 0;
|
162
|
+
}
|
163
|
+
|
164
|
+
/*****************************************************************************/
|
165
|
+
/*
|
166
|
+
/* Posts
|
167
|
+
/*
|
168
|
+
/*****************************************************************************/
|
169
|
+
|
170
|
+
#post {
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
/* standard */
|
175
|
+
|
176
|
+
#post pre {
|
177
|
+
border: 1px solid #ddd;
|
178
|
+
background-color: #eef;
|
179
|
+
padding: 0 .4em;
|
180
|
+
}
|
181
|
+
|
182
|
+
#post ul,
|
183
|
+
#post ol {
|
184
|
+
margin-left: 1.25em;
|
185
|
+
}
|
186
|
+
|
187
|
+
#post code {
|
188
|
+
border: 1px solid #ddd;
|
189
|
+
background-color: #eef;
|
190
|
+
font-size: 95%;
|
191
|
+
padding: 0 .2em;
|
192
|
+
}
|
193
|
+
|
194
|
+
#post pre code {
|
195
|
+
border: none;
|
196
|
+
}
|
197
|
+
|
198
|
+
/* terminal */
|
199
|
+
|
200
|
+
pre.terminal {
|
201
|
+
border: 1px solid black;
|
202
|
+
background-color: #333;
|
203
|
+
color: white;
|
204
|
+
padding: 5px;
|
205
|
+
overflow: auto;
|
206
|
+
word-wrap: break-word;
|
207
|
+
}
|
208
|
+
|
209
|
+
pre.terminal code {
|
210
|
+
font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace;
|
211
|
+
background-color: #333;
|
212
|
+
}
|
213
|
+
|
data/lib/cijoe/server.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class CIJoe
|
5
|
+
class Server < Sinatra::Base
|
6
|
+
attr_reader :joe
|
7
|
+
|
8
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
9
|
+
|
10
|
+
set :views, "#{dir}/views"
|
11
|
+
set :public, "#{dir}/public"
|
12
|
+
set :static, true
|
13
|
+
set :lock, true
|
14
|
+
|
15
|
+
before { joe.restore }
|
16
|
+
|
17
|
+
get '/ping' do
|
18
|
+
if joe.building? || !joe.last_build || !joe.last_build.worked?
|
19
|
+
halt 412, joe.last_build ? joe.last_build.sha : "building"
|
20
|
+
end
|
21
|
+
|
22
|
+
joe.last_build.sha
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/?' do
|
26
|
+
erb(:template, {}, :joe => joe)
|
27
|
+
end
|
28
|
+
|
29
|
+
post '/?' do
|
30
|
+
payload = params[:payload].to_s
|
31
|
+
if payload.empty? || payload.include?(joe.git_branch)
|
32
|
+
joe.build
|
33
|
+
end
|
34
|
+
redirect request.path
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
helpers do
|
39
|
+
include Rack::Utils
|
40
|
+
alias_method :h, :escape_html
|
41
|
+
|
42
|
+
# thanks integrity!
|
43
|
+
def ansi_color_codes(string)
|
44
|
+
string.gsub("\e[0m", '</span>').
|
45
|
+
gsub(/\e\[(\d+)m/, "<span class=\"color\\1\">")
|
46
|
+
end
|
47
|
+
|
48
|
+
def pretty_time(time)
|
49
|
+
time.strftime("%Y-%m-%d %H:%M")
|
50
|
+
end
|
51
|
+
|
52
|
+
def cijoe_root
|
53
|
+
root = request.path
|
54
|
+
root = "" if root == "/"
|
55
|
+
root
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(*args)
|
60
|
+
super
|
61
|
+
check_project
|
62
|
+
@joe = CIJoe.new(options.project_path)
|
63
|
+
|
64
|
+
CIJoe::Campfire.activate(options.project_path)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.start(host, port, project_path)
|
68
|
+
set :project_path, project_path
|
69
|
+
CIJoe::Server.run! :host => host, :port => port
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.project_path=(project_path)
|
73
|
+
user, pass = Config.cijoe(project_path).user.to_s, Config.cijoe(project_path).pass.to_s
|
74
|
+
if user != '' && pass != ''
|
75
|
+
use Rack::Auth::Basic do |username, password|
|
76
|
+
[ username, password ] == [ user, pass ]
|
77
|
+
end
|
78
|
+
puts "Using HTTP basic auth"
|
79
|
+
end
|
80
|
+
set :project_path, Proc.new{project_path}
|
81
|
+
end
|
82
|
+
|
83
|
+
def check_project
|
84
|
+
if options.project_path.nil? || !File.exists?(File.expand_path(options.project_path))
|
85
|
+
puts "Whoops! I need the path to a Git repo."
|
86
|
+
puts " $ git clone git@github.com:username/project.git project"
|
87
|
+
abort " $ cijoe project"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|