BigW Consortium Gitlab

Commit c6bce7e6 by Kamil Trzcinski Committed by Grzegorz Bizon

Save Ci::Commit object to persist all created builds

parent 07af37a2
......@@ -66,7 +66,10 @@ module Ci
# We use around_transition to create builds for next stage as soon as possible, before the `after_*` is executed
around_transition any => [:success, :failed, :canceled] do |build, block|
block.call
build.commit.create_next_builds(build) if build.commit
if build.commit
build.commit.create_next_builds(build)
build.commit.save
end
end
after_transition any => [:success, :failed, :canceled] do |build|
......
......@@ -13,7 +13,7 @@ module Ci
validate :valid_commit_sha
# Invalidate object and save if when touched
after_touch :update_state!
after_touch :update_state
def self.truncate_sha(sha)
sha[0...8]
......@@ -159,7 +159,9 @@ module Ci
git_commit_message =~ /(\[ci skip\])/ if git_commit_message
end
def update_state!
private
def update_state
statuses.reload
self.status = if yaml_errors.blank?
statuses.latest.status || 'skipped'
......
......@@ -31,7 +31,7 @@ module Ci
pipeline.errors.add(:base, 'No builds for this pipeline.')
end
pipeline.update_state!
pipeline.save
pipeline
end
......
......@@ -15,6 +15,7 @@ module Ci
)
if ci_commit.create_builds(nil, trigger_request)
ci_commit.save
trigger_request
end
end
......
......@@ -55,11 +55,15 @@ describe Ci::Commit, models: true do
let!(:commit) { FactoryGirl.create :ci_commit, project: project, ref: 'master', tag: false }
def create_builds(trigger_request = nil)
commit.create_builds(nil, trigger_request)
if commit.create_builds(nil, trigger_request)
commit.save
end
end
def create_next_builds
commit.create_next_builds(commit.builds.order(:id).last)
if commit.create_next_builds(commit.builds.order(:id).last)
commit.save
end
end
it 'creates builds' do
......
......@@ -22,6 +22,7 @@ describe Ci::API::API do
it "should start a build" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil)
commit.save
build = commit.builds.first
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......@@ -58,6 +59,7 @@ describe Ci::API::API do
it "returns options" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil)
commit.save
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......@@ -68,6 +70,7 @@ describe Ci::API::API do
it "returns variables" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil)
commit.save
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......@@ -87,6 +90,7 @@ describe Ci::API::API do
trigger_request = FactoryGirl.create(:ci_trigger_request_with_variables, commit: commit, trigger: trigger)
commit.create_builds(nil, trigger_request)
commit.save
project.variables << Ci::Variable.new(key: "SECRET_KEY", value: "secret_value")
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......@@ -105,6 +109,7 @@ describe Ci::API::API do
it "returns dependent builds" do
commit = FactoryGirl.create(:ci_commit, project: project, ref: 'master')
commit.create_builds(nil, nil)
commit.save
commit.builds.where(stage: 'test').each(&:success)
post ci_api("/builds/register"), token: runner.token, info: { platform: :darwin }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment