diff options
author | James Lopez <james@jameslopez.es> | 2016-11-16 09:58:23 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:59 +0100 |
commit | cbc9f0cd1aa9f379952b6e4d3ad6df9971f9092a (patch) | |
tree | c8f1cfd9bab5183825a46ddd8a978d261b26cfec | |
parent | 633ddc9ed98c690c082c7347422ac85f9b592fb4 (diff) | |
download | gitlab-ce-cbc9f0cd1aa9f379952b6e4d3ad6df9971f9092a.tar.gz |
fix issue with commits and also updated routes
-rw-r--r-- | app/controllers/projects/cycle_analytics/events_controller.rb | 6 | ||||
-rw-r--r-- | config/routes/project.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/events.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/query_config.rb | 3 | ||||
-rw-r--r-- | spec/requests/projects/cycle_analytics_events_spec.rb | 2 |
5 files changed, 23 insertions, 8 deletions
diff --git a/app/controllers/projects/cycle_analytics/events_controller.rb b/app/controllers/projects/cycle_analytics/events_controller.rb index cb52dfc830a..961183f44c3 100644 --- a/app/controllers/projects/cycle_analytics/events_controller.rb +++ b/app/controllers/projects/cycle_analytics/events_controller.rb @@ -1,4 +1,6 @@ -class Projects::CycleAnalytics::EventsController < Projects::ApplicationController +module Projects + module CycleAnalytics +class EventsController < Projects::ApplicationController include CycleAnalyticsParams before_action :authorize_read_cycle_analytics! @@ -61,3 +63,5 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll return access_denied! unless current_user.can?(:read_build, project) end end + end +end diff --git a/config/routes/project.rb b/config/routes/project.rb index 7e0536b464f..d6eae1c9fce 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -154,7 +154,7 @@ resources :namespaces, path: '/', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: resource :cycle_analytics, only: [:show] namespace :cycle_analytics do - scope :events, controller: '/projects/cycle_analytics/events' do + scope :events, controller: 'events' do get :issue get :plan get :code diff --git a/lib/gitlab/cycle_analytics/events.rb b/lib/gitlab/cycle_analytics/events.rb index d3c7d6fe1aa..f4d6d2049ef 100644 --- a/lib/gitlab/cycle_analytics/events.rb +++ b/lib/gitlab/cycle_analytics/events.rb @@ -12,9 +12,11 @@ module Gitlab def plan_events @fetcher.fetch(stage: :plan).map do |event| - commit = first_time_reference_commit(event.delete('commits'), event) + st_commit = first_time_reference_commit(event.delete('commits'), event) - AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json + next unless st_commit + + serialize_commit(event, st_commit) end end @@ -53,11 +55,17 @@ module Gitlab end def first_time_reference_commit(commits, event) - st_commit = YAML.load(commits).detect do |commit| - commit['created_at'] == event['first_mentioned_in_commit_at'] + YAML.load(commits).find do |commit| + next unless commit[:committed_date] && event['first_mentioned_in_commit_at'] + + commit[:committed_date].to_i == DateTime.parse(event['first_mentioned_in_commit_at']).to_i end + end + + def serialize_commit(event, st_commit) + commit = Commit.new(Gitlab::Git::Commit.new(st_commit), @project) - Commit.new(Gitlab::Git::Commit.new(st_commit), @project) + AnalyticsCommitSerializer.new(project: @project, total_time: event['total_time']).represent(commit).as_json end def interval_in_words(diff) diff --git a/lib/gitlab/cycle_analytics/query_config.rb b/lib/gitlab/cycle_analytics/query_config.rb index a18c263ba53..4fddbad95f2 100644 --- a/lib/gitlab/cycle_analytics/query_config.rb +++ b/lib/gitlab/cycle_analytics/query_config.rb @@ -33,7 +33,8 @@ module Gitlab start_time_attrs: issue_metrics_table[:first_associated_with_milestone_at], end_time_attrs: [issue_metrics_table[:first_added_to_board_at], issue_metrics_table[:first_mentioned_in_commit_at]], - projections: [mr_diff_table[:st_commits].as('commits')] + projections: [mr_diff_table[:st_commits].as('commits'), + issue_metrics_table[:first_mentioned_in_commit_at]] } end diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb index ef6e4c80911..280aa2152b1 100644 --- a/spec/requests/projects/cycle_analytics_events_spec.rb +++ b/spec/requests/projects/cycle_analytics_events_spec.rb @@ -142,5 +142,7 @@ describe 'cycle analytics events' do create(:ci_build, pipeline: pipeline, status: :success, author: user) merge_merge_requests_closing_issue(issue) + + Issue::Metrics.update_all(first_mentioned_in_commit_at: mr.commits.last.committed_date) end end |