oliyoung-integrity 0.1.9.0

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.
Files changed (80) hide show
  1. data/README.markdown +73 -0
  2. data/Rakefile +118 -0
  3. data/bin/integrity +4 -0
  4. data/config/config.sample.ru +21 -0
  5. data/config/config.sample.yml +41 -0
  6. data/config/thin.sample.yml +13 -0
  7. data/lib/integrity.rb +72 -0
  8. data/lib/integrity/app.rb +138 -0
  9. data/lib/integrity/author.rb +39 -0
  10. data/lib/integrity/build.rb +84 -0
  11. data/lib/integrity/commit.rb +71 -0
  12. data/lib/integrity/core_ext/object.rb +6 -0
  13. data/lib/integrity/helpers.rb +16 -0
  14. data/lib/integrity/helpers/authorization.rb +33 -0
  15. data/lib/integrity/helpers/breadcrumbs.rb +20 -0
  16. data/lib/integrity/helpers/forms.rb +28 -0
  17. data/lib/integrity/helpers/pretty_output.rb +45 -0
  18. data/lib/integrity/helpers/rendering.rb +19 -0
  19. data/lib/integrity/helpers/resources.rb +19 -0
  20. data/lib/integrity/helpers/urls.rb +49 -0
  21. data/lib/integrity/installer.rb +131 -0
  22. data/lib/integrity/migrations.rb +140 -0
  23. data/lib/integrity/notifier.rb +48 -0
  24. data/lib/integrity/notifier/base.rb +65 -0
  25. data/lib/integrity/project.rb +153 -0
  26. data/lib/integrity/project_builder.rb +56 -0
  27. data/lib/integrity/scm.rb +19 -0
  28. data/lib/integrity/scm/git.rb +84 -0
  29. data/lib/integrity/scm/git/uri.rb +57 -0
  30. data/public/buttons.css +82 -0
  31. data/public/reset.css +7 -0
  32. data/public/spinner.gif +0 -0
  33. data/test/acceptance/api_test.rb +97 -0
  34. data/test/acceptance/browse_project_builds_test.rb +65 -0
  35. data/test/acceptance/browse_project_test.rb +95 -0
  36. data/test/acceptance/build_notifications_test.rb +42 -0
  37. data/test/acceptance/create_project_test.rb +97 -0
  38. data/test/acceptance/delete_project_test.rb +53 -0
  39. data/test/acceptance/edit_project_test.rb +117 -0
  40. data/test/acceptance/error_page_test.rb +18 -0
  41. data/test/acceptance/helpers.rb +2 -0
  42. data/test/acceptance/installer_test.rb +82 -0
  43. data/test/acceptance/manual_build_project_test.rb +82 -0
  44. data/test/acceptance/notifier_test.rb +109 -0
  45. data/test/acceptance/project_syndication_test.rb +30 -0
  46. data/test/acceptance/stylesheet_test.rb +18 -0
  47. data/test/helpers.rb +80 -0
  48. data/test/helpers/acceptance.rb +78 -0
  49. data/test/helpers/acceptance/email_notifier.rb +55 -0
  50. data/test/helpers/acceptance/git_helper.rb +99 -0
  51. data/test/helpers/acceptance/textfile_notifier.rb +26 -0
  52. data/test/helpers/expectations.rb +4 -0
  53. data/test/helpers/expectations/be_a.rb +23 -0
  54. data/test/helpers/expectations/change.rb +90 -0
  55. data/test/helpers/expectations/have.rb +105 -0
  56. data/test/helpers/expectations/predicates.rb +37 -0
  57. data/test/helpers/fixtures.rb +87 -0
  58. data/test/helpers/initial_migration_fixture.sql +44 -0
  59. data/test/unit/build_test.rb +51 -0
  60. data/test/unit/commit_test.rb +83 -0
  61. data/test/unit/helpers_test.rb +56 -0
  62. data/test/unit/integrity_test.rb +18 -0
  63. data/test/unit/migrations_test.rb +56 -0
  64. data/test/unit/notifier_test.rb +123 -0
  65. data/test/unit/project_builder_test.rb +111 -0
  66. data/test/unit/project_test.rb +282 -0
  67. data/test/unit/scm_test.rb +54 -0
  68. data/views/_commit_info.haml +24 -0
  69. data/views/build.haml +2 -0
  70. data/views/error.haml +37 -0
  71. data/views/home.haml +21 -0
  72. data/views/integrity.sass +400 -0
  73. data/views/layout.haml +28 -0
  74. data/views/new.haml +51 -0
  75. data/views/not_found.haml +31 -0
  76. data/views/notifier.haml +7 -0
  77. data/views/project.builder +21 -0
  78. data/views/project.haml +30 -0
  79. data/views/unauthorized.haml +38 -0
  80. metadata +225 -0
