From 317a7469545d0e9a70e54a87a540b8aabe4c418b Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 5 Oct 2015 12:02:26 +0200 Subject: Make commit_spec run --- app/models/ci/build.rb | 4 ++- app/models/ci/commit.rb | 75 +++++++++++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 31 deletions(-) (limited to 'app/models') diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index bfdc1c7486e..79f040b8954 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -80,6 +80,8 @@ module Ci def retry(build) new_build = Ci::Build.new(status: :pending) + new_build.ref = build.ref + new_build.tag = build.tag new_build.options = build.options new_build.commands = build.commands new_build.tag_list = build.tag_list @@ -141,7 +143,7 @@ module Ci state :canceled, value: 'canceled' end - delegate :sha, :short_sha, :before_sha, :ref, :project, + delegate :sha, :short_sha, :project, to: :commit, prefix: false def trace_html diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index 3c577e3f081..59d4932d434 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -58,14 +58,6 @@ module Ci end end - def new_branch? - before_sha == Ci::Git::BLANK_SHA - end - - def compare? - !new_branch? - end - def git_author_name commit_data.author_name if commit_data end @@ -78,10 +70,6 @@ module Ci commit_data.message if commit_data end - def short_before_sha - Ci::Commit.truncate_sha(before_sha) - end - def short_sha Ci::Commit.truncate_sha(sha) end @@ -99,7 +87,22 @@ module Ci def create_builds(ref, tag, user, trigger_request = nil) return if skip_ci? && trigger_request.blank? return unless config_processor - CreateBuildsService.new.execute(self, config_processor, ref, tag, user, trigger_request) + config_processor.stages.any? do |stage| + CreateBuildsService.new.execute(self, stage, ref, tag, user, trigger_request).present? + end + end + + def create_next_builds(ref, tag, user, trigger_request) + return if skip_ci? && trigger_request.blank? + return unless config_processor + + stages = builds.where(ref: ref, tag: tag, trigger_request: trigger_request).group_by(&:stage) + + config_processor.stages.any? do |stage| + unless stages.include?(stage) + CreateBuildsService.new.execute(self, stage, ref, tag, user, trigger_request).present? + end + end end def refs @@ -111,7 +114,14 @@ module Ci end def builds_without_retry - builds.latest + @builds_without_retry ||= + begin + grouped_builds = builds.group_by(&:name) + latest_builds = grouped_builds.map do |name, builds| + builds.sort_by(&:id).last + end + latest_builds.sort_by(&:stage_idx) + end end def retried_builds @@ -125,32 +135,35 @@ module Ci return 'failed' elsif builds.none? return 'skipped' - end - - statuses = builds_without_retry.ignore_failures.pluck(:status) - if statuses.all? { |status| status == 'success' } - return 'success' - elsif statuses.all? { |status| status == 'pending' } - return 'pending' - elsif statuses.include?('running') || statuses.include?('pending') - return 'running' - elsif statuses.all? { |status| status == 'canceled' } - return 'canceled' + elsif success? + 'success' + elsif pending? + 'pending' + elsif running? + 'running' + elsif canceled? + 'canceled' else - return 'failed' + 'failed' end end def pending? - status == 'pending' + builds_without_retry.all? do |build| + build.pending? + end end def running? - status == 'running' + builds_without_retry.any? do |build| + build.running? || build.pending? + end end def success? - status == 'success' + builds_without_retry.all? do |build| + build.success? || build.ignored? + end end def failed? @@ -158,7 +171,9 @@ module Ci end def canceled? - status == 'canceled' + builds_without_retry.all? do |build| + build.canceled? + end end def duration -- cgit v1.2.3