bantic-integrity 0.1.4
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/README.markdown +153 -0
- data/Rakefile +82 -0
- data/VERSION.yml +4 -0
- data/app.rb +278 -0
- data/bin/integrity +82 -0
- data/config/config.sample.ru +30 -0
- data/config/config.sample.yml +34 -0
- data/config/thin.sample.yml +13 -0
- data/integrity.gemspec +72 -0
- data/lib/integrity/build.rb +56 -0
- data/lib/integrity/builder.rb +49 -0
- data/lib/integrity/core_ext/object.rb +6 -0
- data/lib/integrity/core_ext/string.rb +5 -0
- data/lib/integrity/core_ext/time.rb +13 -0
- data/lib/integrity/notifier/base.rb +55 -0
- data/lib/integrity/notifier.rb +50 -0
- data/lib/integrity/project.rb +94 -0
- data/lib/integrity/scm/git/uri.rb +57 -0
- data/lib/integrity/scm/git.rb +83 -0
- data/lib/integrity/scm.rb +22 -0
- data/lib/integrity.rb +71 -0
- data/public/buttons.css +82 -0
- data/public/reset.css +7 -0
- data/public/spinner.gif +0 -0
- data/spec/form_field_matchers.rb +91 -0
- data/spec/spec_helper.rb +135 -0
- data/vendor/sinatra-hacks/lib/hacks.rb +49 -0
- data/views/build.haml +2 -0
- data/views/build_info.haml +22 -0
- data/views/error.haml +29 -0
- data/views/home.haml +22 -0
- data/views/integrity.sass +387 -0
- data/views/layout.haml +25 -0
- data/views/new.haml +53 -0
- data/views/not_found.haml +31 -0
- data/views/notifier.haml +7 -0
- data/views/project.haml +32 -0
- data/views/unauthorized.haml +38 -0
- metadata +216 -0
data/README.markdown
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
Integrity
|
2
|
+
=========
|
3
|
+
|
4
|
+
Integrity is your friendly automated Continuous Integration server.
|
5
|
+
|
6
|
+
It's fully usable from within its web interface (backed by [Sinatra][]),
|
7
|
+
allowing you to add a project, set preferences for it (where's the code
|
8
|
+
repository, is it completely private or public, etc), and run the build command
|
9
|
+
from there.
|
10
|
+
|
11
|
+
It has been designed with ruby projects in mind, but any project that can be
|
12
|
+
tested in an unix-y fashion (with a command line tool that returns 0 on success
|
13
|
+
and non-zero on failure) works with it.
|
14
|
+
|
15
|
+
Getting Started
|
16
|
+
===============
|
17
|
+
|
18
|
+
Install the `integrity` gem from GitHub:
|
19
|
+
|
20
|
+
gem sources --add http://gems.github.com
|
21
|
+
sudo gem install foca-integrity
|
22
|
+
|
23
|
+
In order to setup Integrity, run the following command:
|
24
|
+
|
25
|
+
integrity install /path/to/my/app
|
26
|
+
|
27
|
+
Then browse to /path/to/my/app and edit the config files at your convenience.
|
28
|
+
The default configuration should be "good enough" in most cases, so you should
|
29
|
+
be pretty much ready to rock.
|
30
|
+
|
31
|
+
For deployment, we recommend [Thin][]. Provided with Integrity comes a thin.yml
|
32
|
+
file, so all you need to do after running `integrity install` should be
|
33
|
+
|
34
|
+
thin -C /path/to/my/app/thin.yml -R /path/to/my/app/config.ru start
|
35
|
+
|
36
|
+
And you should be up and running.
|
37
|
+
|
38
|
+
If you want automatic commit processing, you currently need to be using
|
39
|
+
[GitHub][]. Click the edit link on your GitHub project, and add an integrity
|
40
|
+
link that looks like the following to the `Post-Receive URL` field:
|
41
|
+
|
42
|
+
http://integrity.domain.tld/projectname/push
|
43
|
+
|
44
|
+
Receiving Notifications
|
45
|
+
=======================
|
46
|
+
|
47
|
+
If you want to be notified after each build, you need to install our notifiers.
|
48
|
+
For example, in order to receive an email after each build, install:
|
49
|
+
|
50
|
+
sudo gem install foca-integrity-email
|
51
|
+
|
52
|
+
And then edit `/path/to/my/app/config.ru` and add:
|
53
|
+
|
54
|
+
require "notifier/email"
|
55
|
+
|
56
|
+
After all the `require` lines.
|
57
|
+
|
58
|
+
Available notifiers
|
59
|
+
-------------------
|
60
|
+
|
61
|
+
* [Mail](http://github.com/foca/integrity-email)
|
62
|
+
* [Jabber](http://github.com/ph/integrity-jabber)
|
63
|
+
* [Campfire](http://github.com/defunkt/integrity-campfire)
|
64
|
+
|
65
|
+
Resources
|
66
|
+
========
|
67
|
+
|
68
|
+
We have a [Lighthouse account][lighthouse] where you can submit patches or
|
69
|
+
feature requests. Also, someone is usually around [#integrity][irc-channel] on
|
70
|
+
Freenode, so don't hesitate to stop by for ideas, help, patches or something.
|
71
|
+
|
72
|
+
Future plans
|
73
|
+
============
|
74
|
+
|
75
|
+
* [Twitter][]/[IRC][]/etc bots
|
76
|
+
* A sample generic post-receive-hook so you can run this from any git repo
|
77
|
+
* Better integration with GitHub
|
78
|
+
|
79
|
+
Development
|
80
|
+
===========
|
81
|
+
|
82
|
+
The code is stored in [GitHub][repo]. Feel free to fork, play with it, and send
|
83
|
+
a pull request afterwards.
|
84
|
+
|
85
|
+
In order to run the test suite you'll need a few more gems: [rspec][], [rcov][]
|
86
|
+
and [hpricot][]. With that installed running `rake` will run the specs and
|
87
|
+
ensure the code coverage stays high.
|
88
|
+
|
89
|
+
Thanks
|
90
|
+
======
|
91
|
+
|
92
|
+
Thanks to the fellowing people for their feedbacks, ideas and patches :
|
93
|
+
|
94
|
+
* [James Adam][james]
|
95
|
+
* [Elliott Cable][ec]
|
96
|
+
* [Corey Donohoe][atmos]
|
97
|
+
* [Kyle Hargraves][kyle]
|
98
|
+
* [Pier-Hugues Pellerin][ph]
|
99
|
+
* [Simon Rozet][sr]
|
100
|
+
* [Scott Taylor][scott]
|
101
|
+
|
102
|
+
[james]: http://github.com/lazyatom
|
103
|
+
[ec]: http://github.com/elliotcabble
|
104
|
+
[atmos]: http://github.com/atmos
|
105
|
+
[kyle]: http://github.com/pd
|
106
|
+
[ph]: http://github.com/ph
|
107
|
+
[sr]: http://purl.org/net/sr/
|
108
|
+
[scott]: http://github.com/smtlaissezfaire
|
109
|
+
|
110
|
+
License
|
111
|
+
=======
|
112
|
+
|
113
|
+
(The MIT License)
|
114
|
+
|
115
|
+
Copyright (c) 2008 [Nicolás Sanguinetti][foca], [entp][]
|
116
|
+
|
117
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
118
|
+
a copy of this software and associated documentation files (the
|
119
|
+
'Software'), to deal in the Software without restriction, including
|
120
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
121
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
122
|
+
permit persons to whom the Software is furnished to do so, subject to
|
123
|
+
the following conditions:
|
124
|
+
|
125
|
+
The above copyright notice and this permission notice shall be
|
126
|
+
included in all copies or substantial portions of the Software.
|
127
|
+
|
128
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
129
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
130
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
131
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
132
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
133
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
134
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
135
|
+
|
136
|
+
[Sinatra]: http://sinatrarb.com
|
137
|
+
[git]: http://git.or.cz
|
138
|
+
[svn]: http://subversion.tigris.org
|
139
|
+
[Twitter]: http://twitter.com
|
140
|
+
[IRC]: http://wikipedia.org/wiki/IRC
|
141
|
+
[entp]: http://entp.com
|
142
|
+
[GitHub]: http://github.com
|
143
|
+
[Thin]: http://code.macournoyer.com/thin/
|
144
|
+
|
145
|
+
[rspec]: http://rspec.info
|
146
|
+
[rcov]: http://eigenclass.org/hiki.rb?rcov
|
147
|
+
[hpricot]: http://code.whytheluckystiff.net/hpricot
|
148
|
+
|
149
|
+
[repo]: http://github.com/foca/integrity
|
150
|
+
[lighthouse]: http://integrity.lighthouseapp.com/projects/14308-integrity
|
151
|
+
[irc-channel]: irc://irc.freenode.net/integrity
|
152
|
+
|
153
|
+
[foca]: http://nicolassanguinetti.info/
|
data/Rakefile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/integrity"
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
require 'spec/rake/verify_rcov'
|
4
|
+
|
5
|
+
task :default => ["spec:coverage", "spec:coverage:verify"]
|
6
|
+
|
7
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
8
|
+
t.spec_opts = ["--color", "--format", "progress"]
|
9
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
10
|
+
t.libs = ['lib']
|
11
|
+
t.rcov = false
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :spec do
|
15
|
+
Spec::Rake::SpecTask.new(:coverage) do |t|
|
16
|
+
t.spec_opts = ["--color", "--format", "progress"]
|
17
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
18
|
+
t.libs = ['lib']
|
19
|
+
t.rcov = true
|
20
|
+
t.rcov_opts = ['--exclude-only', '".*"', '--include-file', '^lib']
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :coverage do
|
24
|
+
RCov::VerifyTask.new(:verify) do |t|
|
25
|
+
t.threshold = 100
|
26
|
+
t.index_html = "coverage" / 'index.html'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :db do
|
32
|
+
desc "Setup connection."
|
33
|
+
task :connect do
|
34
|
+
config = File.expand_path(ENV['CONFIG']) if ENV['CONFIG']
|
35
|
+
config = Integrity.root / 'config.yml' if File.exists?(Integrity.root / 'config.yml')
|
36
|
+
Integrity.new(config)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Automigrate the database"
|
40
|
+
task :migrate => :connect do
|
41
|
+
require "project"
|
42
|
+
require "build"
|
43
|
+
require "notifier"
|
44
|
+
DataMapper.auto_migrate!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
require 'jeweler'
|
50
|
+
Jeweler::Tasks.new do |s|
|
51
|
+
files = `git ls-files`.split("\n").reject {|f| f =~ %r(^spec) || f =~ %r(^vendor/rspec) || f =~ /^\.git/ }
|
52
|
+
files += %w(spec/spec_helper.rb spec/form_field_matchers.rb)
|
53
|
+
|
54
|
+
s.name = 'integrity'
|
55
|
+
s.summary = 'The easy and fun Continuous Integration server'
|
56
|
+
s.description = 'Your Friendly Continuous Integration server. Easy, fun and painless!'
|
57
|
+
s.homepage = 'http://integrityapp.com'
|
58
|
+
s.rubyforge_project = 'integrity'
|
59
|
+
s.email = 'contacto@nicolassanguinetti.info'
|
60
|
+
s.authors = ['Nicolás Sanguinetti', 'Simon Rozet']
|
61
|
+
s.files = files
|
62
|
+
s.executables = ['integrity']
|
63
|
+
s.post_install_message = 'Run `integrity help` for information on how to setup Integrity.'
|
64
|
+
|
65
|
+
s.add_dependency 'sinatra', ['>= 0.3.2']
|
66
|
+
s.add_dependency 'haml' # ah, you evil monkey you
|
67
|
+
s.add_dependency 'dm-core', ['>= 0.9.5']
|
68
|
+
s.add_dependency 'dm-validations', ['>= 0.9.5']
|
69
|
+
s.add_dependency 'dm-types', ['>= 0.9.5']
|
70
|
+
s.add_dependency 'dm-timestamps', ['>= 0.9.5']
|
71
|
+
s.add_dependency 'dm-aggregates', ['>= 0.9.5']
|
72
|
+
s.add_dependency 'data_objects', ['>= 0.9.5']
|
73
|
+
s.add_dependency 'do_sqlite3', ['>= 0.9.5']
|
74
|
+
s.add_dependency 'json'
|
75
|
+
s.add_dependency 'foca-sinatra-diddies', ['>= 0.0.2']
|
76
|
+
s.add_dependency 'rspec_hpricot_matchers'
|
77
|
+
s.add_dependency 'thor'
|
78
|
+
s.add_dependency 'bcrypt-ruby'
|
79
|
+
end
|
80
|
+
rescue LoadError
|
81
|
+
end
|
82
|
+
|
data/VERSION.yml
ADDED
data/app.rb
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/integrity'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'diddies'
|
4
|
+
require 'hacks'
|
5
|
+
|
6
|
+
set :root, Integrity.root
|
7
|
+
set :public, Integrity.root / "public"
|
8
|
+
set :views, Integrity.root / "views"
|
9
|
+
|
10
|
+
enable :sessions
|
11
|
+
|
12
|
+
include Integrity
|
13
|
+
|
14
|
+
configure :development do
|
15
|
+
config = Integrity.root / "config" / "config.yml"
|
16
|
+
Integrity.config = config if File.exists? config
|
17
|
+
end
|
18
|
+
|
19
|
+
configure do
|
20
|
+
Integrity.new
|
21
|
+
end
|
22
|
+
|
23
|
+
not_found do
|
24
|
+
status 404
|
25
|
+
show :not_found, :title => "lost, are we?"
|
26
|
+
end
|
27
|
+
|
28
|
+
error do
|
29
|
+
@error = request.env['sinatra.error']
|
30
|
+
status 500
|
31
|
+
show :error, :title => "something has gone terribly wrong"
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
35
|
+
# The browser only sends http auth data for requests that are explicitly
|
36
|
+
# required to do so. This way we get the real values of +#logged_in?+ and
|
37
|
+
# +#current_user+
|
38
|
+
login_required if session[:user]
|
39
|
+
end
|
40
|
+
|
41
|
+
get "/" do
|
42
|
+
@projects = Project.all(authorized? ? {} : { :public => true })
|
43
|
+
show :home, :title => "projects"
|
44
|
+
end
|
45
|
+
|
46
|
+
get "/login" do
|
47
|
+
login_required
|
48
|
+
session[:user] = current_user
|
49
|
+
redirect "/"
|
50
|
+
end
|
51
|
+
|
52
|
+
get "/new" do
|
53
|
+
login_required
|
54
|
+
|
55
|
+
@project = Project.new
|
56
|
+
show :new, :title => ["projects", "new project"]
|
57
|
+
end
|
58
|
+
|
59
|
+
post "/" do
|
60
|
+
login_required
|
61
|
+
|
62
|
+
@project = Project.new(params[:project_data])
|
63
|
+
if @project.save
|
64
|
+
@project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
|
65
|
+
redirect project_url(@project)
|
66
|
+
else
|
67
|
+
show :new, :title => ["projects", "new project"]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
get "/:project" do
|
72
|
+
login_required unless current_project.public?
|
73
|
+
show :project, :title => ["projects", current_project.permalink]
|
74
|
+
end
|
75
|
+
|
76
|
+
put "/:project" do
|
77
|
+
login_required
|
78
|
+
|
79
|
+
if current_project.update_attributes(params[:project_data])
|
80
|
+
current_project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
|
81
|
+
redirect project_url(current_project)
|
82
|
+
else
|
83
|
+
show :new, :title => ["projects", current_project.permalink, "edit"]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
delete "/:project" do
|
88
|
+
login_required
|
89
|
+
|
90
|
+
current_project.destroy
|
91
|
+
redirect "/"
|
92
|
+
end
|
93
|
+
|
94
|
+
get "/:project/edit" do
|
95
|
+
login_required
|
96
|
+
|
97
|
+
show :new, :title => ["projects", current_project.permalink, "edit"]
|
98
|
+
end
|
99
|
+
|
100
|
+
post "/:project/push" do
|
101
|
+
login_required
|
102
|
+
|
103
|
+
content_type 'text/plain'
|
104
|
+
|
105
|
+
begin
|
106
|
+
payload = JSON.parse(params[:payload] || "")
|
107
|
+
|
108
|
+
if Integrity.config[:build_all_commits]
|
109
|
+
payload['commits'].sort_by { |commit| Time.parse(commit['timestamp']) }.each do |commit|
|
110
|
+
current_project.build(commit['id']) if payload['ref'] =~ /#{current_project.branch}/
|
111
|
+
end
|
112
|
+
else
|
113
|
+
current_project.build(payload['after']) if payload['ref'] =~ /#{current_project.branch}/
|
114
|
+
end
|
115
|
+
|
116
|
+
'Thanks, build started.'
|
117
|
+
rescue JSON::ParserError => exception
|
118
|
+
invalid_payload!(exception.to_s)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
post "/:project/builds" do
|
123
|
+
login_required
|
124
|
+
|
125
|
+
current_project.build
|
126
|
+
redirect project_url(@project)
|
127
|
+
end
|
128
|
+
|
129
|
+
get '/:project/builds/:build' do
|
130
|
+
login_required unless current_project.public?
|
131
|
+
show :build, :title => ["projects", current_project.permalink, current_build.short_commit_identifier]
|
132
|
+
end
|
133
|
+
|
134
|
+
get "/integrity.css" do
|
135
|
+
header "Content-Type" => "text/css; charset=utf-8"
|
136
|
+
sass :integrity
|
137
|
+
end
|
138
|
+
|
139
|
+
helpers do
|
140
|
+
include Rack::Utils
|
141
|
+
include Sinatra::Authorization
|
142
|
+
alias_method :h, :escape_html
|
143
|
+
|
144
|
+
def authorization_realm
|
145
|
+
"Integrity"
|
146
|
+
end
|
147
|
+
|
148
|
+
def authorized?
|
149
|
+
return true unless Integrity.config[:use_basic_auth]
|
150
|
+
!!request.env['REMOTE_USER']
|
151
|
+
end
|
152
|
+
|
153
|
+
def authorize(user, password)
|
154
|
+
if Integrity.config[:hash_admin_password]
|
155
|
+
password = Digest::SHA1.hexdigest(password)
|
156
|
+
end
|
157
|
+
|
158
|
+
!Integrity.config[:use_basic_auth] ||
|
159
|
+
(Integrity.config[:admin_username] == user &&
|
160
|
+
Integrity.config[:admin_password] == password)
|
161
|
+
end
|
162
|
+
|
163
|
+
def unauthorized!(realm=authorization_realm)
|
164
|
+
header 'WWW-Authenticate' => %(Basic realm="#{realm}")
|
165
|
+
throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
|
166
|
+
end
|
167
|
+
|
168
|
+
def invalid_payload!(msg=nil)
|
169
|
+
throw :halt, [422, msg || 'No payload given']
|
170
|
+
end
|
171
|
+
|
172
|
+
def current_project
|
173
|
+
@project ||= Project.first(:permalink => params[:project]) or raise Sinatra::NotFound
|
174
|
+
end
|
175
|
+
|
176
|
+
def current_build
|
177
|
+
@build ||= current_project.builds.first(:commit_identifier => params[:build]) or raise Sinatra::NotFound
|
178
|
+
end
|
179
|
+
|
180
|
+
def show(view, options={})
|
181
|
+
@title = breadcrumbs(*options[:title])
|
182
|
+
haml view
|
183
|
+
end
|
184
|
+
|
185
|
+
def pages
|
186
|
+
@pages ||= [["projects", "/"], ["new project", "/new"]]
|
187
|
+
end
|
188
|
+
|
189
|
+
def breadcrumbs(*crumbs)
|
190
|
+
crumbs[0..-2].map do |crumb|
|
191
|
+
if page_data = pages.detect {|c| c.first == crumb }
|
192
|
+
%Q(<a href="#{page_data.last}">#{page_data.first}</a>)
|
193
|
+
elsif @project && @project.permalink == crumb
|
194
|
+
%Q(<a href="#{project_url(@project)}">#{@project.permalink}</a>)
|
195
|
+
end
|
196
|
+
end + [crumbs.last]
|
197
|
+
end
|
198
|
+
|
199
|
+
def cycle(*values)
|
200
|
+
@cycles ||= {}
|
201
|
+
@cycles[values] ||= -1 # first value returned is 0
|
202
|
+
next_value = @cycles[values] = (@cycles[values] + 1) % values.size
|
203
|
+
values[next_value]
|
204
|
+
end
|
205
|
+
|
206
|
+
def project_url(project, *path)
|
207
|
+
"/" << [project.permalink, *path].join("/")
|
208
|
+
end
|
209
|
+
|
210
|
+
def push_url_for(project)
|
211
|
+
Addressable::URI.parse(Integrity.config[:base_uri]).join("#{project_url(project)}/push").to_s
|
212
|
+
end
|
213
|
+
|
214
|
+
def build_url(build)
|
215
|
+
"/#{build.project.permalink}/builds/#{build.commit_identifier}"
|
216
|
+
end
|
217
|
+
|
218
|
+
def filter_attributes_of(model)
|
219
|
+
valid = model.properties.collect {|p| p.name.to_s }
|
220
|
+
Hash[*params.dup.select {|k,_| valid.include?(k) }.flatten]
|
221
|
+
end
|
222
|
+
|
223
|
+
def errors_on(object, field)
|
224
|
+
return "" unless errors = object.errors.on(field)
|
225
|
+
errors.map {|e| e.gsub(/#{field} /i, "") }.join(", ")
|
226
|
+
end
|
227
|
+
|
228
|
+
def error_class(object, field)
|
229
|
+
object.errors.on(field).nil? ? "" : "with_errors"
|
230
|
+
end
|
231
|
+
|
232
|
+
def checkbox(name, condition, extras={})
|
233
|
+
attrs = { :name => name, :type => "checkbox" }.merge(condition ? { :checked => "checked" } : {})
|
234
|
+
attrs.merge(extras)
|
235
|
+
end
|
236
|
+
|
237
|
+
def bash_color_codes(string)
|
238
|
+
string.gsub("\e[0m", '</span>').
|
239
|
+
gsub("\e[31m", '<span class="color31">').
|
240
|
+
gsub("\e[32m", '<span class="color32">').
|
241
|
+
gsub("\e[33m", '<span class="color33">').
|
242
|
+
gsub("\e[34m", '<span class="color34">').
|
243
|
+
gsub("\e[35m", '<span class="color35">').
|
244
|
+
gsub("\e[36m", '<span class="color36">').
|
245
|
+
gsub("\e[37m", '<span class="color37">')
|
246
|
+
end
|
247
|
+
|
248
|
+
def pretty_date(date_time)
|
249
|
+
today = Date.today
|
250
|
+
if date_time.day == today.day && date_time.month == today.month && date_time.year == today.year
|
251
|
+
"today"
|
252
|
+
elsif date_time.day == today.day - 1 && date_time.month == today.month && date_time.year == today.year
|
253
|
+
"yesterday"
|
254
|
+
else
|
255
|
+
date_time.strftime("on %b %d%o")
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def pretty_time_since(date_time)
|
260
|
+
seconds = Time.now - Time.parse(date_time.to_s)
|
261
|
+
seconds = seconds.round
|
262
|
+
if seconds < 60
|
263
|
+
"#{seconds}s"
|
264
|
+
else
|
265
|
+
minutes = seconds / 60
|
266
|
+
remainder_seconds = seconds % 60
|
267
|
+
"#{minutes}m#{remainder_seconds}s"
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def notifier_form(notifier)
|
272
|
+
haml(notifier.to_haml, :layout => :notifier, :locals => {
|
273
|
+
:config => current_project.config_for(notifier),
|
274
|
+
:notifier => "#{notifier.to_s.split(/::/).last}",
|
275
|
+
:enabled => current_project.notifies?(notifier)
|
276
|
+
})
|
277
|
+
end
|
278
|
+
end
|
data/bin/integrity
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
require File.dirname(__FILE__) + "/../lib/integrity"
|
6
|
+
|
7
|
+
class WithIntegrity < Thor
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
desc "install [PATH]",
|
11
|
+
"Copy template files to PATH. Next, go there and edit them."
|
12
|
+
def install(path)
|
13
|
+
@root = File.expand_path(path)
|
14
|
+
|
15
|
+
create_dir_structure
|
16
|
+
copy_template_files
|
17
|
+
edit_template_files
|
18
|
+
create_db(root / "config.yml")
|
19
|
+
after_setup_message
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "create_db [CONFIG]",
|
23
|
+
"Checks the `database_uri` in CONFIG and creates and bootstraps a database for integrity"
|
24
|
+
def create_db(config)
|
25
|
+
Integrity.new(config)
|
26
|
+
DataMapper.auto_migrate!
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
attr_reader :root
|
31
|
+
|
32
|
+
def create_dir_structure
|
33
|
+
mkdir_p root
|
34
|
+
mkdir_p root / "builds"
|
35
|
+
mkdir_p root / "log"
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_template_files
|
39
|
+
cp Integrity.root / "config" / "config.sample.ru", root / "config.ru"
|
40
|
+
cp Integrity.root / "config" / "config.sample.yml", root / "config.yml"
|
41
|
+
cp Integrity.root / "config" / "thin.sample.yml", root / "thin.yml"
|
42
|
+
end
|
43
|
+
|
44
|
+
def edit_template_files
|
45
|
+
edit_integrity_configuration
|
46
|
+
edit_thin_configuration
|
47
|
+
end
|
48
|
+
|
49
|
+
def edit_integrity_configuration
|
50
|
+
config = File.read(root / "config.yml")
|
51
|
+
config.gsub! %r(sqlite3:///var/integrity.db), "sqlite3://#{root}/integrity.db"
|
52
|
+
config.gsub! %r(/path/to/scm/exports), "#{root}/builds"
|
53
|
+
config.gsub! %r(/var/log), "#{root}/log"
|
54
|
+
File.open(root / "config.yml", "w") { |f| f.puts config }
|
55
|
+
end
|
56
|
+
|
57
|
+
def edit_thin_configuration
|
58
|
+
config = File.read(root / "thin.yml")
|
59
|
+
config.gsub! %r(/apps/integrity), root
|
60
|
+
File.open(root / "thin.yml", 'w') { |f| f.puts config }
|
61
|
+
end
|
62
|
+
|
63
|
+
def after_setup_message
|
64
|
+
puts
|
65
|
+
puts %Q(Awesome! Integrity was installed successfully!)
|
66
|
+
puts
|
67
|
+
puts %Q(If you want to enable notifiers, install the gems and then require them)
|
68
|
+
puts %Q(in #{root}/config.ru)
|
69
|
+
puts
|
70
|
+
puts %Q(For example:)
|
71
|
+
puts
|
72
|
+
puts %Q( sudo gem install -s http://gems.github.com foca-integrity-email)
|
73
|
+
puts
|
74
|
+
puts %Q(And then in #{root}/config.ru add:)
|
75
|
+
puts
|
76
|
+
puts %Q( require "notifier/email")
|
77
|
+
puts
|
78
|
+
puts %Q(Don't forget to tweak #{root / "config.yml"} to your needs.)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
WithIntegrity.start
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'integrity'
|
4
|
+
|
5
|
+
# If you want to add any notifiers, install the gems and then require them here
|
6
|
+
# For example, to enable the Email notifier: install the gem (from github:
|
7
|
+
#
|
8
|
+
# sudo gem install -s http://gems.github.com foca-integrity-email
|
9
|
+
#
|
10
|
+
# And then uncomment the following line:
|
11
|
+
#
|
12
|
+
# require "notifier/email"
|
13
|
+
|
14
|
+
# Load integrity's configuration.
|
15
|
+
Integrity.config = File.expand_path('./config.yml')
|
16
|
+
|
17
|
+
#######################################################################
|
18
|
+
## ##
|
19
|
+
## == DON'T EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING == ##
|
20
|
+
## ##
|
21
|
+
#######################################################################
|
22
|
+
require Integrity.root / 'app'
|
23
|
+
|
24
|
+
set :public, Integrity.root / 'public'
|
25
|
+
set :views, Integrity.root / 'views'
|
26
|
+
set :port, 8910
|
27
|
+
set :env, :production
|
28
|
+
disable :run, :reload
|
29
|
+
|
30
|
+
run Sinatra.application
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Domain where integrity will be running from. This is used to have
|
2
|
+
# nice URLs in your notifications.
|
3
|
+
# For example:
|
4
|
+
# http://builder.integrityapp.com
|
5
|
+
:base_uri: http://integrity.domain.tld
|
6
|
+
|
7
|
+
# This should be a complete connection string to your database. For example
|
8
|
+
# `mysql://user@localhost/integrity` (you need an `integrity` db created in
|
9
|
+
# localhost, of course).
|
10
|
+
:database_uri: sqlite3:///var/integrity.db
|
11
|
+
|
12
|
+
# This is where your project's code will be checked out to. Make sure it's
|
13
|
+
# writable by the user that runs Integrity.
|
14
|
+
:export_directory: /path/to/scm/exports
|
15
|
+
|
16
|
+
# Path to the integrity log file
|
17
|
+
:log: /var/log/integrity.log
|
18
|
+
|
19
|
+
# Enable or disable HTTP authentication for the app. BE AWARE that if you
|
20
|
+
# disable this anyone can delete and alter projects, so do it only if your
|
21
|
+
# app is running in a controlled environment (ie, behind your company's
|
22
|
+
# firewall.)
|
23
|
+
:use_basic_auth: false
|
24
|
+
|
25
|
+
# When `use_basic_auth` is true, the admin's username for HTTP authentication.
|
26
|
+
:admin_username: username
|
27
|
+
|
28
|
+
# When `use_basic_auth` is true, the admin's password. Usually saved as a
|
29
|
+
# SHA1 hash. See the next option.
|
30
|
+
:admin_password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
31
|
+
|
32
|
+
# If this is true, then whenever we authenticate the admin user, will hash
|
33
|
+
# it using SHA1. If not, we'll assume the provided password is in plain text.
|
34
|
+
:hash_admin_password: true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
environment: production
|
3
|
+
chdir: /apps/integrity
|
4
|
+
address: 127.0.0.1
|
5
|
+
port: 8910
|
6
|
+
pid: /apps/integrity/thin.pid
|
7
|
+
rackup: /apps/integrity/config.ru
|
8
|
+
log: /apps/integrity/log/thin.log
|
9
|
+
max_conns: 1024
|
10
|
+
timeout: 30
|
11
|
+
max_persistent_conns: 512
|
12
|
+
daemonize: true
|
13
|
+
servers: 2
|