Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2 from square/jkingdon/rails4-readiness
Browse files Browse the repository at this point in the history
Get ready for rails4.
  • Loading branch information
jkingdon committed Sep 10, 2013
2 parents e17d18c + 0ef24ef commit c270257
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/builds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def make_build
elsif params['build']
@project = Project.where(:name => params[:project_id]).first
unless @project
repository = Repository.find_or_create_by_url(params[:repo_url])
repository = Repository.where(url: params[:repo_url]).first_or_create
@project = repository.projects.create!(:name => params[:project_id])
end
project_build(params[:build][:branch], params[:build][:ref])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/pull_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def handle_repo_push_request
end
repository = Repository.find_by_url(ssh_url)
return unless repository
project = repository.projects.find_or_create_by_name(repository.repository_name)
project = repository.projects.where(name: repository.repository_name).first_or_create
if payload["ref"] == "refs/heads/master" && repository.run_ci?
sha = payload["after"]
project.builds.create_new_build_for(sha)
Expand All @@ -28,7 +28,7 @@ def handle_repo_push_request

def handle_pull_request
repository = Repository.find_by_url(payload['repository']['ssh_url'])
project = repository.projects.find_or_create_by_name(repository.repository_name + "-pull_requests")
project = repository.projects.where(name: repository.repository_name + "-pull_requests").first_or_create
if active_pull_request? && (build_requested_for_pull_request? || repository.build_pull_requests)
sha = payload["pull_request"]["head"]["sha"]
branch = payload["pull_request"]["head"]["ref"]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class RepositoriesController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:build_ref]

def create
repository = Repository.find_or_initialize_by_url(params[:repository][:url])
repository = Repository.where(url: params[:repository][:url]).first_or_initialize
repository.update_attributes!(params[:repository])
repository.projects.find_or_create_by_name("#{repository.repository_name}-pull_requests")
project = repository.projects.find_or_create_by_name(repository.repository_name)
Expand Down Expand Up @@ -46,7 +46,7 @@ def build_ref
project_name = repository.repository_name
project_name += '-pull_requests' unless ref == 'master'

project = repository.projects.find_or_create_by_name(project_name)
project = repository.projects.where(name: project_name).first_or_create

build = if ref == 'master'
project.ensure_master_build_exists(sha)
Expand Down
15 changes: 8 additions & 7 deletions app/models/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def errored

after_create :enqueue_partitioning_job

scope :completed, {:conditions => {:state => TERMINAL_STATES}}
scope :completed, -> { where(state: TERMINAL_STATES) }
scope :successful_for_project, lambda { |project_id| where(:project_id => project_id, :state => :succeeded) }

def test_command(run_list)
Expand Down Expand Up @@ -138,7 +138,9 @@ def auto_merge!

def promote!
BuildStrategy.promote_build(ref, repository)
if repository.has_on_success_script? && !promoted? && Build.update_all({:promoted => true}, {:id => self.id, :promoted => nil}) == 1
if repository.has_on_success_script? &&
!promoted? &&
Build.where(id: self.id, promoted: nil).update_all(promoted: true) == 1
output = BuildStrategy.run_success_script(repository, ref, branch)
script_log = FilelessIO.new(output)
script_log.original_filename = "on_success_script.log"
Expand All @@ -159,10 +161,9 @@ def abort!
update_attributes!(:state => :aborted)

all_build_part_ids = build_parts.select('id').collect(&:id)
BuildAttempt.update_all(
{:state => :aborted, :updated_at => Time.now},
{:state => :runnable, :build_part_id => all_build_part_ids}
)
BuildAttempt.
where(state: :runnable, build_part_id: all_build_part_ids).
update_all(state: :aborted, updated_at: Time.now)
end

def to_color
Expand Down Expand Up @@ -195,7 +196,7 @@ def send_build_status_email!
return if (project.main? && !previous_successful_build) || !repository.send_build_failure_email?

if completed? && failed? && !build_failure_email_sent?
if Build.update_all({:build_failure_email_sent => true}, {:id => self.id, :build_failure_email_sent => nil}) == 1
if Build.where(id: self.id, build_failure_email_sent: nil).update_all(build_failure_email_sent: true) == 1
BuildMailer.build_break_email(self).deliver
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/build_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class BuildArtifact < ActiveRecord::Base
mount_uploader :log_file, LogFileUploader
validates_presence_of :log_file

scope :stdout_log, where(:log_file => ['stdout.log.gz', 'stdout.log'])
scope :junit_log, where(:log_file => 'rspec.xml.log.gz')
scope :error_txt, where(:log_file => 'error.txt')
scope :stdout_log, -> { where(:log_file => ['stdout.log.gz', 'stdout.log']) }
scope :junit_log, -> { where(:log_file => 'rspec.xml.log.gz') }
scope :error_txt, -> { where(:log_file => 'error.txt') }
end
2 changes: 1 addition & 1 deletion app/models/build_attempt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BuildAttempt < ActiveRecord::Base

symbolize :state, :in => STATES, :scopes => true

scope :unsuccessful, :conditions => {:state => FAILED_BUILD_STATES}
scope :unsuccessful, -> { where(state: FAILED_BUILD_STATES) }

def elapsed_time
if finished_at && started_at
Expand Down
4 changes: 2 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Project < ActiveRecord::Base
has_many :builds, :dependent => :destroy, :inverse_of => :project do
def create_new_build_for(sha)
last_build = all.last
last_build = last
return last_build if last_build && !last_build.completed?
build = find_or_initialize_by_ref(sha, :state => :partitioning, :branch => 'master')
build = where(ref: sha).first_or_initialize(state: :partitioning, branch: 'master')
build.save!
build
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/repositories/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
= f.submit @repository.new_record? ? "Create" : "Update"

- unless @repository.new_record?
= button_to "Delete", @repository, :method => :delete, :form_class => "delete-form", :class => "danger-button", :confirm => "This is a permanent destructive action, are you sure?"
= button_to "Delete", @repository, method: :delete, form_class: "delete-form", class: "danger-button", data: {confirm: "This is a permanent destructive action, are you sure?"}
3 changes: 0 additions & 3 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand Down
3 changes: 0 additions & 3 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end
end
end
match '/XmlStatusReport.aspx', :to => "projects#status_report", :defaults => { :format => 'xml' }
match '/XmlStatusReport.aspx', to: "projects#status_report", defaults: {:format => 'xml'}, via: :get

match '/build_attempts/:build_attempt_id/build_artifacts' => "build_artifacts#create", :via => :post
match '/build_attempts/:id/start' => "build_attempts#start", :via => :post
Expand Down

0 comments on commit c270257

Please sign in to comment.