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
- #build_status ⇒ Object
- #build_status=(status) ⇒ Object
- #builds ⇒ Object
- #commit ⇒ Object
- #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_branch ⇒ Object
- #integration_branch=(name) ⇒ Object
- #integration_branches ⇒ 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
- #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
57 58 59 |
# File 'lib/heidi/project.rb', line 57 def (commit=self.commit) @git.log(1, "%cN <%cE>", commit) end |
#basename ⇒ Object
49 50 51 |
# File 'lib/heidi/project.rb', line 49 def basename File.basename(@root) end |
#build_status ⇒ Object
86 87 88 |
# File 'lib/heidi/project.rb', line 86 def build_status @git["build.status"] end |
#build_status=(status) ⇒ Object
89 90 91 |
# File 'lib/heidi/project.rb', line 89 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
53 54 55 |
# File 'lib/heidi/project.rb', line 53 def commit @git.commit[0..8] end |
#current_build ⇒ Object
79 80 81 |
# File 'lib/heidi/project.rb', line 79 def current_build @git["build.current"] end |
#date(commit = self.commit) ⇒ Object
61 62 63 |
# File 'lib/heidi/project.rb', line 61 def date(commit=self.commit) @git.log(1, "%ci", commit) end |
#diff(commit) ⇒ Object
191 192 193 |
# File 'lib/heidi/project.rb', line 191 def diff(commit) @git.diff(commit) end |
#fetch ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/heidi/project.rb', line 127 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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/heidi/project.rb', line 106 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
93 94 95 96 |
# File 'lib/heidi/project.rb', line 93 def integration_branch name = @git["build.branch"] name == "" ? nil : name end |
#integration_branch=(name) ⇒ Object
97 98 99 100 |
# File 'lib/heidi/project.rb', line 97 def integration_branch=(name) name = name.split('/').last if name =~ /\// @git["build.branch"] = name end |
#integration_branches ⇒ Object
102 103 104 |
# File 'lib/heidi/project.rb', line 102 def integration_branches @git.remote_branches end |
#last_commit ⇒ Object
65 66 67 |
# File 'lib/heidi/project.rb', line 65 def last_commit @git["commit"] end |
#latest_build ⇒ Object
72 73 74 |
# File 'lib/heidi/project.rb', line 72 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
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/heidi/project.rb', line 147 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
199 200 201 |
# File 'lib/heidi/project.rb', line 199 def locked? File.exists? lock_file end |
#log ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/heidi/project.rb', line 158 def log log = @git.graph(120) 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 |
#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
82 83 84 |
# File 'lib/heidi/project.rb', line 82 def record_current_build @git["build.current"] = self.commit end |
#record_last_commit ⇒ Object
68 69 70 |
# File 'lib/heidi/project.rb', line 68 def record_last_commit @git["commit"] = self.commit end |
#record_latest_build ⇒ Object
75 76 77 |
# File 'lib/heidi/project.rb', line 75 def record_latest_build @git["build.latest"] = self.commit end |
#stat(commit) ⇒ Object
187 188 189 |
# File 'lib/heidi/project.rb', line 187 def stat(commit) @git.stat(commit) end |
#unlock ⇒ Object
195 196 197 |
# File 'lib/heidi/project.rb', line 195 def unlock File.unlink lock_file end |