diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-08-15 18:45:45 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-08-15 18:45:45 +0800 |
commit | b5d1e6341b67206de8b90ef693723434368363cf (patch) | |
tree | b04bf8a5d0d387de4b7f8d239f9c1aa521640cd9 /app/models/commit_status.rb | |
parent | 21fdc1edaecf228c1fdc540375bbdad0fd69164a (diff) | |
parent | a391652fe60930e2139ecfacb175da6aa0f3b1e9 (diff) | |
download | gitlab-ce-b5d1e6341b67206de8b90ef693723434368363cf.tar.gz |
Merge branch 'pipeline-hooks-without-slack' into wall-clock-time-for-showing-pipeline
* pipeline-hooks-without-slack: (156 commits)
Fix test failures
Make pipeline to be in created state for hooks tests
Make `execute_methods` public
Added specs for started_at and finished_at
Use explicit events to transition between states
Fix tests. We cannot reload unless it's already saved:
Have trait all_events_enabled so that's easier to reuse, feedback:
Simplify the name for data builder, feedback:
Prefer extend self over module_function, feedback:
Make it more grammatically correct, feedback:
if -> when; when -> `when`; %w() -> %w[]; and fix some typos:
Prefer described_class, feedback:
Make the comment more clear, feedback:
Update CHANGELOG
render only commit title
Fix test failures, that did occur because of missing previously used `reload_status!` call
Use state machine for pipeline event processing
Upgrade Rails to 4.2.7.1 for security fixes.
Update gitlab-shell to v3.3.3
Verify the pipeline status after executing events on builds
...
Diffstat (limited to 'app/models/commit_status.rb')
-rw-r--r-- | app/models/commit_status.rb | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 5d0a28ecfcc..ac589fa2e31 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -5,7 +5,7 @@ class CommitStatus < ActiveRecord::Base self.table_name = 'ci_builds' belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id - belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id, touch: true + belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :commit_id belongs_to :user delegate :commit, to: :pipeline @@ -26,28 +26,36 @@ class CommitStatus < ActiveRecord::Base scope :ordered, -> { order(:name) } scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) } - state_machine :status, initial: :pending do + state_machine :status do event :queue do - transition skipped: :pending + transition [:created, :skipped] => :pending end event :run do transition pending: :running end + event :skip do + transition [:created, :pending] => :skipped + end + event :drop do - transition [:pending, :running] => :failed + transition [:created, :pending, :running] => :failed end event :success do - transition [:pending, :running] => :success + transition [:created, :pending, :running] => :success end event :cancel do - transition [:pending, :running] => :canceled + transition [:created, :pending, :running] => :canceled end - after_transition pending: :running do |commit_status| + after_transition created: [:pending, :running] do |commit_status| + commit_status.update_attributes queued_at: Time.now + end + + after_transition [:created, :pending] => :running do |commit_status| commit_status.update_attributes started_at: Time.now end @@ -55,7 +63,18 @@ class CommitStatus < ActiveRecord::Base commit_status.update_attributes finished_at: Time.now end - after_transition [:pending, :running] => :success do |commit_status| + # We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed + around_transition any => [:success, :failed, :canceled] do |commit_status, block| + block.call + + commit_status.pipeline.try(:process!) + end + + after_transition do |commit_status, transition| + commit_status.pipeline.try(:build_updated) unless transition.loopback? + end + + after_transition [:created, :pending, :running] => :success do |commit_status| MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status) end |