Class: Heidi::Project
- Inherits:
-
Object
- Object
- Heidi::Project
- Defined in:
- lib/heidi/project.rb
Instance Attribute Summary collapse
-
#cached_root ⇒ Object
readonly
Returns the value of attribute cached_root.
-
#lock_file ⇒ Object
readonly
Returns the value of attribute lock_file.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #author(commit = self.commit) ⇒ Object
- #build_status ⇒ Object
- #build_status=(status) ⇒ Object
- #builds ⇒ Object
- #commit ⇒ Object
- #current_build ⇒ Object
- #date(commit = self.commit) ⇒ Object
- #fetch ⇒ Object
-
#initialize(root) ⇒ Project
constructor
A new instance of Project.
- #integrate(forced = false) ⇒ Object
- #integration_branch ⇒ Object
- #last_commit ⇒ Object
- #latest_build ⇒ Object
- #load_builds ⇒ Object
- #lock(&block) ⇒ Object
- #locked? ⇒ Boolean
- #log ⇒ Object
- #name ⇒ Object
- #name=(name) ⇒ Object
- #record_current_build ⇒ Object
- #record_last_commit ⇒ Object
- #record_latest_build ⇒ Object
- #unlock ⇒ Object
Constructor Details
Instance Attribute Details
#cached_root ⇒ Object (readonly)
Returns the value of attribute cached_root.
8 9 10 |
# File 'lib/heidi/project.rb', line 8 def cached_root @cached_root end |
#lock_file ⇒ Object (readonly)
Returns the value of attribute lock_file.
8 9 10 |
# File 'lib/heidi/project.rb', line 8 def lock_file @lock_file end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/heidi/project.rb', line 8 def root @root end |
Class Method Details
.find(commit) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/heidi/project.rb', line 28 def @builds.find(commit) return nil unless commit.is_a?(String) return nil unless commit.length >= 5 self.select do |build| build.commit == commit || build.commit =~ Regexp.new("^#{commit}") end.first end |
Instance Method Details
#author(commit = self.commit) ⇒ Object
53 54 55 |
# File 'lib/heidi/project.rb', line 53 def (commit=self.commit) @git.log(1, "%cN <%cE>", commit) end |
#build_status ⇒ Object
82 83 84 |
# File 'lib/heidi/project.rb', line 82 def build_status @git["build.status"] end |
#build_status=(status) ⇒ Object
85 86 87 |
# File 'lib/heidi/project.rb', line 85 def build_status=(status) @git["build.status"] = status end |
#builds ⇒ Object
17 18 19 |
# File 'lib/heidi/project.rb', line 17 def builds @builds || load_builds end |
#commit ⇒ Object
49 50 51 |
# File 'lib/heidi/project.rb', line 49 def commit @git.commit[0..8] end |
#current_build ⇒ Object
75 76 77 |
# File 'lib/heidi/project.rb', line 75 def current_build @git["build.current"] end |
#date(commit = self.commit) ⇒ Object
57 58 59 |
# File 'lib/heidi/project.rb', line 57 def date(commit=self.commit) @git.log(1, "%ci", commit) end |
#fetch ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/heidi/project.rb', line 115 def fetch if integration_branch && @git.branch != integration_branch if @git.branches.include? integration_branch @git.switch(integration_branch) @git.merge "origin/#{integration_branch}" else @git.checkout(integration_branch, "origin/#{integration_branch}") end end @git.pull # when the head has changed, update some stuff if last_commit != self.commit record_last_commit end end |
#integrate(forced = false) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/heidi/project.rb', line 94 def integrate(forced=false) return true if !forced && self.current_build == self.commit return "locked" if locked? status = "unknown" self.lock do record_current_build res = Heidi::Integrator.new(self).integrate if res == true status = nil elsif res.is_a? String status = res else status = "failed" end end return status end |
#integration_branch ⇒ Object
89 90 91 92 |
# File 'lib/heidi/project.rb', line 89 def integration_branch name = @git["build.branch"] name == "" ? nil : name end |
#last_commit ⇒ Object
61 62 63 |
# File 'lib/heidi/project.rb', line 61 def last_commit @git["commit"] end |
#latest_build ⇒ Object
68 69 70 |
# File 'lib/heidi/project.rb', line 68 def latest_build @git["build.latest"] end |
#load_builds ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/heidi/project.rb', line 21 def load_builds @builds = [] Dir[File.join(root, "logs", "*")].each do |build| next unless File.directory? build @builds << Heidi::Build.new(self, File.basename(build)) end def @builds.find(commit) return nil unless commit.is_a?(String) return nil unless commit.length >= 5 self.select do |build| build.commit == commit || build.commit =~ Regexp.new("^#{commit}") end.first end return @builds end |
#lock(&block) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/heidi/project.rb', line 135 def lock(&block) File.open(lock_file, File::TRUNC|File::CREAT|File::WRONLY) do |f| f.puts Time.now.strftime("%c") end if block_given? yield self.unlock end end |
#locked? ⇒ Boolean
163 164 165 |
# File 'lib/heidi/project.rb', line 163 def locked? File.exists? lock_file end |
#log ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/heidi/project.rb', line 146 def log log = @git.graph(120) lines = [] log.out.lines.each do |line| color_less = line.gsub(/\e\[[^m]+m/, '') commit = color_less.scan(/^[\| \*]+ ([a-z0-9]+)/).flatten.first lines << { :line => line, :build => builds.find(commit) } end return lines end |
#name ⇒ Object
45 46 47 |
# File 'lib/heidi/project.rb', line 45 def name @name ||= @git[:name] end |
#name=(name) ⇒ Object
40 41 42 43 |
# File 'lib/heidi/project.rb', line 40 def name=(name) @name = name @git["name"] = name end |
#record_current_build ⇒ Object
78 79 80 |
# File 'lib/heidi/project.rb', line 78 def record_current_build @git["build.current"] = self.commit end |
#record_last_commit ⇒ Object
64 65 66 |
# File 'lib/heidi/project.rb', line 64 def record_last_commit @git["commit"] = self.commit end |
#record_latest_build ⇒ Object
71 72 73 |
# File 'lib/heidi/project.rb', line 71 def record_latest_build @git["build.latest"] = self.commit end |
#unlock ⇒ Object
159 160 161 |
# File 'lib/heidi/project.rb', line 159 def unlock File.unlink lock_file end |