From 52e2729bf44ff3376071c2462679b46e9f67a44e Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 20 Oct 2016 13:14:23 +0200 Subject: add pipeline id to merge request metrics table. Also, updated the pipeline worker to populate this field. --- app/models/merge_request.rb | 2 +- app/models/merge_request/metrics.rb | 1 + app/workers/pipeline_metrics_worker.rb | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index d76feb9680e..a3eb815dd34 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -232,7 +232,7 @@ class MergeRequest < ActiveRecord::Base end def diff_head_commit - if persisted? + if persisted?diff_head_commit merge_request_diff.head_commit else source_branch_head diff --git a/app/models/merge_request/metrics.rb b/app/models/merge_request/metrics.rb index 99c49a020c9..7d19943769e 100644 --- a/app/models/merge_request/metrics.rb +++ b/app/models/merge_request/metrics.rb @@ -1,5 +1,6 @@ class MergeRequest::Metrics < ActiveRecord::Base belongs_to :merge_request + belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :ci_commit_id def record! if merge_request.merged? && self.merged_at.blank? diff --git a/app/workers/pipeline_metrics_worker.rb b/app/workers/pipeline_metrics_worker.rb index 34f6ef161fb..cca39761d8f 100644 --- a/app/workers/pipeline_metrics_worker.rb +++ b/app/workers/pipeline_metrics_worker.rb @@ -12,11 +12,11 @@ class PipelineMetricsWorker private def update_metrics_for_active_pipeline(pipeline) - metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil) + metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil, ci_commit_id: pipeline.id) end def update_metrics_for_succeeded_pipeline(pipeline) - metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at) + metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, ci_commit_id: pipeline.id) end def metrics(pipeline) -- cgit v1.2.1