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
- #basename ⇒ Object
- #branch ⇒ Object
- #branch=(name) ⇒ Object
- #build_status ⇒ Object
- #build_status=(status) ⇒ Object
- #builds ⇒ Object
- #commit ⇒ Object (also: #HEAD)
- #current_build ⇒ Object
- #date(commit = self.commit) ⇒ Object
- #diff(commit) ⇒ Object
- #fetch ⇒ Object
-
#initialize(root) ⇒ Project
constructor
A new instance of Project.
- #integrate(forced = false) ⇒ Object
- #integration_branches ⇒ Object
- #last_commit ⇒ Object
- #latest_build ⇒ Object
- #load_builds ⇒ Object
- #lock(&block) ⇒ Object
- #locked? ⇒ Boolean
- #log(length = 60) ⇒ Object
- #message(commit = self.commit) ⇒ Object
- #name ⇒ Object
- #name=(name) ⇒ Object
- #record_current_build ⇒ Object
- #record_last_commit ⇒ Object
- #record_latest_build ⇒ Object
- #stat(commit) ⇒ 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
59 60 61 |
# File 'lib/heidi/project.rb', line 59 def (commit=self.commit) @git.log(1, "%cN <%cE>", commit) end |
#basename ⇒ Object
50 51 52 |
# File 'lib/heidi/project.rb', line 50 def basename File.basename(@root) end |
#branch ⇒ Object
99 100 101 102 |
# File 'lib/heidi/project.rb', line 99 def branch name = @git["build.branch"] name == "" ? nil : name end |
#branch=(name) ⇒ Object
103 104 105 106 |
# File 'lib/heidi/project.rb', line 103 def branch=(name) name.gsub!("origin/", "") @git["build.branch"] = name end |
#build_status ⇒ Object
92 93 94 |
# File 'lib/heidi/project.rb', line 92 def build_status @git["build.status"] || "unknown" end |
#build_status=(status) ⇒ Object
95 96 97 |
# File 'lib/heidi/project.rb', line 95 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 Also known as: HEAD
54 55 56 |
# File 'lib/heidi/project.rb', line 54 def commit @git.commit[0..7] end |
#current_build ⇒ Object
85 86 87 |
# File 'lib/heidi/project.rb', line 85 def current_build @git["build.current"] end |
#date(commit = self.commit) ⇒ Object
63 64 65 |
# File 'lib/heidi/project.rb', line 63 def date(commit=self.commit) @git.log(1, "%ci", commit) end |
#diff(commit) ⇒ Object
204 205 206 |
# File 'lib/heidi/project.rb', line 204 def diff(commit) @git.diff(commit) end |
#fetch ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/heidi/project.rb', line 136 def fetch return if locked? self.lock do if branch && @git.branch != branch if @git.branches.include? branch @git.switch(branch) @git.merge "origin/#{branch}" else @git.checkout(branch, "origin/#{branch}") end end @git.pull # when the head has changed, update some stuff if last_commit != self.commit record_last_commit end end end |
#integrate(forced = false) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/heidi/project.rb', line 112 def integrate(forced=false) must_build = !(self.current_build == self.commit) must_build = build_status != "passed" return true if !forced && !must_build return "locked" if locked? status = Heidi::DNF 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 = Heidi::FAILED end end return status end |
#integration_branches ⇒ Object
108 109 110 |
# File 'lib/heidi/project.rb', line 108 def integration_branches @git.remote_branches end |
#last_commit ⇒ Object
71 72 73 |
# File 'lib/heidi/project.rb', line 71 def last_commit @git["commit"] end |
#latest_build ⇒ Object
78 79 80 |
# File 'lib/heidi/project.rb', line 78 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.sort_by(&:time) end |
#lock(&block) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/heidi/project.rb', line 160 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
212 213 214 |
# File 'lib/heidi/project.rb', line 212 def locked? File.exists? lock_file end |
#log(length = 60) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/heidi/project.rb', line 171 def log(length=60) log = @git.graph(length) lines = [] log.out.lines.each do |line| commit = nil = nil graph = nil if line =~ /\*/ color_less = line.gsub(/\e\[[^m]*m?/, '') commit = color_less.scan(/^[^a-z0-9]+([a-z0-9]+)/).flatten.first (graph, ) = line.chomp.split(commit) else graph = line.chomp end lines << { :line => line, :commit => commit, :build => builds.find(commit), :graph => graph, :message => , } end return lines end |
#message(commit = self.commit) ⇒ Object
67 68 69 |
# File 'lib/heidi/project.rb', line 67 def (commit=self.commit) @git.log(1, "%B", commit) end |
#name ⇒ Object
44 45 46 47 48 |
# File 'lib/heidi/project.rb', line 44 def name name ||= @git[:name] || basename name = basename if name.empty? name end |
#name=(name) ⇒ Object
40 41 42 |
# File 'lib/heidi/project.rb', line 40 def name=(name) @git["name"] = name end |
#record_current_build ⇒ Object
88 89 90 |
# File 'lib/heidi/project.rb', line 88 def record_current_build @git["build.current"] = self.commit end |
#record_last_commit ⇒ Object
74 75 76 |
# File 'lib/heidi/project.rb', line 74 def record_last_commit @git["commit"] = self.commit end |
#record_latest_build ⇒ Object
81 82 83 |
# File 'lib/heidi/project.rb', line 81 def record_latest_build @git["build.latest"] = self.commit end |
#stat(commit) ⇒ Object
200 201 202 |
# File 'lib/heidi/project.rb', line 200 def stat(commit) @git.stat(commit) end |
#unlock ⇒ Object
208 209 210 |
# File 'lib/heidi/project.rb', line 208 def unlock File.unlink lock_file end |