forked from integrity/integrity
/
commit.rb
72 lines (59 loc) · 1.95 KB
/
commit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module Integrity
class Commit
include DataMapper::Resource
property :id, Integer, :serial => true
property :identifier, String, :nullable => false
property :message, String, :nullable => false, :length => 255
property :author, String, :nullable => false, :length => 255
property :committed_at, DateTime, :nullable => false
property :created_at, DateTime
property :updated_at, DateTime
belongs_to :project, :class_name => "Integrity::Project"
has 1, :build, :class_name => "Integrity::Build"
def short_identifier
identifier.to_s[0..6]
end
def author
@structured_author ||= attribute_get(:author).tap do |author_string|
author_string =~ /^(.*) <(.*)>$/
author_string.singleton_def(:name) { $1.strip }
author_string.singleton_def(:email) { $2.strip }
author_string.singleton_def(:full) { author_string }
end
end
def status
build.nil? ? :pending : build.status
end
def successful?
status == :success
end
def failed?
status == :failed
end
def pending?
status == :pending
end
def human_readable_status
case status
when :success; "Built #{short_identifier} successfully"
when :failed; "Built #{short_identifier} and failed"
when :pending; "#{short_identifier} hasn't been built yet"
end
end
def output
build && build.output
end
def queue_build
self.build = Build.create(:commit_id => id)
self.save
# Build on foreground (this will move away, I promise)
ProjectBuilder.new(project).build(self)
end
# Deprecation layer
alias :short_commit_identifier :short_identifier
alias :commit_identifier :identifier
alias :commit_author :author
alias :commit_message :message
alias :commited_at :committed_at
end
end