data/README.markdown ADDED
@@ -0,0 +1,73 @@
1
+ Integrity
2
+ =========
3
+
4
+ [Integrity][website] is your friendly automated Continuous Integration server.
5
+
6
+ * See our [website][] for documentation and a [live demo][demo]
7
+ * Report bugs and submit features request on our [Lighthouse account][lighthouse]
8
+ * Join us on [#integrity][irc-channel] for ideas, help, patches or something
9
+ * Get the code on [GitHub][repo]
10
+
11
+ Try it!
12
+ -------
13
+
14
+ $ git clone git://github.com/foca/integrity.git
15
+ $ rake launch
16
+ # Navigate to <http://0.0.0.0:4567>
17
+
18
+ Thanks
19
+ ------
20
+
21
+ Thanks to the fellowing people for their feedbacks, ideas and patches :
22
+
23
+ * [James Adam][james]
24
+ * [Elliott Cable][ec]
25
+ * [Corey Donohoe][atmos]
26
+ * [Kyle Hargraves][kyle]
27
+ * [Pier-Hugues Pellerin][ph]
28
+ * [Simon Rozet][sr]
29
+ * [Scott Taylor][scott]
30
+
31
+ License
32
+ -------
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2008 [Nicolás Sanguinetti][foca], [entp][]
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56
+
57
+ [website]: http://integrityapp.com
58
+ [demo]: http://builder.integrityapp.com
59
+ [repo]: http://github.com/foca/integrity
60
+ [lighthouse]: http://integrity.lighthouseapp.com/projects/14308-integrity
61
+ [irc-channel]: irc://irc.freenode.net/integrity
62
+
63
+ [foca]: http://nicolassanguinetti.info/
64
+ [entp]: http://entp.com
65
+
66
+ [james]: http://github.com/lazyatom
67
+ [ec]: http://github.com/elliotcabble
68
+ [atmos]: http://github.com/atmos
69
+ [kyle]: http://github.com/pd
70
+ [ph]: http://github.com/ph
71
+ [sr]: http://purl.org/net/sr/
72
+ [scott]: http://github.com/smtlaissezfaire
73
+
data/Rakefile ADDED
@@ -0,0 +1,118 @@
1
+ require "rake/testtask"
2
+ require "rake/clean"
3
+ require "rcov/rcovtask"
4
+
5
+ begin
6
+ require "metric_fu"
7
+ rescue LoadError
8
+ end
9
+
10
+ desc "Default: run all tests"
11
+ task :default => :test
12
+
13
+ desc "Special task for running tests on <http://builder.integrityapp.com>"
14
+ task :ci do
15
+ sh "git submodule update --init"
16
+
17
+ Rake::Task["test"].invoke
18
+
19
+ metrics = %w(flay flog:all reek roodi saikuro)
20
+ metrics.each { |m| Rake::Task["metrics:#{m}"].invoke }
21
+
22
+ rm_rf "/var/www/integrity-metrics"
23
+ mv "tmp/metric_fu", "/var/www/integrity-metrics"
24
+
25
+ File.open("/var/www/integrity-metrics/index.html", "w") { |f|
26
+ f << "<ul>"
27
+ metrics.map { |m| m.split(":").first }.each { |m|
28
+ f << %Q(<li><a href="/#{m}">#{m}</a></li>)
29
+ }
30
+ f << "</ul>"
31
+ }
32
+ end
33
+
34
+ desc "Run tests"
35
+ task :test => %w(test:units test:acceptance)
36
+ namespace :test do
37
+ Rake::TestTask.new(:units) do |t|
38
+ t.test_files = FileList["test/unit/*_test.rb"]
39
+ end
40
+
41
+ Rake::TestTask.new(:acceptance) do |t|
42
+ t.test_files = FileList["test/acceptance/*_test.rb"]
43
+ end
44
+
45
+ desc "Install all gems on which the tests depend on"
46
+ task :install_dependencies do
47
+ system "gem install rr mocha dm-sweatshop ZenTest"
48
+ system "gem install -s http://gems.github.com jeremymcanally-context \
49
+ jeremymcanally-matchy jeremymcanally-pending foca-storyteller"
50
+ system "git submodule update --init"
51
+ end
52
+ end
53
+
54
+ desc "Launch Integrity real quick"
55
+ task :launch do
56
+ ruby "bin/integrity launch"
57
+ end
58
+
59
+ directory "dist/"
60
+ CLOBBER.include("dist")
61
+
62
+ # Load the gemspec using the same limitations as github
63
+ def spec
64
+ @spec ||=
65
+ begin
66
+ require "rubygems/specification"
67
+ data = File.read("integrity.gemspec")
68
+ spec = nil
69
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
70
+ spec
71
+ end
72
+ end
73
+
74
+ def package(ext="")
75
+ "dist/integrity-#{spec.version}" + ext
76
+ end
77
+
78
+ desc "Build and install as local gem"
79
+ task :install => package('.gem') do
80
+ sh "gem install #{package('.gem')}"
81
+ end
82
+
83
+ desc "Publish the current release on Rubyforge"
84
+ task :rubyforge => ["rubyforge:gem", "rubyforge:tarball", "rubyforge:git"]
85
+
86
+ namespace :rubyforge do
87
+ desc "Publish gem and tarball to rubyforge"
88
+ task :gem => package(".gem") do
89
+ sh "rubyforge add_release integrity integrity #{spec.version} #{package('.gem')}"
90
+ end
91
+
92
+ task :tarball => package(".tar.gz") do
93
+ sh "rubyforge add_file integrity integrity #{spec.version} #{package('.tar.gz')}"
94
+ end
95
+
96
+ desc "Push to gitosis@rubyforge.org:integrity.git"
97
+ task :git do
98
+ sh "git push gitosis@rubyforge.org:integrity.git master"
99
+ end
100
+ end
101
+
102
+ desc "Build gem tarball into dist/"
103
+ task :package => %w(.gem .tar.gz).map { |ext| package(ext) }
104
+ namespace :package do
105
+ file package(".tar.gz") => "dist/" do |f|
106
+ sh <<-SH
107
+ git archive \
108
+ --prefix=integrity-#{spec.version}/ \
109
+ --format=tar \
110
+ HEAD | gzip > #{f.name}
111
+ SH
112
+ end
113
+
114
+ file package(".gem") => "dist/" do |f|
115
+ sh "gem build integrity.gemspec"
116
+ mv File.basename(f.name), f.name
117
+ end
118
+ end
data/bin/integrity ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + "/../lib/integrity/installer"
3
+
4
+ Integrity::Installer.start
@@ -0,0 +1,21 @@
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 configuration and initialize Integrity
15
+ Integrity.new(File.dirname(__FILE__) + "/config.yml")
16
+
17
+ # You probably don't want to edit anything below
18
+ Integrity::App.set :environment, ENV["RACK_ENV"] || :production
19
+ Integrity::App.set :port, 8910
20
+
21
+ run Integrity::App
@@ -0,0 +1,41 @@
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.
8
+ #
9
+ # Examples:
10
+ # * `mysql://user:password@localhost/integrity`
11
+ # * `postgres://user:password@localhost/integrity`
12
+ # * `sqlite3:///home/integrity/db/integrity.sqlite`
13
+ #
14
+ # Note:
15
+ # * The appropriate data_objects adapter must be installed (`do_mysql`, etc)
16
+ # * You must create the `integrity` database on localhost, of course.
17
+ :database_uri: sqlite3:///var/integrity.db
18
+
19
+ # This is where your project's code will be checked out to. Make sure it's
20
+ # writable by the user that runs Integrity.
21
+ :export_directory: /path/to/scm/exports
22
+
23
+ # Path to the integrity log file
24
+ :log: /var/log/integrity.log
25
+
26
+ # Enable or disable HTTP authentication for the app. BE AWARE that if you
27
+ # disable this anyone can delete and alter projects, so do it only if your
28
+ # app is running in a controlled environment (ie, behind your company's
29
+ # firewall.)
30
+ :use_basic_auth: false
31
+
32
+ # When `use_basic_auth` is true, the admin's username for HTTP authentication.
33
+ :admin_username: username
34
+
35
+ # When `use_basic_auth` is true, the admin's password. Usually saved as a
36
+ # SHA1 hash. See the next option.
37
+ :admin_password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
38
+
39
+ # If this is true, then whenever we authenticate the admin user, will hash
40
+ # it using SHA1. If not, we'll assume the provided password is in plain text.
41
+ :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
data/lib/integrity.rb ADDED
@@ -0,0 +1,72 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__))
2
+
3
+ require "json"
4
+ require "haml"
5
+ require "dm-core"
6
+ require "dm-validations"
7
+ require "dm-types"
8
+ require "dm-timestamps"
9
+ require "dm-aggregates"
10
+ require "sinatra/base"
11
+
12
+ require "yaml"
13
+ require "logger"
14
+ require "digest/sha1"
15
+ require "timeout"
16
+ require "ostruct"
17
+ require "pathname"
18
+
19
+ require "integrity/core_ext/object"
20
+
21
+ require "integrity/project"
22
+ require "integrity/author"
23
+ require "integrity/commit"
24
+ require "integrity/build"
25
+ require "integrity/project_builder"
26
+ require "integrity/scm"
27
+ require "integrity/scm/git"
28
+ require "integrity/notifier"
29
+ require "integrity/helpers"
30
+ require "integrity/app"
31
+
32
+ module Integrity
33
+ def self.new(config_file = nil)
34
+ self.config = YAML.load_file(config_file) unless config_file.nil?
35
+ DataMapper.setup(:default, config[:database_uri])
36
+ end
37
+
38
+ def self.default_configuration
39
+ @defaults ||= { :database_uri => "sqlite3::memory:",
40
+ :export_directory => "/tmp/exports",
41
+ :log => STDOUT,
42
+ :base_uri => "http://localhost:8910",
43
+ :use_basic_auth => false,
44
+ :build_all_commits => true,
45
+ :log_debug_info => false }
46
+ end
47
+
48
+ def self.config
49
+ @config ||= default_configuration.dup
50
+ end
51
+
52
+ def self.config=(options)
53
+ @config = default_configuration.merge(options)
54
+ end
55
+
56
+ def self.log(message, &block)
57
+ logger.info(message, &block)
58
+ end
59
+
60
+ def self.logger
61
+ @logger ||= Logger.new(config[:log], "daily").tap do |logger|
62
+ logger.formatter = LogFormatter.new
63
+ end
64
+ end
65
+ private_class_method :logger
66
+
67
+ class LogFormatter < Logger::Formatter
68
+ def call(severity, time, progname, msg)
69
+ time.strftime("[%H:%M:%S] ") + msg2str(msg) + "\n"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,138 @@
1
+ module Integrity
2
+ class App < Sinatra::Default
3
+ set :root, File.dirname(__FILE__) + "/../.."
4
+ set :app_file, __FILE__
5
+ enable :sessions
6
+
7
+ include Integrity
8
+ include Integrity::Helpers
9
+
10
+ not_found do
11
+ status 404
12
+ show :not_found, :title => "lost, are we?"
13
+ end
14
+
15
+ error do
16
+ @error = request.env["sinatra.error"]
17
+ status 500
18
+ show :error, :title => "something has gone terribly wrong"
19
+ end
20
+
21
+ before do
22
+ # The browser only sends http auth data for requests that are explicitly
23
+ # required to do so. This way we get the real values of +#logged_in?+ and
24
+ # +#current_user+
25
+ login_required if session[:user]
26
+ end
27
+
28
+ get "/integrity.css" do
29
+ response["Content-Type"] = "text/css; charset=utf-8"
30
+ etag stylesheet_hash
31
+ sass :integrity
32
+ end
33
+
34
+ get "/" do
35
+ @projects = Project.only_public_unless(authorized?)
36
+ show :home, :title => "projects"
37
+ end
38
+
39
+ get "/login" do
40
+ login_required
41
+
42
+ session[:user] = current_user
43
+ redirect root_url
44
+ end
45
+
46
+ get "/new" do
47
+ login_required
48
+
49
+ @project = Project.new
50
+ show :new, :title => ["projects", "new project"]
51
+ end
52
+
53
+ post "/" do
54
+ login_required
55
+
56
+ @project = Project.new(params[:project_data])
57
+
58
+ if @project.save
59
+ update_notifiers_of(@project)
60
+ redirect project_url(@project)
61
+ else
62
+ show :new, :title => ["projects", "new project"]
63
+ end
64
+ end
65
+
66
+ get "/:project.atom" do
67
+ login_required unless current_project.public?
68
+ response["Content-Type"] = "application/rss+xml; charset=utf-8"
69
+ builder :project
70
+ end
71
+
72
+ get "/:project" do
73
+ login_required unless current_project.public?
74
+ show :project, :title => ["projects", current_project.name]
75
+ end
76
+
77
+ put "/:project" do
78
+ login_required
79
+
80
+ if current_project.update_attributes(params[:project_data])
81
+ update_notifiers_of(current_project)
82
+ redirect project_url(current_project)
83
+ else
84
+ show :new, :title => ["projects", current_project.permalink, "edit"]
85
+ end
86
+ end
87
+
88
+ delete "/:project" do
89
+ login_required
90
+
91
+ current_project.destroy
92
+ redirect root_url
93
+ end
94
+
95
+ get "/:project/edit" do
96
+ login_required
97
+
98
+ show :new, :title => ["projects", current_project.permalink, "edit"]
99
+ end
100
+
101
+ post "/:project/push" do
102
+ login_required
103
+
104
+ content_type "text/plain"
105
+
106
+ begin
107
+ current_project.push(params[:payload])
108
+ 201
109
+ rescue ArgumentError
110
+ [422, "Invalid Request"]
111
+ end
112
+ end
113
+
114
+ post "/:project/builds" do
115
+ login_required
116
+
117
+ current_project.build
118
+ redirect project_url(current_project)
119
+ end
120
+
121
+ get "/:project/commits/:commit" do
122
+ login_required unless current_project.public?
123
+
124
+ show :build, :title => ["projects", current_project.permalink, current_commit.short_commit_identifier]
125
+ end
126
+
127
+ get "/:project/builds/:commit" do
128
+ redirect "/#{params[:project]}/commits/#{params[:commit]}", 301
129
+ end
130
+
131
+ post "/:project/commits/:commit/builds" do
132
+ login_required
133
+
134
+ current_project.build(params[:commit])
135
+ redirect commit_url(current_commit)
136
+ end
137
+ end
138
+ end