Skip to content

Commit

Permalink
Enable triggered builds for non-master convergence branches.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shenil committed Sep 29, 2015
1 parent 91df595 commit 3e497b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 6 additions & 8 deletions app/controllers/pull_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ def build
def handle_repo_push_request
return unless @repository

if payload["ref"] == "refs/heads/master"
branch = @repository.branches.where(name: 'master').first

if branch.present? && @repository.run_ci?
sha = payload["after"]
branch.kickoff_new_build_unless_currently_busy(sha)
end
branch_name = payload["ref"].sub(%r{\Arefs/heads/}, '')
branch = @repository.branches.where(name: branch_name).first
if branch.present? && branch.convergence? && @repository.run_ci?
sha = payload["after"]
branch.kickoff_new_build_unless_currently_busy(sha)
end
end

Expand All @@ -42,7 +40,7 @@ def handle_pull_request

if active_pull_request? && @repository.build_pull_requests
sha = payload["pull_request"]["head"]["sha"]
branch_name = payload["pull_request"]["head"]["ref"].gsub(%r{^refs/heads/}, '')
branch_name = payload["pull_request"]["head"]["ref"].sub(%r{\Arefs/heads/}, '')
branch = @repository.branches.where(name: branch_name).first_or_create!

build = @repository.ensure_build_exists(sha, branch)
Expand Down
10 changes: 9 additions & 1 deletion spec/controllers/pull_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
context "for push events" do
let(:repository_fields) { { run_ci: true } }
let!(:master_branch) { FactoryGirl.create(:master_branch, repository: repository) }
let!(:convergence_branch) { FactoryGirl.create(:branch, repository: repository, convergence: true, name: "convergence_branch") }

it "creates a build" do
expect(Build.where(branch_id: master_branch.id, ref: to_40('2'))).to_not exist
Expand All @@ -36,7 +37,7 @@
expect(Build.where(branch_id: master_branch.id, ref: to_40('2'))).to exist
end

it "does not create a build for pushes to branches other than master" do # eventually this should be changed to non-convergence
it "does not create a build for pushes to non-convergence branches" do
expect {
post :build, 'payload' => push_payload("ref" => "refs/heads/some-branch")
expect(response).to be_success
Expand All @@ -62,6 +63,13 @@
}.to_not change(Build, :count)
end

it "builds for convergence branches" do
expect {
post :build, 'payload' => push_payload("ref" => "refs/heads/convergence_branch")
expect(response).to be_success
}.to change(Build, :count).by(1)
end

it "builds if there is completed ci build" do
master_branch.builds.create!(:ref => to_40('w'), :state => :succeeded)
expect {
Expand Down

0 comments on commit 3e497b2

Please sign in to comment.