giraffesoft-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 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,81 @@
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
+ end
79
+ rescue LoadError
80
+ end
81
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ major: 0
3
+ patch: 3
4
+ minor: 1
data/app.rb ADDED
@@ -0,0 +1,266 @@
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 notifier_form(notifier)
260
+ haml(notifier.to_haml, :layout => :notifier, :locals => {
261
+ :config => current_project.config_for(notifier),
262
+ :notifier => "#{notifier.to_s.split(/::/).last}",
263
+ :enabled => current_project.notifies?(notifier)
264
+ })
265
+ end
266
+ end