Class: VetCI::Project
- Inherits:
-
Object
- Object
- VetCI::Project
- Defined in:
- lib/vet-ci/project.rb
Instance Attribute Summary collapse
-
#autoupdate ⇒ Object
Returns the value of attribute autoupdate.
-
#build_command ⇒ Object
Returns the value of attribute build_command.
-
#building ⇒ Object
Returns the value of attribute building.
-
#default_branch ⇒ Object
Returns the value of attribute default_branch.
-
#name ⇒ Object
Returns the value of attribute name.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Class Method Summary collapse
- .datastore ⇒ Object
- .datastore=(value) ⇒ Object
-
.named(value) ⇒ Object
Returns a project in the list that is named ..
- .parse_vetfile_contents(parameters) ⇒ Object
-
.projects ⇒ Object
This shouldn’t be here, but it was easy.
- .projects=(value) ⇒ Object
Instance Method Summary collapse
- #build(faye = nil, payload = nil) ⇒ Object
- #build!(faye = nil, payload = nil) ⇒ Object
- #builds ⇒ Object
- #builds=(value) ⇒ Object
- #git_update ⇒ Object
-
#initialize(attributes = {}) ⇒ Project
constructor
A new instance of Project.
- #insertBuild(build) ⇒ Object
- #is_building? ⇒ Boolean
- #last_build_status ⇒ Object
- #pagedBuilds(page = 1, limit = 10) ⇒ Object
- #repo ⇒ Object
- #save! ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Project
Returns a new instance of Project.
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/vet-ci/project.rb', line 98 def initialize(attributes = {}) attributes.each do |key, value| self.send("#{key}=", value) end # Now, let's load any existing builds in the list from the datastore unless Project.datastore.nil? Project.datastore.transaction(true) do builds = Project.datastore[self.name] self.builds.concat(builds) unless builds.nil? end end end |
Instance Attribute Details
#autoupdate ⇒ Object
Returns the value of attribute autoupdate.
62 63 64 |
# File 'lib/vet-ci/project.rb', line 62 def autoupdate @autoupdate end |
#build_command ⇒ Object
Returns the value of attribute build_command.
60 61 62 |
# File 'lib/vet-ci/project.rb', line 60 def build_command @build_command end |
#building ⇒ Object
Returns the value of attribute building.
63 64 65 |
# File 'lib/vet-ci/project.rb', line 63 def building @building end |
#default_branch ⇒ Object
Returns the value of attribute default_branch.
61 62 63 |
# File 'lib/vet-ci/project.rb', line 61 def default_branch @default_branch end |
#name ⇒ Object
Returns the value of attribute name.
58 59 60 |
# File 'lib/vet-ci/project.rb', line 58 def name @name end |
#project_path ⇒ Object
Returns the value of attribute project_path.
59 60 61 |
# File 'lib/vet-ci/project.rb', line 59 def project_path @project_path end |
Class Method Details
.datastore ⇒ Object
24 25 26 |
# File 'lib/vet-ci/project.rb', line 24 def datastore @datastore end |
.datastore=(value) ⇒ Object
28 29 30 |
# File 'lib/vet-ci/project.rb', line 28 def datastore=(value) @datastore = value end |
.named(value) ⇒ Object
Returns a project in the list that is named ..
33 34 35 |
# File 'lib/vet-ci/project.rb', line 33 def named(value) self.projects[value] end |
.parse_vetfile_contents(parameters) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vet-ci/project.rb', line 37 def parse_vetfile_contents(parameters) parameters.each do |project| name = project['name'] path = project['path'] command = project['command'] default_branch = project['default_branch'] autoupdate = (project['autoupdate'].nil? ? false : project['autoupdate']) if path.nil? path = Dir.pwd else path = File. path end project = Project.new(:name => name, :project_path => path, :build_command => command, :default_branch => default_branch, :autoupdate => autoupdate) self.projects[project.name] = project end end |
.projects ⇒ Object
This shouldn’t be here, but it was easy. We’ll refactor it when that time comes…
16 17 18 |
# File 'lib/vet-ci/project.rb', line 16 def projects @projects ||= {} end |
.projects=(value) ⇒ Object
20 21 22 |
# File 'lib/vet-ci/project.rb', line 20 def projects=(value) @projects = value end |
Instance Method Details
#build(faye = nil, payload = nil) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/vet-ci/project.rb', line 143 def build(faye=nil, payload=nil) if is_building? return end if payload begin payload = JSON.parse payload rescue payload = nil end end Thread.new {build!(faye, payload)} end |
#build!(faye = nil, payload = nil) ⇒ Object
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 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/vet-ci/project.rb', line 159 def build!(faye=nil, payload=nil) self.building = true unless faye.nil? faye.publish '/all', :project => self.name, :status => 'running' end # First, let's reset the repo if we said we should in the Vetfile if self.autoupdate == true puts "Updating the repo" self.git_update end @result = '' repo = Grit::Repo.new @project_path commit = repo.commits.first Util.open_pipe("cd #{@project_path} && #{@build_command} 2>&1") do |pipe, process_id| puts "#{Time.now.to_i}: Building with command '#{@build_command}'..." @current_pid = process_id @result = pipe.read end Process.waitpid(@current_pid) puts $?.exitstatus.to_i if commit.nil? current_build = Build.new(:project => self, :status => $?.exitstatus.to_i, :output => @result, :date => Time.now, :payload => payload) else current_build = Build.new(:project => self, :status => $?.exitstatus.to_i, :output => @result, :date => Time.now, :commit => commit.id, :committer => commit.committer.name, :payload => payload) end puts "Saving build..." unless faye.nil? faye.publish '/all', :project => self.name, :status => current_build.status_class, :last_build => current_build.dashboard_time end self.insertBuild current_build self.building = false self.save! end |
#builds ⇒ Object
66 67 68 |
# File 'lib/vet-ci/project.rb', line 66 def builds @builds ||= [] end |
#builds=(value) ⇒ Object
81 82 83 |
# File 'lib/vet-ci/project.rb', line 81 def builds=(value) @builds = value end |
#git_update ⇒ Object
120 121 122 123 |
# File 'lib/vet-ci/project.rb', line 120 def git_update reset_branch = self.default_branch.nil? ? "" : " origin/#{self.default_branch}" `cd #{self.project_path} && git fetch origin && git reset --hard#{reset_branch}` end |
#insertBuild(build) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vet-ci/project.rb', line 85 def insertBuild(build) self.builds << build @builds.sort! do |a, b| if a.date == b.date 0 elsif a.date < b.date 1 else -1 end end end |
#is_building? ⇒ Boolean
129 130 131 |
# File 'lib/vet-ci/project.rb', line 129 def is_building? self.building == true end |
#last_build_status ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/vet-ci/project.rb', line 133 def last_build_status if is_building? return 'running' elsif self.builds.count > 0 return self.builds.first.status_class else return '' end end |
#pagedBuilds(page = 1, limit = 10) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vet-ci/project.rb', line 70 def pagedBuilds(page=1, limit=10) # We need to calculate the slice page = page.nil? ? 1 : page.to_i limit = limit.nil? ? 10 : limit.to_i page = 1 if page < 0 start = (page-1) * limit # limit is the length result = self.builds[start,limit] result.nil? ? [] : result end |
#repo ⇒ Object
125 126 127 |
# File 'lib/vet-ci/project.rb', line 125 def repo Grit::Repo.new(self.project_path) end |