lib/perkins/build_report.rb in perkins-0.0.3 vs lib/perkins/build_report.rb in perkins-0.0.5

- old
+ new

@@ -1,36 +1,48 @@ module Perkins class BuildReport < ActiveRecord::Base belongs_to :repo - def commit - self.repo.load_git - @commit ||= Perkins::Commit.new(self.sha, self.repo) + after_create :enqueue + + serialize :commit + + def enqueue + BuildWorker.perform_async(self.id, sha, branch ) end + #def formatted_commit + #self.repo.load_git + # self.commit ||= $github_client.commits(repo.name, sha) + # Perkins::Commit.new(self.commit) + #end + + def retrieve_commit_info + hsh = $github_client.commits(repo.name, sha).first.to_attrs + self.commit = hsh + self.save + end + def send_github_status(sha) self.repo.git self.build_status_report(sha) end def as_json(options = {}) data = {} unless fields = options[:only] fields = [:id, :sha, :commit, :branch, :build_time, - :status, :duration, :build_time, :response] + :status, :duration, :build_time, :response, :build_status] end fields.each { |k| data[k] = send(k) } data end - - # Status report to GITHUB repo - def build_status_report(sha) $github_client.create_status( self.repo.name, sha, github_state, { context: "Perkins CI", @@ -49,9 +61,17 @@ d = self.status ? "passed" : "fail" end def github_state_url "#{Perkins::Application.instance.sse_endpoint}/repos/#{repo.name}/builds/#{self.id}" + end + + def start! + update_attribute(:build_status, "started") + end + + def stop! + update_attribute(:build_status, "stopped") end end end \ No newline at end of file