oliyoung-integrity 0.1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +73 -0
- data/Rakefile +118 -0
- data/bin/integrity +4 -0
- data/config/config.sample.ru +21 -0
- data/config/config.sample.yml +41 -0
- data/config/thin.sample.yml +13 -0
- data/lib/integrity.rb +72 -0
- data/lib/integrity/app.rb +138 -0
- data/lib/integrity/author.rb +39 -0
- data/lib/integrity/build.rb +84 -0
- data/lib/integrity/commit.rb +71 -0
- data/lib/integrity/core_ext/object.rb +6 -0
- data/lib/integrity/helpers.rb +16 -0
- data/lib/integrity/helpers/authorization.rb +33 -0
- data/lib/integrity/helpers/breadcrumbs.rb +20 -0
- data/lib/integrity/helpers/forms.rb +28 -0
- data/lib/integrity/helpers/pretty_output.rb +45 -0
- data/lib/integrity/helpers/rendering.rb +19 -0
- data/lib/integrity/helpers/resources.rb +19 -0
- data/lib/integrity/helpers/urls.rb +49 -0
- data/lib/integrity/installer.rb +131 -0
- data/lib/integrity/migrations.rb +140 -0
- data/lib/integrity/notifier.rb +48 -0
- data/lib/integrity/notifier/base.rb +65 -0
- data/lib/integrity/project.rb +153 -0
- data/lib/integrity/project_builder.rb +56 -0
- data/lib/integrity/scm.rb +19 -0
- data/lib/integrity/scm/git.rb +84 -0
- data/lib/integrity/scm/git/uri.rb +57 -0
- data/public/buttons.css +82 -0
- data/public/reset.css +7 -0
- data/public/spinner.gif +0 -0
- data/test/acceptance/api_test.rb +97 -0
- data/test/acceptance/browse_project_builds_test.rb +65 -0
- data/test/acceptance/browse_project_test.rb +95 -0
- data/test/acceptance/build_notifications_test.rb +42 -0
- data/test/acceptance/create_project_test.rb +97 -0
- data/test/acceptance/delete_project_test.rb +53 -0
- data/test/acceptance/edit_project_test.rb +117 -0
- data/test/acceptance/error_page_test.rb +18 -0
- data/test/acceptance/helpers.rb +2 -0
- data/test/acceptance/installer_test.rb +82 -0
- data/test/acceptance/manual_build_project_test.rb +82 -0
- data/test/acceptance/notifier_test.rb +109 -0
- data/test/acceptance/project_syndication_test.rb +30 -0
- data/test/acceptance/stylesheet_test.rb +18 -0
- data/test/helpers.rb +80 -0
- data/test/helpers/acceptance.rb +78 -0
- data/test/helpers/acceptance/email_notifier.rb +55 -0
- data/test/helpers/acceptance/git_helper.rb +99 -0
- data/test/helpers/acceptance/textfile_notifier.rb +26 -0
- data/test/helpers/expectations.rb +4 -0
- data/test/helpers/expectations/be_a.rb +23 -0
- data/test/helpers/expectations/change.rb +90 -0
- data/test/helpers/expectations/have.rb +105 -0
- data/test/helpers/expectations/predicates.rb +37 -0
- data/test/helpers/fixtures.rb +87 -0
- data/test/helpers/initial_migration_fixture.sql +44 -0
- data/test/unit/build_test.rb +51 -0
- data/test/unit/commit_test.rb +83 -0
- data/test/unit/helpers_test.rb +56 -0
- data/test/unit/integrity_test.rb +18 -0
- data/test/unit/migrations_test.rb +56 -0
- data/test/unit/notifier_test.rb +123 -0
- data/test/unit/project_builder_test.rb +111 -0
- data/test/unit/project_test.rb +282 -0
- data/test/unit/scm_test.rb +54 -0
- data/views/_commit_info.haml +24 -0
- data/views/build.haml +2 -0
- data/views/error.haml +37 -0
- data/views/home.haml +21 -0
- data/views/integrity.sass +400 -0
- data/views/layout.haml +28 -0
- data/views/new.haml +51 -0
- data/views/not_found.haml +31 -0
- data/views/notifier.haml +7 -0
- data/views/project.builder +21 -0
- data/views/project.haml +30 -0
- data/views/unauthorized.haml +38 -0
- metadata +225 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
module Integrity
|
2
|
+
class Author < DataMapper::Type
|
3
|
+
primitive String
|
4
|
+
size 65535
|
5
|
+
lazy true
|
6
|
+
|
7
|
+
class AuthorStruct < Struct.new(:name, :email)
|
8
|
+
def self.parse(string)
|
9
|
+
raise ArgumentError.new("invalid author string") unless string =~ /^(.*) <(.*)>$/
|
10
|
+
|
11
|
+
new($1.strip, $2.strip)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
@full ||= "#{name} <#{email}>"
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :full, :to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.load(value, property)
|
22
|
+
AuthorStruct.parse(value) unless value.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.dump(value, property)
|
26
|
+
return nil if value.nil?
|
27
|
+
|
28
|
+
value.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.typecast(value, property)
|
32
|
+
case value
|
33
|
+
when AuthorStruct then value
|
34
|
+
when NilClass then load(nil, property)
|
35
|
+
else load(value.to_s, property)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Integrity
|
2
|
+
class Build
|
3
|
+
include DataMapper::Resource
|
4
|
+
|
5
|
+
property :id, Integer, :serial => true
|
6
|
+
property :output, Text, :default => "", :lazy => false
|
7
|
+
property :successful, Boolean, :default => false
|
8
|
+
property :commit_id, Integer, :nullable => false
|
9
|
+
property :created_at, DateTime
|
10
|
+
property :updated_at, DateTime
|
11
|
+
property :started_at, DateTime
|
12
|
+
property :completed_at, DateTime
|
13
|
+
|
14
|
+
belongs_to :commit, :class_name => "Integrity::Commit"
|
15
|
+
|
16
|
+
def self.pending
|
17
|
+
all(:started_at => nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def pending?
|
21
|
+
started_at.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def failed?
|
25
|
+
!successful?
|
26
|
+
end
|
27
|
+
|
28
|
+
def status
|
29
|
+
case
|
30
|
+
when pending? then :pending
|
31
|
+
when successful? then :success
|
32
|
+
when failed? then :failed
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def start!(time=Time.now)
|
37
|
+
self.started_at = time
|
38
|
+
end
|
39
|
+
|
40
|
+
def complete!(time=Time.now)
|
41
|
+
self.completed_at = time
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Deprecated methods
|
46
|
+
#
|
47
|
+
def short_commit_identifier
|
48
|
+
warn "Build#short_commit_identifier is deprecated, use Commit#short_identifier"
|
49
|
+
commit.short_identifier
|
50
|
+
end
|
51
|
+
|
52
|
+
def commit_identifier
|
53
|
+
warn "Build#commit_identifier is deprecated, use Commit#identifier"
|
54
|
+
commit.identifier
|
55
|
+
end
|
56
|
+
|
57
|
+
def commit_author
|
58
|
+
warn "Build#commit_author is deprecated, use Commit#author"
|
59
|
+
commit.author
|
60
|
+
end
|
61
|
+
|
62
|
+
def commit_message
|
63
|
+
warn "Build#commit_message is deprecated, use Commit#message"
|
64
|
+
commit.message
|
65
|
+
end
|
66
|
+
|
67
|
+
def commited_at
|
68
|
+
warn "Build#commited_at is deprecated, use Commit#committed_at"
|
69
|
+
commit.committed_at
|
70
|
+
end
|
71
|
+
|
72
|
+
def project_id
|
73
|
+
warn "Build#project_id is deprecated, use Commit#project_id"
|
74
|
+
commit.project_id
|
75
|
+
end
|
76
|
+
|
77
|
+
def commit_metadata
|
78
|
+
warn "Build#commit_metadata is deprecated, use the different methods in Commit instead"
|
79
|
+
{ :message => commit.message,
|
80
|
+
:author => commit.author,
|
81
|
+
:date => commit.committed_at }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Integrity
|
2
|
+
class Commit
|
3
|
+
include DataMapper::Resource
|
4
|
+
|
5
|
+
property :id, Integer, :serial => true
|
6
|
+
property :identifier, String, :nullable => false
|
7
|
+
property :message, String, :length => 255
|
8
|
+
property :author, Author, :length => 255
|
9
|
+
property :committed_at, DateTime
|
10
|
+
property :created_at, DateTime
|
11
|
+
property :updated_at, DateTime
|
12
|
+
|
13
|
+
has 1, :build, :class_name => "Integrity::Build", :order => [:created_at.desc]
|
14
|
+
belongs_to :project, :class_name => "Integrity::Project"
|
15
|
+
|
16
|
+
def message
|
17
|
+
attribute_get(:message) || "<Commit message not loaded>"
|
18
|
+
end
|
19
|
+
|
20
|
+
def author
|
21
|
+
attribute_get(:author) || Author.load('<Commit author not loaded> <<Commit author not loaded>>', :author)
|
22
|
+
end
|
23
|
+
|
24
|
+
def short_identifier
|
25
|
+
identifier.to_s[0..6]
|
26
|
+
end
|
27
|
+
|
28
|
+
def status
|
29
|
+
build.nil? ? :pending : build.status
|
30
|
+
end
|
31
|
+
|
32
|
+
def successful?
|
33
|
+
status == :success
|
34
|
+
end
|
35
|
+
|
36
|
+
def failed?
|
37
|
+
status == :failed
|
38
|
+
end
|
39
|
+
|
40
|
+
def pending?
|
41
|
+
status == :pending
|
42
|
+
end
|
43
|
+
|
44
|
+
def human_readable_status
|
45
|
+
case status
|
46
|
+
when :success; "Built #{short_identifier} successfully"
|
47
|
+
when :failed; "Built #{short_identifier} and failed"
|
48
|
+
when :pending; "#{short_identifier} hasn't been built yet"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def output
|
53
|
+
build && build.output
|
54
|
+
end
|
55
|
+
|
56
|
+
def queue_build
|
57
|
+
self.build = Build.create(:commit_id => id)
|
58
|
+
self.save
|
59
|
+
|
60
|
+
# Build on foreground (this will move away, I promise)
|
61
|
+
ProjectBuilder.new(project).build(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Deprecation layer
|
65
|
+
alias :short_commit_identifier :short_identifier
|
66
|
+
alias :commit_identifier :identifier
|
67
|
+
alias :commit_author :author
|
68
|
+
alias :commit_message :message
|
69
|
+
alias :commited_at :committed_at
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/helpers/*.rb"].each &method(:require)
|
2
|
+
|
3
|
+
module Integrity
|
4
|
+
module Helpers
|
5
|
+
include Authorization
|
6
|
+
include Breadcrumbs
|
7
|
+
include Forms
|
8
|
+
include PrettyOutput
|
9
|
+
include Rendering
|
10
|
+
include Resources
|
11
|
+
include Urls
|
12
|
+
|
13
|
+
include Rack::Utils
|
14
|
+
alias :h :escape_html
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "sinatra/ditties"
|
2
|
+
|
3
|
+
module Integrity
|
4
|
+
module Helpers
|
5
|
+
module Authorization
|
6
|
+
include Sinatra::Authorization
|
7
|
+
|
8
|
+
def authorization_realm
|
9
|
+
"Integrity"
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorized?
|
13
|
+
return true unless Integrity.config[:use_basic_auth]
|
14
|
+
!!request.env["REMOTE_USER"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def authorize(user, password)
|
18
|
+
if Integrity.config[:hash_admin_password]
|
19
|
+
password = Digest::SHA1.hexdigest(password)
|
20
|
+
end
|
21
|
+
|
22
|
+
!Integrity.config[:use_basic_auth] ||
|
23
|
+
(Integrity.config[:admin_username] == user &&
|
24
|
+
Integrity.config[:admin_password] == password)
|
25
|
+
end
|
26
|
+
|
27
|
+
def unauthorized!(realm=authorization_realm)
|
28
|
+
response["WWW-Authenticate"] = %(Basic realm="#{realm}")
|
29
|
+
throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module Breadcrumbs
|
4
|
+
def pages
|
5
|
+
@pages ||= [["projects", "/"], ["new project", "/new"]]
|
6
|
+
end
|
7
|
+
|
8
|
+
def breadcrumbs(*crumbs)
|
9
|
+
crumbs[0..-2].map do |crumb|
|
10
|
+
if page_data = pages.detect {|c| c.first == crumb }
|
11
|
+
%Q(<a href="#{page_data.last}">#{page_data.first}</a>)
|
12
|
+
elsif @project && @project.permalink == crumb
|
13
|
+
%Q(<a href="#{project_url(@project)}">#{@project.permalink}</a>)
|
14
|
+
end
|
15
|
+
end + [crumbs.last]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module Forms
|
4
|
+
def errors_on(object, field)
|
5
|
+
return "" unless errors = object.errors.on(field)
|
6
|
+
errors.map {|e| e.gsub(/#{field} /i, "") }.join(", ")
|
7
|
+
end
|
8
|
+
|
9
|
+
def error_class(object, field)
|
10
|
+
object.errors.on(field).nil? ? "" : "with_errors"
|
11
|
+
end
|
12
|
+
|
13
|
+
def checkbox(name, condition, extras={})
|
14
|
+
attrs = { :name => name, :type => "checkbox", :value => "1" }
|
15
|
+
attrs[:checked] = !!condition
|
16
|
+
attrs.update(extras)
|
17
|
+
end
|
18
|
+
|
19
|
+
def notifier_form(notifier)
|
20
|
+
haml(notifier.to_haml, :layout => :notifier, :locals => {
|
21
|
+
:config => current_project.config_for(notifier),
|
22
|
+
:notifier => "#{notifier.to_s.split(/::/).last}",
|
23
|
+
:enabled => current_project.notifies?(notifier)
|
24
|
+
})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module PrettyOutput
|
4
|
+
def cycle(*values)
|
5
|
+
@cycles ||= {}
|
6
|
+
@cycles[values] ||= -1 # first value returned is 0
|
7
|
+
next_value = @cycles[values] = (@cycles[values] + 1) % values.size
|
8
|
+
values[next_value]
|
9
|
+
end
|
10
|
+
|
11
|
+
def bash_color_codes(string)
|
12
|
+
string.gsub("\e[0m", '</span>').
|
13
|
+
gsub("\e[31m", '<span class="color31">').
|
14
|
+
gsub("\e[32m", '<span class="color32">').
|
15
|
+
gsub("\e[33m", '<span class="color33">').
|
16
|
+
gsub("\e[34m", '<span class="color34">').
|
17
|
+
gsub("\e[35m", '<span class="color35">').
|
18
|
+
gsub("\e[36m", '<span class="color36">').
|
19
|
+
gsub("\e[37m", '<span class="color37">')
|
20
|
+
end
|
21
|
+
|
22
|
+
def pretty_date(date_time)
|
23
|
+
days_away = (Date.today - Date.new(date_time.year, date_time.month, date_time.day)).to_i
|
24
|
+
if days_away == 0
|
25
|
+
"today"
|
26
|
+
elsif days_away == 1
|
27
|
+
"yesterday"
|
28
|
+
else
|
29
|
+
strftime_with_ordinal(date_time, "on %b %d%o")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def strftime_with_ordinal(date_time, format_string)
|
34
|
+
ordinal = case date_time.day
|
35
|
+
when 1, 21, 31 then "st"
|
36
|
+
when 2, 22 then "nd"
|
37
|
+
when 3, 23 then "rd"
|
38
|
+
else "th"
|
39
|
+
end
|
40
|
+
|
41
|
+
date_time.strftime(format_string.gsub("%o", ordinal))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module Rendering
|
4
|
+
def stylesheet_hash
|
5
|
+
@_hash ||= Digest::MD5.file(
|
6
|
+
options.views + "/integrity.sass").tap { |file| file.hexdigest }
|
7
|
+
end
|
8
|
+
|
9
|
+
def show(view, options={})
|
10
|
+
@title = breadcrumbs(*options[:title])
|
11
|
+
haml view
|
12
|
+
end
|
13
|
+
|
14
|
+
def partial(template, locals={})
|
15
|
+
haml("_#{template}".to_sym, :locals => locals, :layout => false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module Resources
|
4
|
+
def current_project
|
5
|
+
@project ||= Project.first(:permalink => params[:project]) or raise Sinatra::NotFound
|
6
|
+
end
|
7
|
+
|
8
|
+
def current_commit
|
9
|
+
@commit ||= current_project.commits.first(:identifier => params[:commit]) or raise Sinatra::NotFound
|
10
|
+
end
|
11
|
+
|
12
|
+
def update_notifiers_of(project)
|
13
|
+
if params["notifiers"]
|
14
|
+
project.enable_notifiers(params["notifiers"].keys, params["notifiers"])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Integrity
|
2
|
+
module Helpers
|
3
|
+
module Urls
|
4
|
+
def url(path)
|
5
|
+
Addressable::URI.parse(request.url).join(path).to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def root_url
|
9
|
+
url("/")
|
10
|
+
end
|
11
|
+
|
12
|
+
def project_path(project, *path)
|
13
|
+
"/" << [project.permalink, *path].join("/")
|
14
|
+
end
|
15
|
+
|
16
|
+
def project_url(project, *path)
|
17
|
+
url project_path(project, *path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def push_url_for(project)
|
21
|
+
Addressable::URI.parse(project_url(project, "push")).tap do |url|
|
22
|
+
if Integrity.config[:use_basic_auth]
|
23
|
+
url.user = Integrity.config[:admin_username]
|
24
|
+
url.password = Integrity.config[:hash_admin_password] ?
|
25
|
+
"<password>" : Integrity.config[:admin_password]
|
26
|
+
end
|
27
|
+
end.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def commit_path(commit, *path)
|
31
|
+
project_path(commit.project, "commits", commit.identifier, *path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_path(build, *path)
|
35
|
+
warn "#build_path is deprecated, use #commit_path instead"
|
36
|
+
commit_path build.commit, *path
|
37
|
+
end
|
38
|
+
|
39
|
+
def commit_url(commit)
|
40
|
+
url commit_path(commit)
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_url(build)
|
44
|
+
warn "#build_url is deprecated, use #commit_url instead"
|
45
|
+
commit_url build.commit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|