summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-11-15 15:22:35 +0100
committerJames Lopez <james@jameslopez.es>2016-11-17 08:22:58 +0100
commitca6da6ea3034a58c0edbc62336d2d49ea6e11fc9 (patch)
tree91e9bb0520f6310b210e26b70d88fc779fdbe4c7
parent73e9ec631995d5ed91a3eb5e8416c924e7d7c5ad (diff)
downloadgitlab-ce-ca6da6ea3034a58c0edbc62336d2d49ea6e11fc9.tar.gz
Renamed pipeline column and fixed permissions for builds in events controller
-rw-r--r--app/controllers/projects/cycle_analytics/events_controller.rb7
-rw-r--r--app/models/merge_request/metrics.rb2
-rw-r--r--app/workers/pipeline_metrics_worker.rb4
-rw-r--r--db/migrate/20161020083353_add_pipeline_id_to_merge_request_metrics.rb4
-rw-r--r--db/schema.rb6
-rw-r--r--lib/gitlab/cycle_analytics/events_fetcher.rb2
6 files changed, 14 insertions, 11 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb
index 77b49d6c4b9..cc75dc247d3 100644
--- a/app/controllers/projects/cycle_analytics/events_controller.rb
+++ b/app/controllers/projects/cycle_analytics/events_controller.rb
@@ -2,6 +2,7 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
include CycleAnalyticsParams
before_action :authorize_read_cycle_analytics!
+ before_action :authorize_read_builds!, only: [:test, :staging]
def issue
render_events(events.issue_events)
@@ -16,7 +17,7 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end
def test
- @opts = { from: start_date(events_params), branch: events_params[:branch_name] }
+ @options = { from: start_date(events_params), branch: events_params[:branch_name] }
render_events(events.test_events)
end
@@ -47,12 +48,12 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end
def options
- @opts ||= { from: start_date(events_params) }
+ @options ||= { from: start_date(events_params) }
end
def events_params
return {} unless params[:events].present?
- { start_date: params[:events][:start_date], branch_name: params[:events][:branch_name] }
+ params[:events].slice(:start_date, :branch_name)
end
end
diff --git a/app/models/merge_request/metrics.rb b/app/models/merge_request/metrics.rb
index 7d19943769e..cdc408738be 100644
--- a/app/models/merge_request/metrics.rb
+++ b/app/models/merge_request/metrics.rb
@@ -1,6 +1,6 @@
class MergeRequest::Metrics < ActiveRecord::Base
belongs_to :merge_request
- belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :ci_commit_id
+ belongs_to :pipeline, class_name: 'Ci::Pipeline', foreign_key: :pipeline_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 cca39761d8f..070943f1ecc 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, ci_commit_id: pipeline.id)
+ metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: nil, pipeline_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, ci_commit_id: pipeline.id)
+ metrics(pipeline).update_all(latest_build_started_at: pipeline.started_at, latest_build_finished_at: pipeline.finished_at, pipeline_id: pipeline.id)
end
def metrics(pipeline)
diff --git a/db/migrate/20161020083353_add_pipeline_id_to_merge_request_metrics.rb b/db/migrate/20161020083353_add_pipeline_id_to_merge_request_metrics.rb
index a47e1ae7f6a..507d576d0bc 100644
--- a/db/migrate/20161020083353_add_pipeline_id_to_merge_request_metrics.rb
+++ b/db/migrate/20161020083353_add_pipeline_id_to_merge_request_metrics.rb
@@ -24,6 +24,8 @@ class AddPipelineIdToMergeRequestMetrics < ActiveRecord::Migration
# disable_ddl_transaction!
def change
- add_reference :merge_request_metrics, :ci_commit, index: true, foreign_key: { on_delete: :cascade }
+ add_column :merge_request_metrics, :pipeline_id, :integer
+ add_index :merge_request_metrics, :pipeline_id
+ add_foreign_key :merge_request_metrics, :ci_commits, column: :pipeline_id, on_delete: :cascade
end
end
diff --git a/db/schema.rb b/db/schema.rb
index 5baa82e1058..983e1c90682 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -634,12 +634,12 @@ ActiveRecord::Schema.define(version: 20161109150329) do
t.datetime "merged_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.integer "ci_commit_id"
+ t.integer "pipeline_id"
end
- add_index "merge_request_metrics", ["ci_commit_id"], name: "index_merge_request_metrics_on_ci_commit_id", using: :btree
add_index "merge_request_metrics", ["first_deployed_to_production_at"], name: "index_merge_request_metrics_on_first_deployed_to_production_at", using: :btree
add_index "merge_request_metrics", ["merge_request_id"], name: "index_merge_request_metrics", using: :btree
+ add_index "merge_request_metrics", ["pipeline_id"], name: "index_merge_request_metrics_on_pipeline_id", using: :btree
create_table "merge_requests", force: :cascade do |t|
t.string "target_branch", null: false
@@ -1246,7 +1246,7 @@ ActiveRecord::Schema.define(version: 20161109150329) do
add_foreign_key "labels", "namespaces", column: "group_id", on_delete: :cascade
add_foreign_key "lists", "boards"
add_foreign_key "lists", "labels"
- add_foreign_key "merge_request_metrics", "ci_commits", on_delete: :cascade
+ add_foreign_key "merge_request_metrics", "ci_commits", column: "pipeline_id", on_delete: :cascade
add_foreign_key "merge_request_metrics", "merge_requests", on_delete: :cascade
add_foreign_key "merge_requests_closing_issues", "issues", on_delete: :cascade
add_foreign_key "merge_requests_closing_issues", "merge_requests", on_delete: :cascade
diff --git a/lib/gitlab/cycle_analytics/events_fetcher.rb b/lib/gitlab/cycle_analytics/events_fetcher.rb
index c12fdd58a47..d19ce6e0f6f 100644
--- a/lib/gitlab/cycle_analytics/events_fetcher.rb
+++ b/lib/gitlab/cycle_analytics/events_fetcher.rb
@@ -20,7 +20,7 @@ module Gitlab
end
def test_custom_query(base_query)
- base_query.join(build_table).on(mr_metrics_table[:ci_commit_id].eq(build_table[:commit_id]))
+ base_query.join(build_table).on(mr_metrics_table[:pipeline_id].eq(build_table[:commit_id]))
end
alias_method :staging_custom_query, :test_custom_query