xlymian-cijoe 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.markdown +159 -0
- data/Rakefile +60 -0
- data/bin/cijoe +49 -0
- data/deps.rip +4 -0
- data/examples/cijoe.ru +15 -0
- data/examples/cijoed +53 -0
- data/lib/cijoe.rb +203 -0
- data/lib/cijoe/build.rb +53 -0
- data/lib/cijoe/campfire.rb +72 -0
- data/lib/cijoe/commit.rb +27 -0
- data/lib/cijoe/config.rb +42 -0
- data/lib/cijoe/public/favicon.ico +0 -0
- data/lib/cijoe/public/octocat.png +0 -0
- data/lib/cijoe/public/screen.css +212 -0
- data/lib/cijoe/server.rb +87 -0
- data/lib/cijoe/talker.rb +108 -0
- data/lib/cijoe/version.rb +3 -0
- data/lib/cijoe/views/template.erb +65 -0
- data/test/helper.rb +12 -0
- data/test/test_cijoe.rb +17 -0
- data/test/test_cijoe_server.rb +50 -0
- data/xlymian-cijoe.gemspec +77 -0
- metadata +110 -0
data/lib/cijoe/build.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class CIJoe
|
4
|
+
class Build < Struct.new(:user, :project, :started_at, :finished_at, :sha, :status, :output, :pid)
|
5
|
+
def initialize(*args)
|
6
|
+
super
|
7
|
+
self.started_at ||= Time.now
|
8
|
+
end
|
9
|
+
|
10
|
+
def status
|
11
|
+
return super if started_at && finished_at
|
12
|
+
:building
|
13
|
+
end
|
14
|
+
|
15
|
+
def failed?
|
16
|
+
status == :failed
|
17
|
+
end
|
18
|
+
|
19
|
+
def worked?
|
20
|
+
status == :worked
|
21
|
+
end
|
22
|
+
|
23
|
+
def short_sha
|
24
|
+
if sha
|
25
|
+
sha[0,7]
|
26
|
+
else
|
27
|
+
"<unknown>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def clean_output
|
32
|
+
output.gsub(/\e\[.+?m/, '').strip
|
33
|
+
end
|
34
|
+
|
35
|
+
def commit
|
36
|
+
return if sha.nil?
|
37
|
+
@commit ||= Commit.new(sha, user, project)
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump(file)
|
41
|
+
config = [user, project, started_at, finished_at, sha, status, output, pid]
|
42
|
+
data = YAML.dump(config)
|
43
|
+
File.open(file, 'wb') { |io| io.write(data) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.load(file)
|
47
|
+
if File.exist?(file)
|
48
|
+
config = YAML.load(File.read(file))
|
49
|
+
new *config
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class CIJoe
|
2
|
+
module Campfire
|
3
|
+
def self.activate
|
4
|
+
if valid_config?
|
5
|
+
require 'tinder'
|
6
|
+
|
7
|
+
CIJoe::Build.class_eval do
|
8
|
+
include CIJoe::Campfire
|
9
|
+
end
|
10
|
+
|
11
|
+
puts "Loaded Campfire notifier"
|
12
|
+
else
|
13
|
+
puts "Can't load Campfire notifier."
|
14
|
+
puts "Please add the following to your project's .git/config:"
|
15
|
+
puts "[campfire]"
|
16
|
+
puts "\tuser = your@campfire.email"
|
17
|
+
puts "\tpass = passw0rd"
|
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.subdomain.to_s,
|
27
|
+
:user => Config.campfire.user.to_s,
|
28
|
+
:pass => Config.campfire.pass.to_s,
|
29
|
+
:room => Config.campfire.room.to_s,
|
30
|
+
:ssl => Config.campfire.ssl.to_s.strip == 'true'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.valid_config?
|
35
|
+
%w( subdomain user pass room ).all? do |key|
|
36
|
+
!config[key.intern].empty?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def notify
|
41
|
+
room.speak "#{short_message}. #{commit.url}"
|
42
|
+
room.paste full_message if failed?
|
43
|
+
room.leave
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def room
|
48
|
+
@room ||= begin
|
49
|
+
config = Campfire.config
|
50
|
+
options = {}
|
51
|
+
options[:ssl] = config[:ssl] ? true : false
|
52
|
+
campfire = Tinder::Campfire.new(config[:subdomain], options)
|
53
|
+
campfire.login(config[:user], config[:pass])
|
54
|
+
campfire.find_room_by_name(config[:room])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def short_message
|
59
|
+
"Build #{short_sha} of #{project} #{worked? ? "was successful" : "failed"}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def full_message
|
63
|
+
<<-EOM
|
64
|
+
Commit Message: #{commit.message}
|
65
|
+
Commit Date: #{commit.committed_at}
|
66
|
+
Commit Author: #{commit.author}
|
67
|
+
|
68
|
+
#{clean_output}
|
69
|
+
EOM
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/cijoe/commit.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class CIJoe
|
2
|
+
class Commit < Struct.new(:sha, :user, :project)
|
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 ||= `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,42 @@
|
|
1
|
+
class CIJoe
|
2
|
+
class Config
|
3
|
+
def self.method_missing(command, *args)
|
4
|
+
new(command)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(command, parent = nil)
|
8
|
+
@command = command
|
9
|
+
@parent = parent
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(command, *args)
|
13
|
+
Config.new(command, self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
git_command = "git config #{config_string}"
|
18
|
+
result = `#{git_command} 2>&1`.chomp
|
19
|
+
process_status = $?
|
20
|
+
|
21
|
+
if successful_command?(process_status) || config_command_with_empty_value?(result,process_status)
|
22
|
+
return result
|
23
|
+
else
|
24
|
+
raise "Error calling git config, is a recent version of git installed? Command: #{git_command}, Error: #{result}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_string
|
29
|
+
@parent ? "#{@parent.config_string}.#{@command}" : @command
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def successful_command?(process_status)
|
35
|
+
process_status.exitstatus.to_i == 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def config_command_with_empty_value?(result, process_status)
|
39
|
+
process_status.exitstatus.to_i == 1 && result.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,212 @@
|
|
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
|
+
color: #aaa;
|
88
|
+
font-family: Monaco, "Courier New", monospace;
|
89
|
+
font-size: 80%;
|
90
|
+
}
|
91
|
+
|
92
|
+
/*****************************************************************************/
|
93
|
+
/*
|
94
|
+
/* Site
|
95
|
+
/*
|
96
|
+
/*****************************************************************************/
|
97
|
+
|
98
|
+
.site {
|
99
|
+
font-size: 110%;
|
100
|
+
text-align: justify;
|
101
|
+
width: 40em;
|
102
|
+
margin: 3em auto 2em auto;
|
103
|
+
line-height: 1.5em;
|
104
|
+
}
|
105
|
+
|
106
|
+
.title {
|
107
|
+
color: #a00;
|
108
|
+
font-weight: bold;
|
109
|
+
margin-bottom: 2em;
|
110
|
+
}
|
111
|
+
|
112
|
+
.site .title a {
|
113
|
+
color: #a00;
|
114
|
+
text-decoration: none;
|
115
|
+
}
|
116
|
+
|
117
|
+
.site .title a:hover {
|
118
|
+
color: black;
|
119
|
+
}
|
120
|
+
|
121
|
+
.site .title .extra {
|
122
|
+
color: #aaa;
|
123
|
+
text-decoration: none;
|
124
|
+
margin-left: 1em;
|
125
|
+
font-size: 0.9em;
|
126
|
+
}
|
127
|
+
|
128
|
+
.site .title a.extra:hover {
|
129
|
+
color: black;
|
130
|
+
}
|
131
|
+
|
132
|
+
.site .meta {
|
133
|
+
color: #aaa;
|
134
|
+
}
|
135
|
+
|
136
|
+
.site .footer {
|
137
|
+
font-size: 80%;
|
138
|
+
color: #666;
|
139
|
+
border-top: 4px solid #eee;
|
140
|
+
margin-top: 2em;
|
141
|
+
overflow: hidden;
|
142
|
+
}
|
143
|
+
|
144
|
+
.site .footer .contact {
|
145
|
+
float: left;
|
146
|
+
margin-right: 3em;
|
147
|
+
}
|
148
|
+
|
149
|
+
.site .footer .contact a {
|
150
|
+
color: #8085C1;
|
151
|
+
}
|
152
|
+
|
153
|
+
.site .footer .rss {
|
154
|
+
margin-top: 1.1em;
|
155
|
+
margin-right: -.2em;
|
156
|
+
float: right;
|
157
|
+
}
|
158
|
+
|
159
|
+
.site .footer .rss img {
|
160
|
+
border: 0;
|
161
|
+
}
|
162
|
+
|
163
|
+
/*****************************************************************************/
|
164
|
+
/*
|
165
|
+
/* Posts
|
166
|
+
/*
|
167
|
+
/*****************************************************************************/
|
168
|
+
|
169
|
+
#post {
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
/* standard */
|
174
|
+
|
175
|
+
#post pre {
|
176
|
+
border: 1px solid #ddd;
|
177
|
+
background-color: #eef;
|
178
|
+
padding: 0 .4em;
|
179
|
+
}
|
180
|
+
|
181
|
+
#post ul,
|
182
|
+
#post ol {
|
183
|
+
margin-left: 1.25em;
|
184
|
+
}
|
185
|
+
|
186
|
+
#post code {
|
187
|
+
border: 1px solid #ddd;
|
188
|
+
background-color: #eef;
|
189
|
+
font-size: 95%;
|
190
|
+
padding: 0 .2em;
|
191
|
+
}
|
192
|
+
|
193
|
+
#post pre code {
|
194
|
+
border: none;
|
195
|
+
}
|
196
|
+
|
197
|
+
/* terminal */
|
198
|
+
|
199
|
+
pre.terminal {
|
200
|
+
border: 1px solid black;
|
201
|
+
background-color: #333;
|
202
|
+
color: white;
|
203
|
+
padding: 5px;
|
204
|
+
overflow: auto;
|
205
|
+
word-wrap: break-word;
|
206
|
+
}
|
207
|
+
|
208
|
+
pre.terminal code {
|
209
|
+
font-family: 'Bitstream Vera Sans Mono', 'Courier', monospace;
|
210
|
+
background-color: #333;
|
211
|
+
}
|
212
|
+
|
data/lib/cijoe/server.rb
ADDED
@@ -0,0 +1,87 @@
|
|
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
|
+
user, pass = Config.cijoe.user.to_s, Config.cijoe.pass.to_s
|
38
|
+
if user != '' && pass != ''
|
39
|
+
use Rack::Auth::Basic do |username, password|
|
40
|
+
[ username, password ] == [ user, pass ]
|
41
|
+
end
|
42
|
+
puts "Using HTTP basic auth"
|
43
|
+
end
|
44
|
+
|
45
|
+
helpers do
|
46
|
+
include Rack::Utils
|
47
|
+
alias_method :h, :escape_html
|
48
|
+
|
49
|
+
# thanks integrity!
|
50
|
+
def ansi_color_codes(string)
|
51
|
+
string.gsub("\e[0m", '</span>').
|
52
|
+
gsub(/\e\[(\d+)m/, "<span class=\"color\\1\">")
|
53
|
+
end
|
54
|
+
|
55
|
+
def pretty_time(time)
|
56
|
+
time.strftime("%Y-%m-%d %H:%M")
|
57
|
+
end
|
58
|
+
|
59
|
+
def cijoe_root
|
60
|
+
root = request.path
|
61
|
+
root = "" if root == "/"
|
62
|
+
root
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def initialize(*args)
|
67
|
+
super
|
68
|
+
check_project
|
69
|
+
@joe = CIJoe.new(options.project_path)
|
70
|
+
|
71
|
+
CIJoe::Talker.activate
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.start(host, port, project_path)
|
75
|
+
set :project_path, project_path
|
76
|
+
CIJoe::Server.run! :host => host, :port => port
|
77
|
+
end
|
78
|
+
|
79
|
+
def check_project
|
80
|
+
if options.project_path.nil? || !File.exists?(File.expand_path(options.project_path))
|
81
|
+
puts "Whoops! I need the path to a Git repo."
|
82
|
+
puts " $ git clone git@github.com:username/project.git project"
|
83
|
+
abort " $ cijoe project"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|